Mercurial > libervia-pubsub
comparison idavoll/gateway.py @ 198:e404775b12df
Change naming and spacing conventions to match Twisted's.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Tue, 10 Jun 2008 11:31:49 +0000 |
parents | 48245777acea |
children | 2c46e6664680 |
comparison
equal
deleted
inserted
replaced
197:9da5a95d408d | 198:e404775b12df |
---|---|
136 def toResponse(nodeIdentifier): | 136 def toResponse(nodeIdentifier): |
137 uri = 'xmpp:%s?;node=%s' % (self.serviceJID.full(), nodeIdentifier) | 137 uri = 'xmpp:%s?;node=%s' % (self.serviceJID.full(), nodeIdentifier) |
138 stream = simplejson.dumps({'uri': uri}) | 138 stream = simplejson.dumps({'uri': uri}) |
139 return http.Response(responsecode.OK, stream=stream) | 139 return http.Response(responsecode.OK, stream=stream) |
140 | 140 |
141 d = self.backend.create_node(None, self.owner) | 141 d = self.backend.createNode(None, self.owner) |
142 d.addCallback(toResponse) | 142 d.addCallback(toResponse) |
143 return d | 143 return d |
144 | 144 |
145 | 145 |
146 | 146 |
182 failure.trap(XMPPURIParseError) | 182 failure.trap(XMPPURIParseError) |
183 return http.StatusResponse(responsecode.BAD_REQUEST, | 183 return http.StatusResponse(responsecode.BAD_REQUEST, |
184 "Malformed XMPP URI: %s" % failure.value.message) | 184 "Malformed XMPP URI: %s" % failure.value.message) |
185 | 185 |
186 d = getNode() | 186 d = getNode() |
187 d.addCallback(self.backend.delete_node, self.owner) | 187 d.addCallback(self.backend.deleteNode, self.owner) |
188 d.addCallback(respond) | 188 d.addCallback(respond) |
189 d.addErrback(trapNotFound) | 189 d.addErrback(trapNotFound) |
190 d.addErrback(trapXMPPURIParseError) | 190 d.addErrback(trapXMPPURIParseError) |
191 return d | 191 return d |
192 | 192 |
250 def getNode(): | 250 def getNode(): |
251 if request.args.get('uri'): | 251 if request.args.get('uri'): |
252 jid, nodeIdentifier = getServiceAndNode(request.args['uri'][0]) | 252 jid, nodeIdentifier = getServiceAndNode(request.args['uri'][0]) |
253 return defer.succeed(nodeIdentifier) | 253 return defer.succeed(nodeIdentifier) |
254 else: | 254 else: |
255 return self.backend.create_node(None, self.owner) | 255 return self.backend.createNode(None, self.owner) |
256 | 256 |
257 def doPublish(payload): | 257 def doPublish(payload): |
258 d = getNode() | 258 d = getNode() |
259 d.addCallback(gotNode, payload) | 259 d.addCallback(gotNode, payload) |
260 return d | 260 return d |
287 def render(self, request): | 287 def render(self, request): |
288 def responseFromNodes(nodeIdentifiers): | 288 def responseFromNodes(nodeIdentifiers): |
289 return http.Response(responsecode.OK, | 289 return http.Response(responsecode.OK, |
290 stream=simplejson.dumps(nodeIdentifiers)) | 290 stream=simplejson.dumps(nodeIdentifiers)) |
291 | 291 |
292 d = self.service.get_nodes() | 292 d = self.service.getNodes() |
293 d.addCallback(responseFromNodes) | 293 d.addCallback(responseFromNodes) |
294 return d | 294 return d |
295 | 295 |
296 | 296 |
297 | 297 |
323 if atomEntry: | 323 if atomEntry: |
324 atomEntries.append(atomEntry) | 324 atomEntries.append(atomEntry) |
325 | 325 |
326 return atomEntries | 326 return atomEntries |
327 | 327 |
328 | |
329 | |
328 def constructFeed(service, nodeIdentifier, entries, title): | 330 def constructFeed(service, nodeIdentifier, entries, title): |
329 nodeURI = 'xmpp:%s?;node=%s' % (service.full(), nodeIdentifier) | 331 nodeURI = 'xmpp:%s?;node=%s' % (service.full(), nodeIdentifier) |
330 now = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) | 332 now = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()) |
331 | 333 |
332 # Collect the received entries in a feed | 334 # Collect the received entries in a feed |
337 | 339 |
338 for entry in entries: | 340 for entry in entries: |
339 feed.addChild(entry) | 341 feed.addChild(entry) |
340 | 342 |
341 return feed | 343 return feed |
344 | |
345 | |
342 | 346 |
343 class RemoteSubscriptionService(service.Service, PubSubClient): | 347 class RemoteSubscriptionService(service.Service, PubSubClient): |
344 """ | 348 """ |
345 Service for subscribing to remote XMPP Publish-Subscribe nodes. | 349 Service for subscribing to remote XMPP Publish-Subscribe nodes. |
346 | 350 |
570 """ | 574 """ |
571 | 575 |
572 def __init__(self, service): | 576 def __init__(self, service): |
573 self.service = service | 577 self.service = service |
574 | 578 |
579 | |
575 def render(self, request): | 580 def render(self, request): |
576 try: | 581 try: |
577 maxItems = int(request.args.get('max_items', [0])[0]) or None | 582 maxItems = int(request.args.get('max_items', [0])[0]) or None |
578 except ValueError: | 583 except ValueError: |
579 return http.StatusResponse(responsecode.BAD_REQUEST, | 584 return http.StatusResponse(responsecode.BAD_REQUEST, |
580 "The argument max_items has an invalid value.") | 585 "The argument max_items has an invalid value.") |
581 | 586 |
582 try: | 587 try: |
583 jid, nodeIdentifier = getServiceAndNode(request.args['uri'][0]) | 588 uri = request.args['uri'][0] |
584 except KeyError: | 589 except KeyError: |
585 return http.StatusResponse(responsecode.BAD_REQUEST, | 590 return http.StatusResponse(responsecode.BAD_REQUEST, |
586 "No URI for the remote node provided.") | 591 "No URI for the remote node provided.") |
592 | |
593 try: | |
594 jid, nodeIdentifier = getServiceAndNode(uri) | |
587 except XMPPURIParseError: | 595 except XMPPURIParseError: |
588 return http.StatusResponse(responsecode.BAD_REQUEST, | 596 return http.StatusResponse(responsecode.BAD_REQUEST, |
589 "Malformed XMPP URI: %s" % failure.value.message) | 597 "Malformed XMPP URI: %s" % uri) |
590 | |
591 | 598 |
592 def respond(items): | 599 def respond(items): |
593 """Create a feed out the retrieved items.""" | 600 """Create a feed out the retrieved items.""" |
594 contentType = http_headers.MimeType('application', | 601 contentType = http_headers.MimeType('application', |
595 'atom+xml', | 602 'atom+xml', |