changeset 2094:438a49dbfe87

xep-0070: fixed use of byte string instead of unicode
author Goffi <goffi@goffi.org>
date Sun, 18 Dec 2016 10:16:47 +0100
parents cbf3af02e941
children 522c4c8903f9
files src/plugins/plugin_xep_0070.py
diffstat 1 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0070.py	Sun Dec 18 10:15:57 2016 +0100
+++ b/src/plugins/plugin_xep_0070.py	Sun Dec 18 10:16:47 2016 +0100
@@ -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 @@
     """
 
     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 @@
 
     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 @@
         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 @@
         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)