Mercurial > libervia-pubsub
comparison idavoll/memory_storage.py @ 126:ffc3c706b0fb
Don't return anything when removing items, and raise exception when an item
is not found.
Return items for get_items() in unicode string.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Sun, 24 Apr 2005 17:19:27 +0000 |
parents | 8892331314c8 |
children | 8f6956b9a688 |
comparison
equal
deleted
inserted
replaced
125:0d7b95fb2549 | 126:ffc3c706b0fb |
---|---|
159 | 159 |
160 def remove_items(self, item_ids): | 160 def remove_items(self, item_ids): |
161 deleted = [] | 161 deleted = [] |
162 | 162 |
163 for item_id in item_ids: | 163 for item_id in item_ids: |
164 try: | 164 if not self._items.has_key(item_id): |
165 item = self._items[item_id] | 165 return defer.fail(storage.ItemNotFound()) |
166 self._itemlist.remove(item) | 166 |
167 del self._items[item_id] | 167 for item_id in item_ids: |
168 deleted.append(item_id) | 168 item = self._items[item_id] |
169 except KeyError: | 169 self._itemlist.remove(item) |
170 pass | 170 del self._items[item_id] |
171 | 171 |
172 return defer.succeed(deleted) | 172 return defer.succeed(None) |
173 | 173 |
174 def get_items(self, max_items=None): | 174 def get_items(self, max_items=None): |
175 if max_items: | 175 if max_items: |
176 list = self._itemlist[-max_items:] | 176 list = self._itemlist[-max_items:] |
177 else: | 177 else: |
178 list = self._itemlist | 178 list = self._itemlist |
179 return defer.succeed([item[0] for item in list]) | 179 return defer.succeed([unicode(item[0], 'utf-8') for item in list]) |
180 | 180 |
181 def get_items_by_id(self, item_ids): | 181 def get_items_by_id(self, item_ids): |
182 items = [] | 182 items = [] |
183 for item_id in item_ids: | 183 for item_id in item_ids: |
184 try: | 184 try: |
185 item = self._items[item_id] | 185 item = self._items[item_id] |
186 except KeyError: | 186 except KeyError: |
187 pass | 187 pass |
188 else: | 188 else: |
189 items.append(item[0]) | 189 items.append(unicode(item[0], 'utf-8')) |
190 return defer.succeed(items) | 190 return defer.succeed(items) |
191 | 191 |
192 def purge(self): | 192 def purge(self): |
193 self._items = {} | 193 self._items = {} |
194 self._itemlist = [] | 194 self._itemlist = [] |