1- # -*- coding: utf-8 -*-
21"""DIDL-Lite (Digital Item Declaration Language) tools for Python."""
32# pylint: disable=too-many-lines
43
@@ -101,9 +100,7 @@ def __init__(
101100 self .xml_el = xml_el
102101 self .descriptors = descriptors if descriptors else []
103102
104- def _ensure_required_properties (
105- self , strict : bool , properties : Mapping [str , Any ]
106- ) -> None :
103+ def _ensure_required_properties (self , strict : bool , properties : Mapping [str , Any ]) -> None :
107104 """Check if all required properties are given."""
108105 if not strict :
109106 return
@@ -184,9 +181,7 @@ def to_xml(self) -> ET.Element:
184181 continue
185182 key = didl_property_def_key (property_def )
186183
187- if (
188- getattr (self , key ) is None or key == "res"
189- ): # no resources, handled later on
184+ if getattr (self , key ) is None or key == "res" : # no resources, handled later on
190185 continue
191186
192187 tag = property_def [0 ] + ":" + property_def [1 ]
@@ -245,11 +240,7 @@ def __setattr__(self, name: str, value: Any) -> None:
245240 def __repr__ (self ) -> str :
246241 """Evaluatable string representation of this object."""
247242 class_name = type (self ).__name__
248- attr = ", " .join (
249- f"{ key } ={ val !r} "
250- for key , val in self .__dict__ .items ()
251- if key not in ("class" , "xml_el" )
252- )
243+ attr = ", " .join (f"{ key } ={ val !r} " for key , val in self .__dict__ .items () if key not in ("class" , "xml_el" ))
253244 return f"{ class_name } ({ attr } )"
254245
255246
@@ -660,11 +651,7 @@ def to_xml(self) -> ET.Element:
660651 def __repr__ (self ) -> str :
661652 """Evaluatable string representation of this object."""
662653 class_name = type (self ).__name__
663- attr = ", " .join (
664- f"{ key } ={ val !r} "
665- for key , val in self .__dict__ .items ()
666- if key not in ("class" , "xml_el" )
667- )
654+ attr = ", " .join (f"{ key } ={ val !r} " for key , val in self .__dict__ .items () if key not in ("class" , "xml_el" ))
668655 children_repr = ", " .join (repr (child ) for child in self )
669656 return f"{ class_name } ({ attr } , children=[{ children_repr } ])"
670657
@@ -988,11 +975,7 @@ def to_xml(self) -> ET.Element:
988975 def __repr__ (self ) -> str :
989976 """Evaluatable string representation of this object."""
990977 class_name = type (self ).__name__
991- attr = ", " .join (
992- f"{ key } ={ val !r} "
993- for key , val in self .__dict__ .items ()
994- if val is not None and key != "xml_el"
995- )
978+ attr = ", " .join (f"{ key } ={ val !r} " for key , val in self .__dict__ .items () if val is not None and key != "xml_el" )
996979 return f"{ class_name } ({ attr } )"
997980
998981
@@ -1045,11 +1028,7 @@ def __getattr__(self, name: str) -> Any:
10451028 def __repr__ (self ) -> str :
10461029 """Evaluatable string representation of this object."""
10471030 class_name = type (self ).__name__
1048- attr = ", " .join (
1049- f"{ key } ={ val !r} "
1050- for key , val in self .__dict__ .items ()
1051- if val is not None and key != "xml_el"
1052- )
1031+ attr = ", " .join (f"{ key } ={ val !r} " for key , val in self .__dict__ .items () if val is not None and key != "xml_el" )
10531032 return f"{ class_name } ({ attr } )"
10541033
10551034
@@ -1071,9 +1050,7 @@ def to_xml_string(*objects: DidlObject) -> bytes:
10711050 return ET .tostring (root_el )
10721051
10731052
1074- def from_xml_string (
1075- xml_string : str , strict : bool = True
1076- ) -> List [Union [DidlObject , Descriptor ]]:
1053+ def from_xml_string (xml_string : str , strict : bool = True ) -> List [Union [DidlObject , Descriptor ]]:
10771054 """Parse DIDL-Lite XML string."""
10781055 if not strict :
10791056 # Find all prefixes used in tags, e.g., <prefix:tag ...>
@@ -1083,9 +1060,7 @@ def from_xml_string(
10831060 defined_prefixes = set (re .findall (r"xmlns:([a-zA-Z0-9]+)=" , xml_string ))
10841061
10851062 # Identify prefixes used but not defined.
1086- missing_prefixes = (
1087- used_prefixes - defined_prefixes - {"DIDL-Lite" , "dc" , "upnp" , "dlna" }
1088- )
1063+ missing_prefixes = used_prefixes - defined_prefixes - {"DIDL-Lite" , "dc" , "upnp" , "dlna" }
10891064
10901065 # Remove the "if missing_prefixes:" line and just keep the for loop
10911066 for prefix in missing_prefixes :
@@ -1099,17 +1074,15 @@ def from_xml_string(
10991074 return from_xml_el (xml_el , strict )
11001075
11011076
1102- def from_xml_el (
1103- xml_el : ET .Element , strict : bool = True
1104- ) -> List [Union [DidlObject , Descriptor ]]:
1077+ def from_xml_el (xml_el : ET .Element , strict : bool = True ) -> List [Union [DidlObject , Descriptor ]]:
11051078 """Convert XML Element to DIDL Objects."""
11061079 didl_objects = [] # type: List[Union[DidlObject, Descriptor]]
11071080
11081081 # items and containers, in order
11091082 for child_el in xml_el :
1110- if child_el .tag != expand_namespace_tag (
1111- "didl_lite:item "
1112- ) and child_el . tag != expand_namespace_tag ( "didl_lite:container" ) :
1083+ if child_el .tag != expand_namespace_tag ("didl_lite:item" ) and child_el . tag != expand_namespace_tag (
1084+ "didl_lite:container "
1085+ ):
11131086 continue
11141087
11151088 # construct item
@@ -1139,9 +1112,7 @@ def from_xml_el(
11391112
11401113
11411114# upnp_class to python type mapping
1142- def type_by_upnp_class (
1143- upnp_class : str , strict : bool = True
1144- ) -> Optional [Type [DidlObject ]]:
1115+ def type_by_upnp_class (upnp_class : str , strict : bool = True ) -> Optional [Type [DidlObject ]]:
11451116 """Get DidlObject-type by upnp_class.
11461117
11471118 When strict is False, the upnp_class lookup will be done ignoring string
0 commit comments