diff libervia.py @ 226:744426c2b699

browser_side, misc: better PEP8 compliance
author souliane <souliane@mailoo.org>
date Thu, 26 Sep 2013 14:32:24 +0200
parents 624a87377412
children 67e24c342e7f
line wrap: on
line diff
--- a/libervia.py	Thu Sep 26 11:39:54 2013 +0200
+++ b/libervia.py	Thu Sep 26 14:32:24 2013 +0200
@@ -19,7 +19,7 @@
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-import pyjd # this is dummy in pyjs
+import pyjd  # this is dummy in pyjs
 from pyjamas.ui.RootPanel import RootPanel
 from pyjamas.ui.HTML import HTML
 from pyjamas.ui.KeyboardListener import KEY_ESCAPE
@@ -39,12 +39,12 @@
 class LiberviaJsonProxy(JSONProxy):
     def __init__(self, *args, **kwargs):
         JSONProxy.__init__(self, *args, **kwargs)
-        self.handler=self
-        self.cb={}
-        self.eb={}
+        self.handler = self
+        self.cb = {}
+        self.eb = {}
 
     def call(self, method, cb, *args):
-        _id = self.callMethod(method,args)
+        _id = self.callMethod(method, args)
         if cb:
             if isinstance(cb, tuple):
                 if len(cb) != 2:
@@ -69,7 +69,7 @@
             del self.cb[request_info.id]
             if request_info.id in self.eb:
                 del self.eb[request_info.id]
-    
+
     def onRemoteError(self, code, errobj, request_info):
         """def dump(obj):
             print "\n\nDUMPING %s\n\n" % obj
@@ -86,7 +86,7 @@
                 """for o in code, error, request_info:
                     dump(o)"""
             else:
-                if isinstance(errobj['message'],dict):
+                if isinstance(errobj['message'], dict):
                    print("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString']))
                 else:
                    print("Error: %s" % errobj['message'])
@@ -94,7 +94,7 @@
 class RegisterCall(LiberviaJsonProxy):
     def __init__(self):
         LiberviaJsonProxy.__init__(self, "/register_api",
-                        ["isRegistered","isConnected","connect"])
+                        ["isRegistered", "isConnected", "connect"])
 
 class BridgeCall(LiberviaJsonProxy):
     def __init__(self):
@@ -114,12 +114,12 @@
 
     def __init__(self, host):
         self.host = host
-        self.retry_delay = self.RETRY_BASE_DELAY 
+        self.retry_delay = self.RETRY_BASE_DELAY
         LiberviaJsonProxy.__init__(self, "/json_signal_api",
                         ["getSignals"])
 
     def onRemoteResponse(self, response, request_info):
-        self.retry_delay = self.RETRY_BASE_DELAY 
+        self.retry_delay = self.RETRY_BASE_DELAY
         LiberviaJsonProxy.onRemoteResponse(self, response, request_info)
 
 
@@ -166,9 +166,9 @@
         DOM.addEventPreview(self)
         self.resize()
         self._register = RegisterCall()
-        self._register.call('isRegistered',self._isRegisteredCB)
+        self._register.call('isRegistered', self._isRegisteredCB)
         self.initialised = False
-        self.init_cache = [] # used to cache events until initialisation is done
+        self.init_cache = []  # used to cache events until initialisation is done
 
     def addSelectedListener(self, callback):
         self._selected_listeners.add(callback)
@@ -193,9 +193,9 @@
 
         if selected:
             selected.removeStyleName('selected_widget')
-    
+
         widgets_panel.selected = widget
-    
+
         if widget:
             widgets_panel.selected.addStyleName('selected_widget')
 
@@ -230,7 +230,7 @@
         def avatarError(error_data):
             # The jid is maybe not in our roster, we ask for the VCard
             self.bridge.call("getCard", None, jid_str)
-    
+
         if jid_str not in self.avatars_cache:
             self.bridge.call('getEntityData', (dataReceived, avatarError), jid_str, ['avatar'])
             self.avatars_cache[jid_str] = "/media/misc/empty_avatar"
@@ -276,14 +276,14 @@
 
     def _isConnectedCB(self, connected):
         if not connected:
-            self._register.call('connect',lambda x:self.logged())
+            self._register.call('connect', lambda x:self.logged())
         else:
             self.logged()
 
     def logged(self):
         if self._register_box:
             self._register_box.hide()
-            del self._register_box # don't work if self._register_box is None
+            del self._register_box  # don't work if self._register_box is None
 
         #it's time to fill the page
         self.bridge.call('getContacts', self._getContactsCB)
@@ -299,8 +299,8 @@
 
     def _getSignalsCB(self, signal_data):
         self.bridge_signals.call('getSignals', self._getSignalsCB)
-        print('Got signal ==> name: %s, params: %s' % (signal_data[0],signal_data[1]))
-        name,args = signal_data
+        print('Got signal ==> name: %s, params: %s' % (signal_data[0], signal_data[1]))
+        name, args = signal_data
         if name == 'personalEvent':
             self._personalEventCb(*args)
         elif name == 'newMessage':
@@ -361,12 +361,12 @@
                 if mblog.has_key('groups'):
                     _groups = set(mblog['groups'].split() if mblog['groups'] else [])
                 else:
-                    _groups=None
+                    _groups = None
                 mblog_entry = MicroblogItem(mblog)
                 self.mblog_cache.append((_groups, mblog_entry))
 
         if len(self.mblog_cache) > MAX_MBLOG_CACHE:
-            del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)]
+            del self.mblog_cache[0:len(self.mblog_cache - MAX_MBLOG_CACHE)]
         for lib_wid in self.libervia_widgets:
             if isinstance(lib_wid, panels.MicroblogPanel):
                 self.FillMicroblogPanel(lib_wid)
@@ -407,17 +407,17 @@
             if 'groups' in data:
                 _groups = set(data['groups'].split() if data['groups'] else [])
             else:
-                _groups=None
+                _groups = None
             mblog_entry = MicroblogItem(data)
-        
+
             for lib_wid in self.libervia_widgets:
                 if isinstance(lib_wid, panels.MicroblogPanel):
-                    self.addBlogEntry(lib_wid, sender, _groups, mblog_entry) 
+                    self.addBlogEntry(lib_wid, sender, _groups, mblog_entry)
 
             if sender == self.whoami.bare:
                 self.mblog_cache.append((_groups, mblog_entry))
                 if len(self.mblog_cache) > MAX_MBLOG_CACHE:
-                    del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)]
+                    del self.mblog_cache[0:len(self.mblog_cache - MAX_MBLOG_CACHE)]
 
     def addBlogEntry(self, mblog_panel, sender, _groups, mblog_entry):
         """Check if an entry can go in MicroblogPanel and add to it
@@ -435,7 +435,7 @@
         """
         #XXX: only our own entries are cached
         for cache_entry in self.mblog_cache:
-            _groups, mblog_entry = cache_entry 
+            _groups, mblog_entry = cache_entry
             self.addBlogEntry(mblog_panel, self.whoami.bare, *cache_entry)
 
     def getEntityMBlog(self, entity):
@@ -458,7 +458,7 @@
             #The message has not been showed, we must indicate it
             other = _to if _from.bare == self.whoami.bare else _from
             self.contact_panel.setContactMessageWaiting(other.bare, True)
-        
+
     def _presenceUpdateCb(self, entity, show, priority, statuses):
         _entity = JID(entity)
         #XXX: QnD way to get our status
@@ -483,34 +483,34 @@
 
     def _roomUserJoinedCb(self, room_jid_s, user_nick, user_data):
         for lib_wid in self.libervia_widgets:
-            if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
+            if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
                 lib_wid.userJoined(user_nick, user_data)
 
     def _roomUserLeftCb(self, room_jid_s, user_nick, user_data):
         for lib_wid in self.libervia_widgets:
-            if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
+            if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
                 lib_wid.userLeft(user_nick, user_data)
-    
+
     def _tarotGameStartedCb(self, room_jid_s, referee, players):
         print ("Tarot Game Started \o/")
         for lib_wid in self.libervia_widgets:
-            if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
+            if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
                 lib_wid.startGame("Tarot", referee, players)
 
     def _tarotGameGenericCb(self, event_name, room_jid_s, args):
         for lib_wid in self.libervia_widgets:
-            if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
-                getattr(lib_wid.getGame("Tarot"), event_name)(*args) 
+            if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
+                getattr(lib_wid.getGame("Tarot"), event_name)(*args)
 
     def _radioColStartedCb(self, room_jid_s, referee):
         for lib_wid in self.libervia_widgets:
-            if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
+            if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
                 lib_wid.startGame("RadioCol", referee)
 
     def _radioColGenericCb(self, event_name, room_jid_s, args):
         for lib_wid in self.libervia_widgets:
-            if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
-                getattr(lib_wid.getGame("RadioCol"), event_name)(*args) 
+            if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
+                getattr(lib_wid.getGame("RadioCol"), event_name)(*args)
 
 
     def _getPresenceStatusCb(self, presence_data):
@@ -540,12 +540,12 @@
             #The user want to subscribe to our presence
             _dialog = None
             msg = HTML('The contact <b>%s</b> want to add you in his/her contact list, do you accept ?' % html_sanitize(entity))
-            
+
             def ok_cb(ignore):
                 self.bridge.call('subscription', None, "subscribed", entity, '', _dialog.getSelectedGroups())
             def cancel_cb(ignore):
                 self.bridge.call('subscription', None, "unsubscribed", entity, '', '')
-    
+
             _dialog = dialog.GroupSelector([msg], self.contact_panel.getGroups(), [], ok_cb, cancel_cb)
             _dialog.setHTML('<b>Add contact request</b>')
             _dialog.show()