Mercurial > libervia-pubsub
diff idavoll/memory_storage.py @ 202:77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Wed, 25 Jun 2008 12:27:55 +0000 |
parents | e404775b12df |
children | b4bf0a5ce50d |
line wrap: on
line diff
--- a/idavoll/memory_storage.py Tue Jun 24 08:42:16 2008 +0000 +++ b/idavoll/memory_storage.py Wed Jun 25 12:27:55 2008 +0000 @@ -169,6 +169,24 @@ +class PublishedItem(object): + """ + A published item. + + This represent an item as it was published by an entity. + + @ivar element: The DOM representation of the item that was published. + @type element: L{Element<twisted.words.xish.domish.Element>} + @ivar publisher: The entity that published the item. + @type publisher: L{JID<twisted.words.protocols.jabber.jid.JID>} + """ + + def __init__(self, element, publisher): + self.element = element + self.publisher = publisher + + + class LeafNodeMixin: nodeType = 'leaf' @@ -179,12 +197,9 @@ def storeItems(self, items, publisher): - for data in items: - itemIdentifier = data["id"] - data = data.toXml() - if isinstance(data, str): - data = data.decode('utf-8') - item = (data, publisher) + for element in items: + item = PublishedItem(element, publisher) + itemIdentifier = element["id"] if itemIdentifier in self._items: self._itemlist.remove(self._items[itemIdentifier]) self._items[itemIdentifier] = item @@ -211,10 +226,10 @@ def getItems(self, maxItems=None): if maxItems: - list = self._itemlist[-maxItems:] + itemList = self._itemlist[-maxItems:] else: - list = self._itemlist - return defer.succeed([item[0] for item in list]) + itemList = self._itemlist + return defer.succeed([item.element for item in itemList]) def getItemsById(self, itemIdentifiers): @@ -225,7 +240,7 @@ except KeyError: pass else: - items.append(item[0]) + items.append(item.element) return defer.succeed(items)