comparison idavoll/backend.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 d829db6095d6
children e6b710bf2b24
comparison
equal deleted inserted replaced
201:d829db6095d6 202:77c61e2b8c75
145 elif not items and (persistItems or deliverPayloads): 145 elif not items and (persistItems or deliverPayloads):
146 raise error.ItemRequired() 146 raise error.ItemRequired()
147 147
148 if persistItems or deliverPayloads: 148 if persistItems or deliverPayloads:
149 for item in items: 149 for item in items:
150 item.uri = None
151 item.defaultUri = None
152 if not item.getAttribute("id"): 150 if not item.getAttribute("id"):
153 item["id"] = str(uuid.uuid4()) 151 item["id"] = str(uuid.uuid4())
154 152
155 if persistItems: 153 if persistItems:
156 d = node.storeItems(items, requestor) 154 d = node.storeItems(items, requestor)
222 def _returnSubscription(self, result, nodeIdentifier): 220 def _returnSubscription(self, result, nodeIdentifier):
223 return nodeIdentifier, result 221 return nodeIdentifier, result
224 222
225 223
226 def _sendLastPublished(self, node, subscriber): 224 def _sendLastPublished(self, node, subscriber):
227 class StringParser(object): 225
228 def __init__(self): 226 def notifyItem(items):
229 self.elementStream = domish.elementStream() 227 if not items:
230 self.elementStream.DocumentStartEvent = self.docStart
231 self.elementStream.ElementEvent = self.elem
232 self.elementStream.DocumentEndEvent = self.docEnd
233
234 def docStart(self, elem):
235 self.document = elem
236
237 def elem(self, elem):
238 self.document.addChild(elem)
239
240 def docEnd(self):
241 pass
242
243 def parse(self, string):
244 self.elementStream.parse(string)
245 return self.document
246
247 def notifyItem(result):
248 if not result:
249 return 228 return
250
251 items = [domish.SerializedXML(item) for item in result]
252 229
253 reactor.callLater(0, self.dispatch, 230 reactor.callLater(0, self.dispatch,
254 {'items': items, 231 {'items': items,
255 'nodeIdentifier': node.nodeIdentifier, 232 'nodeIdentifier': node.nodeIdentifier,
256 'subscriber': subscriber}, 233 'subscriber': subscriber},