diff src/plugins/plugin_xep_0095.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_0095.py	Mon Jan 21 00:59:50 2013 +0100
+++ b/src/plugins/plugin_xep_0095.py	Fri Jan 18 17:55:35 2013 +0100
@@ -43,21 +43,22 @@
 SI_PROFILE_HEADER = "http://jabber.org/protocol/si/profile/"
 
 PLUGIN_INFO = {
-"name": "XEP 0095 Plugin",
-"import_name": "XEP-0095",
-"type": "XEP",
-"protocols": ["XEP-0095"],
-"main": "XEP_0095",
-"handler": "yes",
-"description": _("""Implementation of Stream Initiation""")
+    "name": "XEP 0095 Plugin",
+    "import_name": "XEP-0095",
+    "type": "XEP",
+    "protocols": ["XEP-0095"],
+    "main": "XEP_0095",
+    "handler": "yes",
+    "description": _("""Implementation of Stream Initiation""")
 }
 
+
 class XEP_0095(object):
 
     def __init__(self, host):
         info(_("Plugin XEP_0095 initialization"))
         self.host = host
-        self.si_profiles = {} #key: SI profile, value: callback
+        self.si_profiles = {}  # key: SI profile, value: callback
 
     def getHandler(self, profile):
         return XEP_0095_handler(self)
@@ -66,33 +67,33 @@
         """Add a callback for a SI Profile
         param si_profile: SI profile name (e.g. file-transfer)
         param callback: method to call when the profile name is asked"""
-        self.si_profiles[si_profile] =  callback
+        self.si_profiles[si_profile] = callback
 
     def streamInit(self, iq_el, profile):
         """This method is called on stream initiation (XEP-0095 #3.2)
         @param iq_el: IQ element
         @param profile: %(doc_profile)s"""
-        info (_("XEP-0095 Stream initiation"))
-        iq_el.handled=True
+        info(_("XEP-0095 Stream initiation"))
+        iq_el.handled = True
         si_el = iq_el.firstChildElement()
         si_id = si_el.getAttribute('id')
         si_mime_type = iq_el.getAttribute('mime-type', 'application/octet-stream')
         si_profile = si_el.getAttribute('profile')
-        si_profile_key =  si_profile[len(SI_PROFILE_HEADER):] if si_profile.startswith(SI_PROFILE_HEADER) else si_profile
-        if self.si_profiles.has_key(si_profile_key):
+        si_profile_key = si_profile[len(SI_PROFILE_HEADER):] if si_profile.startswith(SI_PROFILE_HEADER) else si_profile
+        if si_profile_key in self.si_profiles:
             #We know this SI profile, we call the callback
             self.si_profiles[si_profile_key](iq_el['id'], iq_el['from'], si_id, si_mime_type, si_el, profile)
         else:
             #We don't know this profile, we send an error
             self.sendBadProfileError(iq_el['id'], iq_el['from'], profile)
 
-    def sendRejectedError(self, iq_id, to_jid, reason = 'Offer Declined', profile='@NONE@'):
+    def sendRejectedError(self, iq_id, to_jid, reason='Offer Declined', profile='@NONE@'):
         """Helper method to send when the stream is rejected
         @param iq_id: IQ id
         @param to_jid: recipient
         @param reason: human readable reason (string)
         @param profile: %(doc_profile)s"""
-        self.sendError(iq_id, to_jid, 403, 'cancel', {'text':reason}, profile=profile)
+        self.sendError(iq_id, to_jid, 403, 'cancel', {'text': reason}, profile=profile)
 
     def sendBadProfileError(self, iq_id, to_jid, profile):
         """Helper method to send when we don't know the SI profile
@@ -113,7 +114,7 @@
         @param iq_id: IQ id
         @param to_jid: recipient
         @param profile: %(doc_profile)s"""
-        self.sendError(iq_id, to_jid, 500, 'cancel', {'custom':'failed'}, profile=profile) #as there is no error code for failed transfer, we use 500 (undefined-condition)
+        self.sendError(iq_id, to_jid, 500, 'cancel', {'custom': 'failed'}, profile=profile)  # as there is no error code for failed transfer, we use 500 (undefined-condition)
 
     def sendError(self, iq_id, to_jid, err_code, err_type='cancel', data={}, profile='@NONE@'):
         """Send IQ error as a result
@@ -131,21 +132,21 @@
         result['id'] = iq_id
         result['to'] = to_jid
         error_el = result.addElement('error')
-        error_el['err_code'] =  str(err_code)
+        error_el['err_code'] = str(err_code)
         error_el['type'] = err_type
-        if err_code==400 and err_type=='cancel':
-            error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','bad-request'))
-            error_el.addElement((NS_SI,'no-valid-streams'))
-        elif err_code==400 and err_type=='modify':
-            error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','bad-request'))
-            error_el.addElement((NS_SI,'bad-profile'))
-        elif err_code==403 and err_type=='cancel':
-            error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','forbidden'))
-            if data.has_key('text'):
-                error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','text'), content=data['text'])
-        elif err_code==500 and err_type=='cancel':
-            condition_el = error_el.addElement((NS_SI,'undefined-condition'))
-            if data.has_key('custom') and data['custom']=='failed':
+        if err_code == 400 and err_type == 'cancel':
+            error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'bad-request'))
+            error_el.addElement((NS_SI, 'no-valid-streams'))
+        elif err_code == 400 and err_type == 'modify':
+            error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'bad-request'))
+            error_el.addElement((NS_SI, 'bad-profile'))
+        elif err_code == 403 and err_type == 'cancel':
+            error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'forbidden'))
+            if 'text' in data:
+                error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas', 'text'), content=data['text'])
+        elif err_code == 500 and err_type == 'cancel':
+            condition_el = error_el.addElement((NS_SI, 'undefined-condition'))
+            if 'custom' in data and data['custom'] == 'failed':
                 condition_el.addContent('Stream failed')
 
         _client.xmlstream.send(result)
@@ -158,7 +159,7 @@
         @param profile: %(doc_profile)s"""
         _client = self.host.getClient(profile)
         assert(_client)
-        info (_("sending stream initiation accept answer"))
+        info(_("sending stream initiation accept answer"))
         result = domish.Element((None, 'iq'))
         result['type'] = 'result'
         result['id'] = iq_id
@@ -180,16 +181,16 @@
         @return: session id, offer"""
         current_jid, xmlstream = self.host.getJidNStream(profile_key)
         if not xmlstream:
-            error (_('Asking for an non-existant or not connected profile'))
+            error(_('Asking for an non-existant or not connected profile'))
             return ""
 
-        offer = client.IQ(xmlstream,'set')
+        offer = client.IQ(xmlstream, 'set')
         sid = str(uuid.uuid4())
-        debug (_("Stream Session ID: %s") % offer["id"])
+        debug(_("Stream Session ID: %s") % offer["id"])
 
         offer["from"] = current_jid.full()
         offer["to"] = to_jid.full()
-        si=offer.addElement('si',NS_SI)
+        si = offer.addElement('si', NS_SI)
         si['id'] = sid
         si["mime-type"] = mime_type
         si["profile"] = si_profile
@@ -209,11 +210,10 @@
         self.host = plugin_parent.host
 
     def connectionInitialized(self):
-        self.xmlstream.addObserver(SI_REQUEST, self.plugin_parent.streamInit, profile = self.parent.profile)
+        self.xmlstream.addObserver(SI_REQUEST, self.plugin_parent.streamInit, profile=self.parent.profile)
 
     def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
         return [disco.DiscoFeature(NS_SI)] + [disco.DiscoFeature("http://jabber.org/protocol/si/profile/%s" % profile_name) for profile_name in self.plugin_parent.si_profiles]
 
     def getDiscoItems(self, requestor, target, nodeIdentifier=''):
         return []
-