Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_item(self, item):
if isinstance(item, Item):
Container.add_item(self, item)
return True
return False
def to_didl_element(self):
""" Returns an Element based on this Resource.
"""
root = Container.to_didl_element(self)
if not all([self.storage_total, self.storage_used, self.storage_free,
self.storage_medium]):
raise Exception('Could not create DIDL Element: missing required '
'properties.')
ElementTree.SubElement(root, 'upnp:storageTotal').text = \
self.storage_total
ElementTree.SubElement(root, 'upnp:storageUsed').text = \
self.storage_used
ElementTree.SubElement(root, 'upnp:storageFree').text = \
self.storage_free
ElementTree.SubElement(root, 'upnp:storageMedium').text = \
self.storage_medium
return root
ElementTree.SubElement(root, 'upnp:author').text = a
for p in self.publishers:
ElementTree.SubElement(root, 'dc:publisher').text = p
for c in self.contributors:
ElementTree.SubElement(root, 'dc:contributor').text = c
for r in self.relations:
ElementTree.SubElement(root, 'dc:relation').text = r
for l in self.languages:
ElementTree.SubElement(root, 'dc:language').text = l
for r in self.rights:
ElementTree.SubElement(root, 'dc:rights').text = r
return root
class Album(Container):
""" Ordered collection of objects. Rendering the album has the semantics of
rendering each object in sequence.
"""
upnp_class = '%s%s' % (Container.upnp_class, '.album')
def __init__(self, object_id='', parent_id='', title='', restricted=False,
creator='', write_status=WRITE_STATUS_NOT_WRITABLE,
searchable=True, search_classes=None, create_classes=None,
storage_medium='', long_description='', description='',
publishers=None, contributors=None, date='', relations=None,
rights=None):
""" Constructor for the Album class.
@param id: unique identifier for the object
@param parent_id: id of object's parent
for a in self.artists:
ElementTree.SubElement(root, 'upnp:artist').text = a
for g in self.genres:
ElementTree.SubElement(root, 'upnp:genre').text = g
for p in self.producers:
ElementTree.SubElement(root, 'upnp:producer').text = p
if self.album_art_uri:
ElementTree.SubElement(root, 'upnp:albumArtURI').text = \
self.album_art_uri
if self.toc:
ElementTree.SubElement(root, 'upnp:toc').text = self.toc
return root
class Genre(Container):
""" A container with a name denoting a genre.
"""
upnp_class = '%s%s' % (Container.upnp_class, '.genre')
def __init__(self, object_id='', parent_id='', title='', restricted=False,
creator='', write_status=WRITE_STATUS_NOT_WRITABLE,
searchable=True, search_classes=None, create_classes=None,
long_description='', description=''):
""" Constructor for the Container class.
@param id: unique identifier for the object
@param parent_id: id of object's parent
@param title: name of the object
@param restricted: True if only CDS can modify the object
@param creator: content creator or owner
def add_container(self, c):
if isinstance(c, Album) or isinstance(c, PlaylistContainer):
Container.add_container(self, c)
return True
return False
for r in self.relations:
ElementTree.SubElement(root, 'dc:relation').text = r
for l in self.languages:
ElementTree.SubElement(root, 'dc:language').text = l
for r in self.rights:
ElementTree.SubElement(root, 'dc:rights').text = r
return root
class Album(Container):
""" Ordered collection of objects. Rendering the album has the semantics of
rendering each object in sequence.
"""
upnp_class = '%s%s' % (Container.upnp_class, '.album')
def __init__(self, object_id='', parent_id='', title='', restricted=False,
creator='', write_status=WRITE_STATUS_NOT_WRITABLE,
searchable=True, search_classes=None, create_classes=None,
storage_medium='', long_description='', description='',
publishers=None, contributors=None, date='', relations=None,
rights=None):
""" Constructor for the Album class.
@param id: unique identifier for the object
@param parent_id: id of object's parent
@param title: name of the object
@param restricted: True if only CDS can modify the object
@param creator: content creator or owner
@param write_status: modifiability of the resources of this object.
Integer parameter based on WRITE_STATUS_*
def to_didl_element(self):
""" Returns an Element based on this Resource.
"""
root = Person.to_didl_element(self)
for g in self.genres:
ElementTree.SubElement(root, 'upnp:genre').text = g
if self.artist_discography_uri:
ElementTree.SubElement(root, 'upnp:artistDiscographyURI').text = \
self.artist_discography_uri
return root
class StorageSystem(Container):
""" Heterogeneous collection of storage media. May only be child of the
root container or another StorageSystem container.
"""
upnp_class = '%s%s' % (Container.upnp_class, '.storageSystem')
def __init__(self, object_id='', parent_id='', title='', restricted=False,
creator='', write_status=WRITE_STATUS_NOT_WRITABLE,
searchable=True, search_classes=None, create_classes=None,
storage_total=0, storage_used=0, storage_free=0,
storage_max_partition=0, storage_medium=''):
""" Constructor for the StorageSystem class.
@param id: unique identifier for the object
@param parent_id: id of object's parent
@param title: name of the object
if self.long_description:
ElementTree.SubElement(root, 'upnp:longDescription').text = \
self.long_description
if self.storage_medium:
ElementTree.SubElement(root, 'upnp:storageMedium').text = \
self.storage_medium
if self.description:
ElementTree.SubElement(root, 'dc:description').text = \
self.description
if self.date:
ElementTree.SubElement(root, 'dc:date').text = self.date
return root
class Person(Container):
""" Unordered collection of objects that belong to a person.
"""
upnp_class = '%s%s' % (Container.upnp_class, '.person')
def __init__(self, object_id='', parent_id='', title='', restricted=False,
creator='', write_status=WRITE_STATUS_NOT_WRITABLE,
searchable=True, search_classes=None, create_classes=None,
languages=None):
""" Constructor for the Person class.
@param id: unique identifier for the object
@param parent_id: id of object's parent
@param title: name of the object
@param restricted: True if only CDS can modify the object
@param creator: content creator or owner
ElementTree.SubElement(root, 'upnp:storageTotal').text = \
self.storage_total
ElementTree.SubElement(root, 'upnp:storageUsed').text = \
self.storage_used
ElementTree.SubElement(root, 'upnp:storageFree').text = \
self.storage_free
ElementTree.SubElement(root, 'upnp:storageMaxPartition').text = \
self.storage_max_partition
ElementTree.SubElement(root, 'upnp:storageMedium').text = \
self.storage_medium
return root
class StorageVolume(Container):
""" Some physical storage unit of a single type. May only be a child of the
root container or a StorageSystem container.
"""
upnp_class = '%s%s' % (Container.upnp_class, '.storageVolume')
def __init__(
self, object_id='', parent_id='', title='', restricted=False,
creator='', write_status=WRITE_STATUS_NOT_WRITABLE,
searchable=True, search_classes=None, create_classes=None,
storage_total=0, storage_used=0, storage_free=0,
storage_medium=''):
""" Constructor for the StorageVolume class.
@param id: unique identifier for the object
@param parent_id: id of object's parent
raise Exception('Could not create DIDL Element: missing required '
'properties.')
ElementTree.SubElement(root, 'upnp:storageTotal').text = \
self.storage_total
ElementTree.SubElement(root, 'upnp:storageUsed').text = \
self.storage_used
ElementTree.SubElement(root, 'upnp:storageFree').text = \
self.storage_free
ElementTree.SubElement(root, 'upnp:storageMedium').text = \
self.storage_medium
return root
class StorageFolder(Container):
""" Collection of objects stored on some storage medium. May only be a
child of the root container or another storage container.
"""
upnp_class = '%s%s' % (Container.upnp_class, '.storageFolder')
def __init__(self, object_id='', parent_id='', title='', restricted=False,
creator='', write_status=WRITE_STATUS_NOT_WRITABLE,
searchable=True, search_classes=None, create_classes=None,
storage_used=''):
""" Constructor for the StorageFolder class.
@param id: unique identifier for the object
@param parent_id: id of object's parent
@param title: name of the object
@param restricted: True if only CDS can modify the object