comparison src/plugins/plugin_xep_0020.py @ 594:e629371a28d3

Fix pep8 support in src/plugins.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:35 +0100
parents beaf6bec2fcd
children 84a6e83157c2
comparison
equal deleted inserted replaced
593:70bae685d05c 594:e629371a28d3
33 from wokkel import disco, iwokkel, data_form 33 from wokkel import disco, iwokkel, data_form
34 34
35 NS_FEATURE_NEG = 'http://jabber.org/protocol/feature-neg' 35 NS_FEATURE_NEG = 'http://jabber.org/protocol/feature-neg'
36 36
37 PLUGIN_INFO = { 37 PLUGIN_INFO = {
38 "name": "XEP 0020 Plugin", 38 "name": "XEP 0020 Plugin",
39 "import_name": "XEP-0020", 39 "import_name": "XEP-0020",
40 "type": "XEP", 40 "type": "XEP",
41 "protocols": ["XEP-0020"], 41 "protocols": ["XEP-0020"],
42 "main": "XEP_0020", 42 "main": "XEP_0020",
43 "handler": "yes", 43 "handler": "yes",
44 "description": _("""Implementation of Feature Negotiation""") 44 "description": _("""Implementation of Feature Negotiation""")
45 } 45 }
46
46 47
47 class XEP_0020(object): 48 class XEP_0020(object):
48 49
49 def __init__(self, host): 50 def __init__(self, host):
50 info(_("Plugin XEP_0020 initialization")) 51 info(_("Plugin XEP_0020 initialization"))
65 form = data_form.Form.fromElement(elt.firstChildElement()) 66 form = data_form.Form.fromElement(elt.firstChildElement())
66 result = {} 67 result = {}
67 for field in form.fields: 68 for field in form.fields:
68 values = form.fields[field].values 69 values = form.fields[field].values
69 result[field] = values[0] if values else None 70 result[field] = values[0] if values else None
70 if len(values)>1: 71 if len(values) > 1:
71 warning(_("More than one value choosed for %s, keeping the first one") % field) 72 warning(_("More than one value choosed for %s, keeping the first one") % field)
72 return result 73 return result
73 74
74 def negociate(self, feature_elt, form_type, negociable_values): 75 def negociate(self, feature_elt, form_type, negociable_values):
75 """Negociate the feature options 76 """Negociate the feature options
90 x_form = data_form.Form('submit') 91 x_form = data_form.Form('submit')
91 x_form.makeFields(options_dict) 92 x_form.makeFields(options_dict)
92 feature_elt.addChild(x_form.toElement()) 93 feature_elt.addChild(x_form.toElement())
93 return feature_elt 94 return feature_elt
94 95
95 def proposeFeatures(self, options_dict, namespace = None): 96 def proposeFeatures(self, options_dict, namespace=None):
96 """Build a feature element with options to propose 97 """Build a feature element with options to propose
97 @param options_dict: dict with feature as key and list of acceptable options as value 98 @param options_dict: dict with feature as key and list of acceptable options as value
98 @param namespace: feature namespace""" 99 @param namespace: feature namespace"""
99 feature_elt = domish.Element((NS_FEATURE_NEG, 'feature')) 100 feature_elt = domish.Element((NS_FEATURE_NEG, 'feature'))
100 x_form = data_form.Form('form', formNamespace=namespace) 101 x_form = data_form.Form('form', formNamespace=namespace)
102 x_form.addField(data_form.Field('list-single', field, 103 x_form.addField(data_form.Field('list-single', field,
103 options=[data_form.Option(_option) for _option in options_dict[field]])) 104 options=[data_form.Option(_option) for _option in options_dict[field]]))
104 feature_elt.addChild(x_form.toElement()) 105 feature_elt.addChild(x_form.toElement())
105 return feature_elt 106 return feature_elt
106 107
108
107 class XEP_0020_handler(XMPPHandler): 109 class XEP_0020_handler(XMPPHandler):
108 implements(iwokkel.IDisco) 110 implements(iwokkel.IDisco)
109 111
110 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): 112 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
111 return [disco.DiscoFeature(NS_FEATURE_NEG)] 113 return [disco.DiscoFeature(NS_FEATURE_NEG)]
112 114
113 def getDiscoItems(self, requestor, target, nodeIdentifier=''): 115 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
114 return [] 116 return []
115