comparison src/core/xmpp.py @ 1573:6338677f3a89

core (client): added a sendError method to easily build error response from <IQ\> stanza
author Goffi <goffi@goffi.org>
date Wed, 11 Nov 2015 14:56:05 +0100
parents 001b62bed67c
children 5b24d6bf5d15
comparison
equal deleted inserted replaced
1572:6a6fe840c3a6 1573:6338677f3a89
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from twisted.internet import task, defer 22 from twisted.internet import task, defer
23 from twisted.words.protocols.jabber import jid, xmlstream 23 from twisted.words.protocols.jabber import jid, xmlstream
24 from twisted.words.protocols.jabber import error
24 from wokkel import client, disco, xmppim, generic, delay, iwokkel 25 from wokkel import client, disco, xmppim, generic, delay, iwokkel
25 from sat.core.log import getLogger 26 from sat.core.log import getLogger
26 log = getLogger(__name__) 27 log = getLogger(__name__)
27 from sat.core import exceptions 28 from sat.core import exceptions
28 from calendar import timegm 29 from calendar import timegm
56 @param timeout(None, int): timeout in seconds 57 @param timeout(None, int): timeout in seconds
57 """ 58 """
58 iq_elt = xmlstream.IQ(self.xmlstream, type_) 59 iq_elt = xmlstream.IQ(self.xmlstream, type_)
59 iq_elt.timeout = timeout 60 iq_elt.timeout = timeout
60 return iq_elt 61 return iq_elt
62
63 def sendError(self, iq_elt, condition):
64 """Send error stanza build from iq_elt
65
66 @param iq_elt(domish.Element): initial IQ element
67 @param condition(unicode): error condition
68 """
69 iq_error_elt = error.StanzaError(condition).toResponse(iq_elt)
70 self.xmlstream.send(iq_error_elt)
61 71
62 def _authd(self, xmlstream): 72 def _authd(self, xmlstream):
63 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile): 73 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile):
64 return 74 return
65 client.XMPPClient._authd(self, xmlstream) 75 client.XMPPClient._authd(self, xmlstream)