def route(self, stanza): """ Route a stanza. @param stanza: The stanza to be routed. @type stanza: L{domish.Element}. """ destination = JID(stanza['to']) if destination.host in self.routes: log.msg("Routing to %s: %r" % (destination.full(), stanza.toXml())) self.routes[destination.host].send(stanza) elif None in self.routes: log.msg("Routing to %s (default route): %r" % (destination.full(), stanza.toXml())) self.routes[None].send(stanza) else: log.msg("No route to %s: %r" % (destination.full(), stanza.toXml())) if stanza.getAttribute('type') not in ('result', 'error'): # No route, send back error exc = error.StanzaError('remote-server-timeout', type='wait') exc.code = '504' response = exc.toResponse(stanza) self.route(response)
def onMessage(self, message): sender = JID(message['from']) if (sender.userhost() == self.occupantJID.userhost() and message['type'] == 'groupchat' and message.body and sender.resource and (not message.x or message.x.uri not in (NS_X_DELAY, NS_X_DELAY))): notification = { u'title': sender.resource or u'*', u'subtitle': unicode(message.body), } self.aggregator.processNotification(notification)
def route(self, stanza): """ Route a stanza. @param stanza: The stanza to be routed. @type stanza: L{domish.Element}. """ destination = JID(stanza['to']) log.msg("Routing to %s: %r" % (destination.full(), stanza.toXml())) if destination.host in self.routes: self.routes[destination.host].send(stanza) else: self.routes[None].send(stanza)
def api_updateItem(self, request): """ Edit the contents of an item. {id} is the id of the item; other args are treated as updates to the item. """ item = self.api_getItem(request) args = dict(request.args) del args['id'] schema = dict(item.__class__.getSchema()) if source.IPubSubEventProcessor.providedBy(item): oldNode = item.getNode() oldEnabled = item.enabled # Map the update attributes for k in args.keys(): if k not in schema: raise Exception("Invalid update attribute: " + k) value = unicode(args[k][0]) if isinstance(schema[k], attributes.boolean): value = value == "true" if isinstance(schema[k], JIDAttribute): value = JID(value) if isinstance(schema[k], attributes.textlist): value = [s.strip() for s in value.strip().split("\n") if s.strip() != ""] if isinstance(schema[k], attributes.reference): if not value: value = None else: value = self.store.getItemByID(int(value)) setattr(item, k, value) # Update the item if (source.IPubSubEventProcessor.providedBy(item) and (oldNode != item.getNode() or oldEnabled != item.enabled)): # Call the pubsub service to fix stuff. if oldEnabled: self.pubsubDispatcher.removeObserver(item) if item.enabled: self.pubsubDispatcher.addObserver(item) if hasattr(item, 'terms') and hasattr(item, 'userIDs'): self.twitterDispatcher.refreshFilters() return item