code style reformatting using black

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

View file

@ -20,6 +20,7 @@
from sat.core.i18n import _
from sat.core.constants import Const as C
from sat.core.log import getLogger
log = getLogger(__name__)
from sat.core import exceptions
from twisted.words.xish import domish
@ -33,7 +34,7 @@ except ImportError:
from wokkel import disco, iwokkel, data_form
NS_FEATURE_NEG = 'http://jabber.org/protocol/feature-neg'
NS_FEATURE_NEG = "http://jabber.org/protocol/feature-neg"
PLUGIN_INFO = {
C.PI_NAME: "XEP 0020 Plugin",
@ -42,12 +43,11 @@ PLUGIN_INFO = {
C.PI_PROTOCOLS: ["XEP-0020"],
C.PI_MAIN: "XEP_0020",
C.PI_HANDLER: "yes",
C.PI_DESCRIPTION: _("""Implementation of Feature Negotiation""")
C.PI_DESCRIPTION: _("""Implementation of Feature Negotiation"""),
}
class XEP_0020(object):
def __init__(self, host):
log.info(_("Plugin XEP_0020 initialization"))
@ -62,7 +62,7 @@ class XEP_0020(object):
@raise exceptions.NotFound: no feature element found
"""
try:
feature_elt = elt.elements(NS_FEATURE_NEG, 'feature').next()
feature_elt = elt.elements(NS_FEATURE_NEG, "feature").next()
except StopIteration:
raise exceptions.NotFound
return feature_elt
@ -100,7 +100,11 @@ class XEP_0020(object):
values = form.fields[field].values
result[field] = values[0] if values else None
if len(values) > 1:
log.warning(_(u"More than one value choosed for {}, keeping the first one").format(field))
log.warning(
_(
u"More than one value choosed for {}, keeping the first one"
).format(field)
)
return result
def negotiate(self, feature_elt, name, negotiable_values, namespace):
@ -126,8 +130,8 @@ class XEP_0020(object):
@param options(dict): dict with feature as key and choosed option as value
@param namespace (None, unicode): form namespace or None to ignore
"""
feature_elt = domish.Element((NS_FEATURE_NEG, 'feature'))
x_form = data_form.Form('submit', formNamespace=namespace)
feature_elt = domish.Element((NS_FEATURE_NEG, "feature"))
x_form = data_form.Form("submit", formNamespace=namespace)
x_form.makeFields(options)
feature_elt.addChild(x_form.toElement())
return feature_elt
@ -138,11 +142,16 @@ class XEP_0020(object):
@param options_dict(dict): dict with feature as key and iterable of acceptable options as value
@param namespace(None, unicode): feature namespace
"""
feature_elt = domish.Element((NS_FEATURE_NEG, 'feature'))
x_form = data_form.Form('form', formNamespace=namespace)
feature_elt = domish.Element((NS_FEATURE_NEG, "feature"))
x_form = data_form.Form("form", formNamespace=namespace)
for field in options_dict:
x_form.addField(data_form.Field('list-single', field,
options=[data_form.Option(option) for option in options_dict[field]]))
x_form.addField(
data_form.Field(
"list-single",
field,
options=[data_form.Option(option) for option in options_dict[field]],
)
)
feature_elt.addChild(x_form.toElement())
return feature_elt
@ -150,8 +159,8 @@ class XEP_0020(object):
class XEP_0020_handler(XMPPHandler):
implements(iwokkel.IDisco)
def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
return [disco.DiscoFeature(NS_FEATURE_NEG)]
def getDiscoItems(self, requestor, target, nodeIdentifier=''):
def getDiscoItems(self, requestor, target, nodeIdentifier=""):
return []