Mercurial > libervia-backend
diff src/plugins/plugin_xep_0100.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 |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0100.py Mon Jan 21 00:59:50 2013 +0100 +++ b/src/plugins/plugin_xep_0100.py Fri Jan 18 17:55:35 2013 +0100 @@ -25,86 +25,85 @@ import twisted.internet.error PLUGIN_INFO = { -"name": "Gateways Plugin", -"import_name": "XEP-0100", -"type": "XEP", -"protocols": ["XEP-0100"], -"dependencies": ["XEP-0077"], -"main": "XEP_0100", -"description": _("""Implementation of Gateways protocol""") + "name": "Gateways Plugin", + "import_name": "XEP-0100", + "type": "XEP", + "protocols": ["XEP-0100"], + "dependencies": ["XEP-0077"], + "main": "XEP_0100", + "description": _("""Implementation of Gateways protocol""") } + class XEP_0100(object): def __init__(self, host): info(_("Gateways plugin initialization")) self.host = host - self.__gateways = {} #dict used to construct the answer to findGateways. Key = target jid + self.__gateways = {} # dict used to construct the answer to findGateways. Key = target jid host.bridge.addMethod("findGateways", ".plugin", in_sign='ss', out_sign='s', method=self.findGateways) host.bridge.addMethod("gatewayRegister", ".plugin", in_sign='ssa(ss)s', out_sign='s', method=self.gatewayRegister) def __inc_handled_items(self, request_id, profile): - self.__gateways[request_id]['__handled_items']+=1 + self.__gateways[request_id]['__handled_items'] += 1 if self.__gateways[request_id]['__total_items'] == self.__gateways[request_id]['__handled_items']: - debug (_("All items checked for id [%s]") % str(request_id)) + debug(_("All items checked for id [%s]") % str(request_id)) del self.__gateways[request_id]['__total_items'] del self.__gateways[request_id]['__handled_items'] - self.host.actionResultExt(request_id,"DICT_DICT",self.__gateways[request_id], profile) + self.host.actionResultExt(request_id, "DICT_DICT", self.__gateways[request_id], profile) def discoInfo(self, disco, entity, request_id, profile): """Find disco infos about entity, to check if it is a gateway""" for identity in disco.identities: if identity[0] == 'gateway': - print (_("Found gateway (%(jid)s): %(identity)s") % {'jid':entity.full(), 'identity':disco.identities[identity]}) + print (_("Found gateway (%(jid)s): %(identity)s") % {'jid': entity.full(), 'identity': disco.identities[identity]}) self.__gateways[request_id][entity.full()] = { - 'name':disco.identities[identity], - 'type':identity[1] + 'name': disco.identities[identity], + 'type': identity[1] } self.__inc_handled_items(request_id, profile) def discoInfoErr(self, failure, entity, request_id, profile): """Something is going wrong with disco""" - failure.trap(jab_error.StanzaError,twisted.internet.error.ConnectionLost) - error(_("Error when discovering [%(jid)s]: %(error)s") % {'jid':entity.full(), 'error':failure.getErrorMessage()}) + failure.trap(jab_error.StanzaError, twisted.internet.error.ConnectionLost) + error(_("Error when discovering [%(jid)s]: %(error)s") % {'jid': entity.full(), 'error': failure.getErrorMessage()}) self.__inc_handled_items(request_id, profile) - def discoItems(self, disco, request_id, target, client): """Look for items with disco protocol, and ask infos for each one""" #FIXME: target is used as we can't find the original iq node (parent is None) # an other way would avoid this useless parameter (is there a way with wokkel ?) if len(disco._items) == 0: - debug (_("No gateway found")) - self.host.actionResultExt(request_id,"DICT_DICT",{}) + debug(_("No gateway found")) + self.host.actionResultExt(request_id, "DICT_DICT", {}) return - self.__gateways[request_id] = {'__total_items':len(disco._items), '__handled_items':0, '__private__':{'target':target.full()}} + self.__gateways[request_id] = {'__total_items': len(disco._items), '__handled_items': 0, '__private__': {'target': target.full()}} for item in disco._items: #TODO: need to set a timeout for theses requests - debug (_("item found: %s"), item.name) + debug(_("item found: %s"), item.name) client.disco.requestInfo(item.entity).addCallback(self.discoInfo, entity=item.entity, request_id=request_id, profile=client.profile).addErrback(self.discoInfoErr, entity=item.entity, request_id=request_id, profile=client.profile) def discoItemsErr(self, failure, request_id, target, client): """Something is going wrong with disco""" - error(_("Error when discovering [%(target)s]: %(condition)s") % {'target':target.full(), 'condition':unicode(failure.value)}) - message_data={"reason": "connection error", "message":_(u"Error while trying to discover %(target)s gateways: %(error_mess)s") % {'target':target.full(), 'error_mess':unicode(failure.value)}} + error(_("Error when discovering [%(target)s]: %(condition)s") % {'target': target.full(), 'condition': unicode(failure.value)}) + message_data = {"reason": "connection error", "message": _(u"Error while trying to discover %(target)s gateways: %(error_mess)s") % {'target': target.full(), 'error_mess': unicode(failure.value)}} self.host.bridge.actionResult("ERROR", request_id, message_data) - def registrationSuccessful(self, target, profile): """Called when in_band registration is ok, we must now follow the rest of procedure""" - debug (_("Registration successful, doing the rest")) + debug(_("Registration successful, doing the rest")) self.host.addContact(target, profile) self.host.setPresence(target, profile) def gatewayRegister(self, action, target, fields, profile_key='@DEFAULT@'): """Register gateway using in-band registration, then log-in to gateway""" profile = self.host.memory.getProfileName(profile_key) - assert(profile) #FIXME: return an error here + assert(profile) # FIXME: return an error here if action == 'SUBMIT': self.host.plugins["XEP-0077"].addTrigger(target, self.registrationSuccessful, profile) return self.host.plugins["XEP-0077"].in_band_submit(action, target, fields, profile) @@ -117,7 +116,7 @@ client = self.host.getClient(profile_key) assert(client) to_jid = jid.JID(target) - debug (_("find gateways (target = %(target)s, profile = %(profile)s)") % {'target':to_jid.full(), 'profile':profile}) + debug(_("find gateways (target = %(target)s, profile = %(profile)s)") % {'target': to_jid.full(), 'profile': profile}) request_id = self.host.get_next_id() - client.disco.requestItems(to_jid).addCallback(self.discoItems, request_id=request_id, target = to_jid, client = client).addErrback(self.discoItemsErr, request_id=request_id, target = to_jid, client = client) + client.disco.requestItems(to_jid).addCallback(self.discoItems, request_id=request_id, target=to_jid, client=client).addErrback(self.discoItemsErr, request_id=request_id, target=to_jid, client=client) return request_id