From 83cdc26f7b2bee695cb82906c60208c8cd138c5f Mon Sep 17 00:00:00 2001 From: Dave Johansen Date: Fri, 8 Nov 2024 16:04:55 -0700 Subject: [PATCH 1/2] Move List classes below the type that they contain --- m3u8/model.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/m3u8/model.py b/m3u8/model.py index 1dc7a5e4..daf360ca 100644 --- a/m3u8/model.py +++ b/m3u8/model.py @@ -449,6 +449,12 @@ def _create_sub_directories(self, filename): os.makedirs(basename, exist_ok=True) +class TagList(list): + def __str__(self): + output = [str(tag) for tag in self] + return "\n".join(output) + + class Segment(BasePathMixin): """ A video segment from a M3U8 playlist @@ -1009,6 +1015,10 @@ def __str__(self): return "#EXT-X-STREAM-INF:" + ",".join(stream_inf) + "\n" + self.uri +class PlaylistList(TagList, GroupedBasePathMixin): + pass + + class IFramePlaylist(BasePathMixin): """ IFramePlaylist object representing a link to a @@ -1260,26 +1270,12 @@ def __str__(self): return self.dumps() -class TagList(list): - def __str__(self): - output = [str(tag) for tag in self] - return "\n".join(output) - - class MediaList(TagList, GroupedBasePathMixin): @property def uri(self): return [media.uri for media in self] -class PlaylistList(TagList, GroupedBasePathMixin): - pass - - -class SessionDataList(TagList): - pass - - class Start: def __init__(self, time_offset, precise=None): self.time_offset = float(time_offset) @@ -1443,7 +1439,7 @@ def __str__(self): return self.dumps() -class DateRangeList(TagList): +class SessionDataList(TagList): pass @@ -1502,6 +1498,10 @@ def __str__(self): return self.dumps() +class DateRangeList(TagList): + pass + + class ContentSteering(BasePathMixin): def __init__(self, base_uri, server_uri, pathway_id=None): self.base_uri = base_uri From ce50ccaa57867e58a638a5f825b5cb581ce880f2 Mon Sep 17 00:00:00 2001 From: Dave Johansen Date: Fri, 8 Nov 2024 16:07:02 -0700 Subject: [PATCH 2/2] Add typing for all lists --- m3u8/model.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/m3u8/model.py b/m3u8/model.py index daf360ca..a0f16f51 100644 --- a/m3u8/model.py +++ b/m3u8/model.py @@ -3,6 +3,7 @@ # license that can be found in the LICENSE file. import decimal import os +from typing import TypeVar from m3u8.mixins import BasePathMixin, GroupedBasePathMixin from m3u8.parser import format_date_time, parse @@ -449,7 +450,10 @@ def _create_sub_directories(self, filename): os.makedirs(basename, exist_ok=True) -class TagList(list): +T = TypeVar("T") + + +class TagList(list[T]): def __str__(self): output = [str(tag) for tag in self] return "\n".join(output) @@ -712,7 +716,7 @@ def base_uri(self, newbase_uri): self.init_section.base_uri = newbase_uri -class SegmentList(list, GroupedBasePathMixin): +class SegmentList(list[Segment], GroupedBasePathMixin): def dumps(self, timespec="milliseconds", infspec="auto"): output = [] last_segment = None @@ -827,7 +831,7 @@ def __str__(self): return self.dumps(None) -class PartialSegmentList(list, GroupedBasePathMixin): +class PartialSegmentList(list[PartialSegment], GroupedBasePathMixin): def __str__(self): output = [str(part) for part in self] return "\n".join(output) @@ -1015,7 +1019,7 @@ def __str__(self): return "#EXT-X-STREAM-INF:" + ",".join(stream_inf) + "\n" + self.uri -class PlaylistList(TagList, GroupedBasePathMixin): +class PlaylistList(TagList[Playlist], GroupedBasePathMixin): pass @@ -1270,7 +1274,7 @@ def __str__(self): return self.dumps() -class MediaList(TagList, GroupedBasePathMixin): +class MediaList(TagList[Media], GroupedBasePathMixin): @property def uri(self): return [media.uri for media in self] @@ -1310,7 +1314,7 @@ def __str__(self): return self.dumps() -class RenditionReportList(list, GroupedBasePathMixin): +class RenditionReportList(list[RenditionReport], GroupedBasePathMixin): def __str__(self): output = [str(report) for report in self] return "\n".join(output) @@ -1439,7 +1443,7 @@ def __str__(self): return self.dumps() -class SessionDataList(TagList): +class SessionDataList(TagList[SessionData]): pass @@ -1498,7 +1502,7 @@ def __str__(self): return self.dumps() -class DateRangeList(TagList): +class DateRangeList(TagList[DateRange]): pass