diff sat/plugins/plugin_xep_0070.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children a55a14c3cbf4
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0070.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat/plugins/plugin_xep_0070.py	Wed Jun 27 20:14:46 2018 +0200
@@ -21,25 +21,27 @@
 from sat.core.log import getLogger
 from twisted.words.protocols.jabber import xmlstream
 from twisted.words.protocols import jabber
+
 log = getLogger(__name__)
 from sat.tools import xml_tools
 
 from wokkel import disco, iwokkel
 from zope.interface import implements
+
 try:
     from twisted.words.protocols.xmlstream import XMPPHandler
 except ImportError:
     from wokkel.subprotocols import XMPPHandler
 
 
-NS_HTTP_AUTH = 'http://jabber.org/protocol/http-auth'
+NS_HTTP_AUTH = "http://jabber.org/protocol/http-auth"
 
-IQ = 'iq'
-IQ_GET = '/'+IQ+'[@type="get"]'
+IQ = "iq"
+IQ_GET = "/" + IQ + '[@type="get"]'
 IQ_HTTP_AUTH_REQUEST = IQ_GET + '/confirm[@xmlns="' + NS_HTTP_AUTH + '"]'
 
-MSG = 'message'
-MSG_GET = '/'+MSG+'[@type="normal"]'
+MSG = "message"
+MSG_GET = "/" + MSG + '[@type="normal"]'
 MSG_HTTP_AUTH_REQUEST = MSG_GET + '/confirm[@xmlns="' + NS_HTTP_AUTH + '"]'
 
 
@@ -51,7 +53,7 @@
     C.PI_DEPENDENCIES: [],
     C.PI_MAIN: "XEP_0070",
     C.PI_HANDLER: "yes",
-    C.PI_DESCRIPTION: _("""Implementation of HTTP Requests via XMPP""")
+    C.PI_DESCRIPTION: _("""Implementation of HTTP Requests via XMPP"""),
 }
 
 
@@ -88,16 +90,20 @@
 
     def _treatHttpAuthRequest(self, elt, stanzaType, client):
         elt.handled = True
-        auth_elt = elt.elements(NS_HTTP_AUTH, 'confirm').next()
-        auth_id = auth_elt['id']
-        auth_method = auth_elt['method']
-        auth_url = auth_elt['url']
+        auth_elt = elt.elements(NS_HTTP_AUTH, "confirm").next()
+        auth_id = auth_elt["id"]
+        auth_method = auth_elt["method"]
+        auth_url = auth_elt["url"]
         self._dictRequest[client] = (auth_id, auth_method, auth_url, stanzaType, elt)
 
-        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 = 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(
+            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)
@@ -107,7 +113,7 @@
     def _authRequestCallback(self, result, profile):
         client = self.host.getClient(profile)
         try:
-            cancelled = result['cancelled']
+            cancelled = result["cancelled"]
         except KeyError:
             cancelled = False
 
@@ -119,23 +125,25 @@
             authorized = False
         else:
             try:
-                auth_id, auth_method, auth_url, stanzaType, elt = self._dictRequest[client]
+                auth_id, auth_method, auth_url, stanzaType, elt = self._dictRequest[
+                    client
+                ]
                 del self._dictRequest[client]
                 authorized = True
             except KeyError:
                 authorized = False
 
         if authorized:
-            if (stanzaType == IQ):
+            if stanzaType == IQ:
                 # iq
                 log.debug(_(u"XEP-0070 reply iq"))
-                iq_result_elt = xmlstream.toResponse(elt, 'result')
+                iq_result_elt = xmlstream.toResponse(elt, "result")
                 client.send(iq_result_elt)
-            elif (stanzaType == MSG):
+            elif stanzaType == MSG:
                 # 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())
+                msg_result_elt = xmlstream.toResponse(elt, "result")
+                msg_result_elt.addChild(elt.elements(NS_HTTP_AUTH, "confirm").next())
                 client.send(msg_result_elt)
         else:
             log.debug(_(u"XEP-0070 reply error"))
@@ -152,11 +160,19 @@
         self.profile = profile
 
     def connectionInitialized(self):
-        self.xmlstream.addObserver(IQ_HTTP_AUTH_REQUEST, self.plugin_parent.onHttpAuthRequestIQ, client=self.parent)
-        self.xmlstream.addObserver(MSG_HTTP_AUTH_REQUEST, self.plugin_parent.onHttpAuthRequestMsg, client=self.parent)
+        self.xmlstream.addObserver(
+            IQ_HTTP_AUTH_REQUEST,
+            self.plugin_parent.onHttpAuthRequestIQ,
+            client=self.parent,
+        )
+        self.xmlstream.addObserver(
+            MSG_HTTP_AUTH_REQUEST,
+            self.plugin_parent.onHttpAuthRequestMsg,
+            client=self.parent,
+        )
 
-    def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
+    def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
         return [disco.DiscoFeature(NS_HTTP_AUTH)]
 
-    def getDiscoItems(self, requestor, target, nodeIdentifier=''):
+    def getDiscoItems(self, requestor, target, nodeIdentifier=""):
         return []