def _cb_message_insert_done (self, _none, element, ) : # remove message file _file = os.path.join( self.parent._file_directory, xpath.queryForNodes("/message/x/file", element, )[0].__str__(), ) os.remove(_file, ) # send return message _q = xmppim.Query(element["from"], ) _q["id"] = element["id"] if isinstance(_none, Failure, ) : _error = StanzaError( "bad-request", #text=_none.getTraceback(), ) from flaskon.app.io._exceptions import AlreadyImported if _none.check(AlreadyImported, ) : _error.type = "already-imported" del _q.children[_q.children.index(_q._element_x, ) - 1] _element_x = domish.Element((xmppim.Query.XMLNS, "x"), ) _e = _error.toResponse(_element_x, ) _e.defaultUri = _e.uri = xmppim.Query.XMLNS _q.addChild(_e, ) else : _q._element_x["type"] = "success" self.send(_q, )
def error(failure): if failure.check(StanzaError): exc = failure.value else: log.err(failure) exc = StanzaError('internal-error') return exc.toResponse(iq)
def error(failure): if failure.check(StanzaError): exc = failure.value else: log.err(failure) exc = StanzaError('internal-error') return exc.toResponse(iq)
def onFrame(self, iq): jid = toJID(iq['from']) neighbor = self._findNeighbor(jid) if neighbor: neighbor.onFrame(iq) else: iq.handled = True error = StanzaError('not-authorized') self.send(error.toResponse(iq))
def test_pingNotSupported(self): """ Pinging a service should fire a deferred with None if not supported. """ def cb(result): self.assertIdentical(None, result) d = self.protocol.ping(JID("example.com")) d.addCallback(cb) iq = self.stub.output[-1] exc = StanzaError('service-unavailable') response = exc.toResponse(iq) self.stub.send(response) return d
def test_pingNotSupported(self): """ Pinging a service should fire a deferred with None if not supported. """ def cb(result): self.assertIdentical(None, result) d = self.protocol.ping(JID("example.com")) d.addCallback(cb) iq = self.stub.output[-1] exc = StanzaError('service-unavailable') response = exc.toResponse(iq) self.stub.send(response) return d
def onFrame(self, iq): iq.handled = True frame = Frame.from_dom(iq) if frame.seq != self.in_seq_recv + 1: log.warning("Ignoring out-of-sequence frame from %s", self.jid.full()) error = StanzaError('bad-request') self.link.send(error.toResponse(iq)) return # ACK self.in_buf.append(frame) self.in_seq_recv += 1 self.link.send(toResponse(iq, 'result')) if not frame.more: self._do_recv()
def test_pingStanzaError(self): """ Pinging a service should errback a deferred on other (stanza) errors. """ def cb(exc): self.assertEquals('item-not-found', exc.condition) d = self.protocol.ping(JID("example.com")) self.assertFailure(d, StanzaError) d.addCallback(cb) iq = self.stub.output[-1] exc = StanzaError('item-not-found') response = exc.toResponse(iq) self.stub.send(response) return d
def test_pingStanzaError(self): """ Pinging a service should errback a deferred on other (stanza) errors. """ def cb(exc): self.assertEquals('item-not-found', exc.condition) d = self.protocol.ping(JID("example.com")) self.assertFailure(d, StanzaError) d.addCallback(cb) iq = self.stub.output[-1] exc = StanzaError('item-not-found') response = exc.toResponse(iq) self.stub.send(response) return d