xep-0070: fixed use of byte string instead of unicode

This commit is contained in:
Goffi 2016-12-18 10:16:47 +01:00
commit 9a9ac75b20

View file

@ -17,8 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _, D_
from sat.core.constants import Const as C
from sat.core.i18n import _
from sat.core.log import getLogger
from twisted.words.protocols.jabber import xmlstream
from twisted.words.protocols import jabber
@ -62,7 +60,7 @@ class XEP_0070(object):
"""
def __init__(self, host):
log.info(_("Plugin XEP_0070 initialization"))
log.info(_(u"Plugin XEP_0070 initialization"))
self.host = host
self._dictRequest = dict()
@ -71,15 +69,19 @@ class XEP_0070(object):
def onHttpAuthRequestIQ(self, iq_elt, client):
"""This method is called on confirmation request received (XEP-0070 #4.5)
@param iq_elt: IQ element
@param client: %(doc_client)s"""
@param client: %(doc_client)s
"""
log.info(_("XEP-0070 Verifying HTTP Requests via XMPP (iq)"))
self._treatHttpAuthRequest(iq_elt, IQ, client)
def onHttpAuthRequestMsg(self, msg_elt, client):
"""This method is called on confirmation request received (XEP-0070 #4.5)
@param msg_elt: message element
@param client: %(doc_client)s"""
@param client: %(doc_client)s
"""
log.info(_("XEP-0070 Verifying HTTP Requests via XMPP (message)"))
self._treatHttpAuthRequest(msg_elt, MSG, client)
@ -91,15 +93,15 @@ class XEP_0070(object):
auth_url = auth_elt['url']
self._dictRequest[client] = (auth_id, auth_method, auth_url, stanzaType, elt)
confirm_ui = xml_tools.XMLUI("form", title=D_("Auth confirmation"), submit_id='')
confirm_ui.addText(D_("{} needs to validate your identity, do you agree ?".format(auth_url)))
confirm_ui.addText(D_("Validation code : {}".format(auth_id)))
confirm_ui.addText(D_("Please check that this code is the same as on {}".format(auth_url)))
confirm_ui.addText("")
confirm_ui.addText(D_("Submit to authorize, cancel otherwise."))
confirm_ui = xml_tools.XMLUI("form", title=D_(u"Auth confirmation"), submit_id='')
confirm_ui.addText(D_(u"{} needs to validate your identity, do you agree ?".format(auth_url)))
confirm_ui.addText(D_(u"Validation code : {}".format(auth_id)))
confirm_ui.addText(D_(u"Please check that this code is the same as on {}".format(auth_url)))
confirm_ui.addText(u"")
confirm_ui.addText(D_(u"Submit to authorize, cancel otherwise."))
d = xml_tools.deferredUI(self.host, confirm_ui, chained=False)
d.addCallback(self._authRequestCallback, client.profile)
self.host.actionNew({"xmlui": confirm_ui.toXml()}, profile=client.profile)
self.host.actionNew({u"xmlui": confirm_ui.toXml()}, profile=client.profile)
def _authRequestCallback(self, result, profile):
client = self.host.getClient(profile)
@ -125,17 +127,17 @@ class XEP_0070(object):
if authorized:
if (stanzaType == IQ):
# iq
log.debug(_("XEP-0070 reply iq"))
log.debug(_(u"XEP-0070 reply iq"))
iq_result_elt = xmlstream.toResponse(elt, 'result')
client.xmlstream.send(iq_result_elt)
elif (stanzaType == MSG):
# message
log.debug(_("XEP-0070 reply message"))
log.debug(_(u"XEP-0070 reply message"))
msg_result_elt = xmlstream.toResponse(elt, 'result')
msg_result_elt.addChild(elt.elements(NS_HTTP_AUTH, 'confirm').next())
client.xmlstream.send(msg_result_elt)
else:
log.debug(_("XEP-0070 reply error"))
log.debug(_(u"XEP-0070 reply error"))
result_elt = jabber.error.StanzaError("not-authorized").toResponse(elt)
client.xmlstream.send(result_elt)