Mercurial > libervia-pubsub
changeset 139:8f6956b9a688
Follow API change in Twisted Xish, while still being compatible with
Twisted Xish 0.1.0.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Wed, 27 Apr 2005 19:45:41 +0000 |
parents | 635e433810ef |
children | d79f0816f6c3 |
files | idavoll/memory_storage.py idavoll/test/test_storage.py |
diffstat | 2 files changed, 17 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/idavoll/memory_storage.py Mon Apr 25 13:02:37 2005 +0000 +++ b/idavoll/memory_storage.py Wed Apr 27 19:45:41 2005 +0000 @@ -149,7 +149,10 @@ def store_items(self, items, publisher): for data in items: id = data["id"] - item = (data.toXml(), publisher) + data = data.toXml() + if isinstance(data, str): + data = data.decode('utf-8') + item = (data, publisher) if id in self._items: self._itemlist.remove(self._items[id]) self._items[id] = item @@ -176,7 +179,7 @@ list = self._itemlist[-max_items:] else: list = self._itemlist - return defer.succeed([unicode(item[0], 'utf-8') for item in list]) + return defer.succeed([item[0] for item in list]) def get_items_by_id(self, item_ids): items = [] @@ -186,7 +189,7 @@ except KeyError: pass else: - items.append(unicode(item[0], 'utf-8')) + items.append(item[0]) return defer.succeed(items) def purge(self):
--- a/idavoll/test/test_storage.py Mon Apr 25 13:02:37 2005 +0000 +++ b/idavoll/test/test_storage.py Wed Apr 27 19:45:41 2005 +0000 @@ -31,6 +31,11 @@ ITEM_TO_NOT_BE_DELETED.addElement(('testns', 'test'), content=u'Test \u2083 item') +def decode(object): + if isinstance(object, str): + object = object.decode('utf-8') + return object + class StorageTests: def _assignTestNode(self, node): @@ -225,7 +230,7 @@ return self.node.get_items_by_id(['new']) def cb2(result): - assertEqual(result[0], unicode(ITEM_NEW.toXml(), 'utf-8')) + assertEqual(result[0], decode(ITEM_NEW.toXml())) d = self.node.store_items([ITEM_NEW], PUBLISHER) d.addCallback(cb1) @@ -237,7 +242,7 @@ return self.node.get_items_by_id(['current']) def cb2(result): - assertEqual(result[0], unicode(ITEM_UPDATED.toXml(), 'utf-8')) + assertEqual(result[0], decode(ITEM_UPDATED.toXml())) d = self.node.store_items([ITEM_UPDATED], PUBLISHER) d.addCallback(cb1) @@ -263,7 +268,7 @@ def testGetItems(self): def cb(result): - assertIn(unicode(ITEM.toXml(), 'utf-8'), result) + assertIn(decode(ITEM.toXml()), result) d = self.node.get_items() d.addCallback(cb) @@ -271,7 +276,7 @@ def testLastItem(self): def cb(result): - assertEqual([unicode(ITEM.toXml(), 'utf-8')], result) + assertEqual([decode(ITEM.toXml())], result) d = self.node.get_items(1) d.addCallback(cb) @@ -333,14 +338,14 @@ subscriptions[SUBSCRIBER_PENDING.full()] = \ Subscription('pending') - item = (ITEM_TO_BE_DELETED.toXml(), PUBLISHER) + item = (decode(ITEM_TO_BE_DELETED.toXml()), PUBLISHER) self.s._nodes['pre-existing']._items['to-be-deleted'] = item self.s._nodes['pre-existing']._itemlist.append(item) self.s._nodes['pre-existing']._items['to-not-be-deleted'] = item self.s._nodes['pre-existing']._itemlist.append(item) self.s._nodes['to-be-purged']._items['to-be-deleted'] = item self.s._nodes['to-be-purged']._itemlist.append(item) - item = (ITEM.toXml(), PUBLISHER) + item = (decode(ITEM.toXml()), PUBLISHER) self.s._nodes['pre-existing']._items['current'] = item self.s._nodes['pre-existing']._itemlist.append(item)