changeset 67acb768d786 in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=67acb768d786
description: One more portion of doc-string and formatting refactoring

diffstat:

 src/common/xmpp/protocol.py         |    2 +-
 src/common/xmpp/proxy_connectors.py |   54 ++-
 src/common/xmpp/roster_nb.py        |  310 ++++++++++++++-------
 src/common/xmpp/simplexml.py        |  567 
+++++++++++++++++++++++++++------------
 4 files changed, 627 insertions(+), 306 deletions(-)

diffs (truncated from 1258 to 300 lines):

diff -r 574974f91869 -r 67acb768d786 src/common/xmpp/protocol.py
--- a/src/common/xmpp/protocol.py       Thu Nov 26 16:32:56 2009 +0200
+++ b/src/common/xmpp/protocol.py       Thu Nov 26 17:46:48 2009 +0200
@@ -476,7 +476,7 @@
                        self.setTo(self['to'])
                if self['from']:
                        self.setFrom(self['from'])
-               if node and type(self )== type(node) and self.__class__ == 
node.__class__ and self.attrs.has_key('id'):
+               if node and type(self) == type(node) and self.__class__ == 
node.__class__ and self.attrs.has_key('id'):
                        del self.attrs['id']
                self.timestamp = None
                for d in self.getTags('delay', namespace=NS_DELAY2):
diff -r 574974f91869 -r 67acb768d786 src/common/xmpp/proxy_connectors.py
--- a/src/common/xmpp/proxy_connectors.py       Thu Nov 26 16:32:56 2009 +0200
+++ b/src/common/xmpp/proxy_connectors.py       Thu Nov 26 17:46:48 2009 +0200
@@ -14,27 +14,30 @@
 ##   but WITHOUT ANY WARRANTY; without even the implied warranty of
 ##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ##   GNU General Public License for more details.
-'''
-Module containing classes for proxy connecting. So far its HTTP CONNECT
-and SOCKS5 proxy.
+
+"""
+Module containing classes for proxy connecting. So far its HTTP CONNECT and
+SOCKS5 proxy
+
 Authentication to NTLM (Microsoft implementation) proxies can be next.
-'''
+"""
 
 import struct, socket, base64
 import logging
 log = logging.getLogger('gajim.c.x.proxy_connectors')
 
 class ProxyConnector:
-       '''
+       """
        Interface for proxy-connecting object - when tunnneling XMPP over 
proxies,
-       some connecting process usually has to be done before opening stream.
-       Proxy connectors are used right after TCP connection is estabilished.
-       '''
+       some connecting process usually has to be done before opening stream. 
Proxy
+       connectors are used right after TCP connection is estabilished
+       """
+
        def __init__(self, send_method, onreceive, old_on_receive, on_success,
-               on_failure, xmpp_server, proxy_creds=(None,None)):
-               '''
+                       on_failure, xmpp_server, proxy_creds=(None,None)):
+               """
                Creates proxy connector, starts connecting immediately and 
gives control
-               back to transport afterwards.
+               back to transport afterwards
 
                :param send_method: transport send method
                :param onreceive: method to set on_receive callbacks
@@ -44,7 +47,7 @@
                :param on_failure: called when errors occured while connecting
                :param xmpp_server: tuple of (hostname, port)
                :param proxy_creds: tuple of (proxy_user, proxy_credentials)
-               '''
+               """
                self.send = send_method
                self.onreceive = onreceive
                self.old_on_receive = old_on_receive
@@ -58,12 +61,12 @@
 
        @classmethod
        def get_instance(cls, *args, **kwargs):
-               '''
-               Factory Method for object creation.
+               """
+               Factory Method for object creation
 
-               Use this instead of directly initializing the class in order to 
make
-               unit testing much easier.
-               '''
+               Use this instead of directly initializing the class in order to 
make unit
+               testing much easier.
+               """
                return cls(*args, **kwargs)
 
        def start_connecting(self):
@@ -75,11 +78,11 @@
 
 class HTTPCONNECTConnector(ProxyConnector):
        def start_connecting(self):
-               '''
-               Connects to proxy, supplies login and password to it
-               (if were specified while creating instance). Instructs proxy to 
make
-               connection to the target server.
-               '''
+               """
+               Connect to a proxy, supply login and password to it (if were 
specified
+               while creating instance). Instruct proxy to make connection to 
the target
+               server.
+               """
                log.info('Proxy server contacted, performing authentification')
                connector = ['CONNECT %s:%s HTTP/1.1' % self.xmpp_server,
                        'Proxy-Connection: Keep-Alive',
@@ -115,10 +118,11 @@
 
 
 class SOCKS5Connector(ProxyConnector):
-       '''
+       """
        SOCKS5 proxy connection class. Allows to use SOCKS5 proxies with
-       (optionally) simple authentication (only USERNAME/PASSWORD auth).
-       '''
+       (optionally) simple authentication (only USERNAME/PASSWORD auth)
+       """
+
        def start_connecting(self):
                log.info('Proxy server contacted, performing authentification')
                if self.proxy_user and self.proxy_pass:
diff -r 574974f91869 -r 67acb768d786 src/common/xmpp/roster_nb.py
--- a/src/common/xmpp/roster_nb.py      Thu Nov 26 16:32:56 2009 +0200
+++ b/src/common/xmpp/roster_nb.py      Thu Nov 26 17:46:48 2009 +0200
@@ -16,10 +16,11 @@
 
 # $Id: roster.py,v 1.17 2005/05/02 08:38:49 snakeru Exp $
 
-'''
+
+"""
 Simple roster implementation. Can be used though for different tasks like
 mass-renaming of contacts.
-'''
+"""
 
 from protocol import JID, Iq, Presence, Node, NodeProcessed, NS_MUC_USER, 
NS_ROSTER
 from plugin import PlugIn
@@ -29,15 +30,18 @@
 
 
 class NonBlockingRoster(PlugIn):
-       ''' Defines a plenty of methods that will allow you to manage roster.
-               Also automatically track presences from remote JIDs taking into
-               account that every JID can have multiple resources connected. 
Does not
-               currently support 'error' presences.
-               You can also use mapping interface for access to the internal 
representation of
-               contacts in roster.
-               '''
+       """
+       Defines a plenty of methods that will allow you to manage roster. Also
+       automatically track presences from remote JIDs taking into account that
+       every JID can have multiple resources connected. Does not currently 
support
+       'error' presences. You can also use mapping interface for access to the
+       internal representation of contacts in roster
+       """
+
        def __init__(self, version=''):
-               ''' Init internal variables. '''
+               """
+               Init internal variables
+               """
                PlugIn.__init__(self)
                self.version = version
                self._data = {}
@@ -45,11 +49,15 @@
                self._exported_methods=[self.getRoster]
                self.received_from_server = False
 
-       def Request(self,force=0):
-               ''' Request roster from server if it were not yet requested
-                       (or if the 'force' argument is set). '''
-               if self.set is None: self.set=0
-               elif not force: return
+       def Request(self, force=0):
+               """
+               Request roster from server if it were not yet requested (or if 
the
+               'force' argument is set)
+               """
+               if self.set is None:
+                       self.set = 0
+               elif not force:
+                       return
 
                iq = Iq('get',NS_ROSTER)
                iq.setTagAttr('query', 'ver', self.version)
@@ -59,9 +67,11 @@
                log.info('Roster requested from server')
                return id_
 
-       def RosterIqHandler(self,dis,stanza):
-               ''' Subscription tracker. Used internally for setting items 
state in
-                       internal roster representation. '''
+       def RosterIqHandler(self, dis, stanza):
+               """
+               Subscription tracker. Used internally for setting items state 
in internal
+               roster representation
+               """
                sender = stanza.getAttr('from')
                if not sender is None and not sender.bareMatch(
                self._owner.User + '@' + self._owner.Server):
@@ -91,9 +101,11 @@
                # Looks like we have a workaround
                # raise NodeProcessed # a MUST. Otherwise you'll get back an 
<iq type='error'/>
 
-       def PresenceHandler(self,dis,pres):
-               ''' Presence tracker. Used internally for setting items' 
resources state in
-                       internal roster representation. '''
+       def PresenceHandler(self, dis, pres):
+               """
+               Presence tracker. Used internally for setting items' resources 
state in
+               internal roster representation
+               """
                if pres.getTag('x', namespace=NS_MUC_USER):
                        return
                jid=pres.getFrom()
@@ -118,112 +130,204 @@
                elif typ=='unavailable' and 
item['resources'].has_key(jid.getResource()): del 
item['resources'][jid.getResource()]
                # Need to handle type='error' also
 
-       def _getItemData(self,jid,dataname):
-               ''' Return specific jid's representation in internal format. 
Used internally. '''
-               jid=jid[:(jid+'/').find('/')]
+       def _getItemData(self, jid, dataname):
+               """
+               Return specific jid's representation in internal format. Used 
internally
+               """
+               jid = jid[:(jid+'/').find('/')]
                return self._data[jid][dataname]
-       def _getResourceData(self,jid,dataname):
-               ''' Return specific jid's resource representation in internal 
format. Used internally. '''
-               if jid.find('/')+1:
-                       jid,resource=jid.split('/',1)
-                       if self._data[jid]['resources'].has_key(resource): 
return self._data[jid]['resources'][resource][dataname]
+
+       def _getResourceData(self, jid, dataname):
+               """
+               Return specific jid's resource representation in internal 
format. Used
+               internally
+               """
+               if jid.find('/') + 1:
+                       jid, resource = jid.split('/', 1)
+                       if self._data[jid]['resources'].has_key(resource):
+                               return 
self._data[jid]['resources'][resource][dataname]
                elif self._data[jid]['resources'].keys():
-                       lastpri=-129
+                       lastpri = -129
                        for r in self._data[jid]['resources'].keys():
-                               if 
int(self._data[jid]['resources'][r]['priority'])>lastpri: 
resource,lastpri=r,int(self._data[jid]['resources'][r]['priority'])
+                               if 
int(self._data[jid]['resources'][r]['priority']) > lastpri:
+                                       
resource,lastpri=r,int(self._data[jid]['resources'][r]['priority'])
                        return self._data[jid]['resources'][resource][dataname]
-       def delItem(self,jid):
-               ''' Delete contact 'jid' from roster.'''
-               
self._owner.send(Iq('set',NS_ROSTER,payload=[Node('item',{'jid':jid,'subscription':'remove'})]))
-       def getAsk(self,jid):
-               ''' Returns 'ask' value of contact 'jid'.'''
-               return self._getItemData(jid,'ask')
-       def getGroups(self,jid):
-               ''' Returns groups list that contact 'jid' belongs to.'''
-               return self._getItemData(jid,'groups')
-       def getName(self,jid):
-               ''' Returns name of contact 'jid'.'''
-               return self._getItemData(jid,'name')
-       def getPriority(self,jid):
-               ''' Returns priority of contact 'jid'. 'jid' should be a full 
(not bare) JID.'''
-               return self._getResourceData(jid,'priority')
+
+       def delItem(self, jid):
+               """
+               Delete contact 'jid' from roster
+               """
+               self._owner.send(Iq('set', NS_ROSTER, payload=[Node('item', 
{'jid': jid, 'subscription': 'remove'})]))
+
+       def getAsk(self, jid):
+               """
+               Return 'ask' value of contact 'jid'
+               """
+               return self._getItemData(jid, 'ask')
+
+       def getGroups(self, jid):
+               """
+               Return groups list that contact 'jid' belongs to
+               """
+               return self._getItemData(jid, 'groups')
+
+       def getName(self, jid):
+               """
+               Return name of contact 'jid'
+               """
+               return self._getItemData(jid, 'name')
+
+       def getPriority(self, jid):
+               """
+               Return priority of contact 'jid'. 'jid' should be a full (not 
bare) JID
+               """
+               return self._getResourceData(jid, 'priority')
+
        def getRawRoster(self):
-               ''' Returns roster representation in internal format. '''
+               """
+               Return roster representation in internal format
+               """
                return self._data
-       def getRawItem(self,jid):
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to