code style reformatting using black

This commit is contained in:
Goffi 2018-06-27 20:14:46 +02:00
commit 744cb0c503

View file

@ -21,25 +21,27 @@ from sat.core.constants import Const as C
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 @@ PLUGIN_INFO = {
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 @@ class XEP_0070(object):
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 @@ class XEP_0070(object):
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 @@ class XEP_0070(object):
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 @@ class XEP_0070_handler(XMPPHandler):
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 []