Browse Source

add support for deleteing Items...

make Containers contain their own list of children...

add the containing ContentDirectory to the Items so that they can
add children to themselves...

[git-p4: depot-paths = "//depot/": change = 762]
replace/4e84fdb41ea781c7a8f872baa423e8b3be4045a7
John-Mark Gurney 19 years ago
parent
commit
528bb66be9
2 changed files with 17 additions and 7 deletions
  1. +10
    -2
      ContentDirectory.py
  2. +7
    -5
      DIDLLite.py

+ 10
- 2
ContentDirectory.py View File

@@ -39,17 +39,25 @@ class ContentDirectoryControl(UPnPPublisher, dict):

def addContainer(self, parent, title, klass = Container, **kwargs):
ret = self.addItem(parent, klass, title, **kwargs)
self.children[ret] = []
self.children[ret] = self[ret]
return ret

def addItem(self, parent, klass, *args, **kwargs):
assert isinstance(self[parent], Container)
nid = self.getnextID()
i = klass(nid, parent, *args, **kwargs)
i = klass(self, nid, parent, *args, **kwargs)
self.children[parent].append(i)
self[i.id] = i
return i.id

def delItem(self, id):
if isinstance(self[id], Container):
for i in self.children[id]:
self.delItem(i)
assert len(self.children[id]) == 0
del self.children[id]
del self[id]

def getchildren(self, item):
assert isinstance(self[item], Container)
return self.children[item][:]


+ 7
- 5
DIDLLite.py View File

@@ -36,9 +36,10 @@ class Object:
res = None
writeStatus = None

def __init__(self, id, parentID, title, restricted = False,
def __init__(self, cd, id, parentID, title, restricted = False,
creator = None):

self.cd = cd
self.id = id
self.parentID = parentID
self.title = title
@@ -203,19 +204,20 @@ class PlaylistItem(Item):
class TextItem(Item):
klass = Item.klass + '.textItem'

class Container(Object):
class Container(Object, list):
"""An object that can contain other objects."""

klass = Object.klass + '.container'

elementName = 'container'
childCount = 0
childCount = property(lambda x: len(x))
createClass = None
searchClass = None
searchable = None

def __init__(self, id, parentID, title, restricted = 0, creator = None):
Object.__init__(self, id, parentID, title, restricted, creator)
def __init__(self, cd, id, parentID, title, restricted = 0, creator = None):
Object.__init__(self, cd, id, parentID, title, restricted, creator)
list.__init__(self)

def toElement(self):



Loading…
Cancel
Save