changeset 574974f91869 in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=574974f91869
description: More doc-string (and not only) refactoring

diffstat:

 src/common/xmpp/auth_nb.py       |    82 +-
 src/common/xmpp/bosh.py          |    68 +-
 src/common/xmpp/c14n.py          |     5 +-
 src/common/xmpp/client_nb.py     |   150 +++-
 src/common/xmpp/dispatcher_nb.py |   185 +++--
 src/common/xmpp/features_nb.py   |    65 +-
 src/common/xmpp/idlequeue.py     |   171 +++--
 src/common/xmpp/plugin.py        |    31 +-
 src/common/xmpp/protocol.py      |  1309 
+++++++++++++++++++++++++++++-------------
 9 files changed, 1336 insertions(+), 730 deletions(-)

diffs (truncated from 3263 to 300 lines):

diff -r 9cb631b00e2e -r 574974f91869 src/common/xmpp/auth_nb.py
--- a/src/common/xmpp/auth_nb.py        Thu Nov 26 14:27:47 2009 +0200
+++ b/src/common/xmpp/auth_nb.py        Thu Nov 26 16:32:56 2009 +0200
@@ -13,12 +13,14 @@
 ##   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.
-'''
+
+"""
 Provides plugs for SASL and NON-SASL authentication mechanisms.
-Can be used both for client and transport authentication.
+Can be used both for client and transport authentication
 
 See client_nb.py
-'''
+"""
+
 from protocol import NS_SASL, NS_SESSION, NS_STREAMS, NS_BIND, NS_AUTH
 from protocol import Node, NodeProcessed, isResultNode, Iq, Protocol, JID
 from plugin import PlugIn
@@ -49,7 +51,8 @@
 SASL_IN_PROCESS = 'in-process'
 
 def challenge_splitter(data):
-       ''' Helper function that creates a dict from challenge string.
+       """
+       Helper function that creates a dict from challenge string
 
        Sample challenge string:
                username="example.org",realm="somerealm",\
@@ -59,7 +62,7 @@
        Expected result for challan:
                dict['qop'] = ('auth','auth-int','auth-conf')
                dict['realm'] = 'somerealm'
-       '''
+       """
        X_KEYWORD, X_VALUE, X_END = 0, 1, 2
        quotes_open = False
        keyword, value = '', ''
@@ -112,16 +115,17 @@
 
 
 class SASL(PlugIn):
-       '''
+       """
        Implements SASL authentication. Can be plugged into NonBlockingClient
-       to start authentication.
-       '''
+       to start authentication
+       """
+
        def __init__(self, username, password, on_sasl):
-               '''
+               """
                :param user: XMPP username
                :param password: XMPP password
                :param on_sasl: Callback, will be called after each SASL 
auth-step.
-               '''
+               """
                PlugIn.__init__(self)
                self.username = username
                self.password = password
@@ -141,7 +145,9 @@
                        self.startsasl = None
 
        def plugout(self):
-               ''' Remove SASL handlers from owner's dispatcher. Used 
internally. '''
+               """
+               Remove SASL handlers from owner's dispatcher. Used internally
+               """
                if 'features' in  self._owner.__dict__:
                        self._owner.UnregisterHandler('features', 
self.FeaturesHandler,
                                xmlns=NS_STREAMS)
@@ -156,13 +162,13 @@
                                xmlns=NS_SASL)
 
        def auth(self):
-               '''
+               """
                Start authentication. Result can be obtained via 
"SASL.startsasl"
-               attribute and will be either SASL_SUCCESS or SASL_FAILURE.
+               attribute and will be either SASL_SUCCESS or SASL_FAILURE
 
                Note that successfull auth will take at least two 
Dispatcher.Process()
                calls.
-               '''
+               """
                if self.startsasl:
                        pass
                elif self._owner.Dispatcher.Stream.features:
@@ -176,7 +182,9 @@
                                self.FeaturesHandler, xmlns=NS_STREAMS)
 
        def FeaturesHandler(self, conn, feats):
-               ''' Used to determine if server supports SASL auth. Used 
internally. '''
+               """
+               Used to determine if server supports SASL auth. Used internally
+               """
                if not feats.getTag('mechanisms', namespace=NS_SASL):
                        self.startsasl='not-supported'
                        log.error('SASL not supported by server')
@@ -235,7 +243,9 @@
                return
 
        def SASLHandler(self, conn, challenge):
-               ''' Perform next SASL auth step. Used internally. '''
+               """
+               Perform next SASL auth step. Used internally
+               """
                if challenge.getNamespace() != NS_SASL:
                        return
                ### Handle Auth result
@@ -359,12 +369,15 @@
 
 
 class NonBlockingNonSASL(PlugIn):
-       '''
+       """
        Implements old Non-SASL (JEP-0078) authentication used in jabberd1.4 and
-       transport authentication.
-       '''
+       transport authentication
+       """
+
        def __init__(self, user, password, resource, on_auth):
-               ''' Caches username, password and resource for auth. '''
+               """
+               Caches username, password and resource for auth
+               """
                PlugIn.__init__(self)
                self.user = user
                if password is None:
@@ -375,10 +388,10 @@
                self.on_auth = on_auth
 
        def plugin(self, owner):
-               '''
+               """
                Determine the best auth method (digest/0k/plain) and use it for 
auth.
-               Returns used method name on success. Used internally.
-               '''
+               Returns used method name on success. Used internally
+               """
                log.info('Querying server about possible auth methods')
                self.owner = owner
 
@@ -438,10 +451,11 @@
 
 
 class NonBlockingBind(PlugIn):
-       '''
+       """
        Bind some JID to the current connection to allow router know of our
-       location. Must be plugged after successful SASL auth.
-       '''
+       location. Must be plugged after successful SASL auth
+       """
+
        def __init__(self):
                PlugIn.__init__(self)
                self.bound = None
@@ -459,10 +473,10 @@
                                xmlns=NS_STREAMS)
 
        def FeaturesHandler(self, conn, feats):
-               '''
+               """
                Determine if server supports resource binding and set some 
internal
-               attributes accordingly.
-               '''
+               attributes accordingly
+               """
                if not feats.getTag('bind', namespace=NS_BIND):
                        log.error('Server does not requested binding.')
                        # we try to bind resource anyway
@@ -476,14 +490,16 @@
                self.bound = []
 
        def plugout(self):
-               ''' Remove Bind handler from owner's dispatcher. Used 
internally. '''
+               """
+               Remove Bind handler from owner's dispatcher. Used internally
+               """
                self._owner.UnregisterHandler('features', self.FeaturesHandler,
                        xmlns=NS_STREAMS)
 
        def NonBlockingBind(self, resource=None, on_bound=None):
-               ''' Perform binding.
-               Use provided resource name or random (if not provided).
-               '''
+               """
+               Perform binding. Use provided resource name or random (if not 
provided).
+               """
                self.on_bound = on_bound
                self._resource = resource
                if self._resource:
diff -r 9cb631b00e2e -r 574974f91869 src/common/xmpp/bosh.py
--- a/src/common/xmpp/bosh.py   Thu Nov 26 14:27:47 2009 +0200
+++ b/src/common/xmpp/bosh.py   Thu Nov 26 16:32:56 2009 +0200
@@ -125,11 +125,12 @@
                        log.warn('set_timeout: TIMEOUT NOT SET: state is %s, fd 
is %s' % (self.get_state(), self.fd))
 
        def on_http_request_possible(self):
-               '''
+               """
                Called when HTTP request it's possible to send a HTTP request. 
It can be when
-               socket is connected or when HTTP response arrived.
+               socket is connected or when HTTP response arrived
+
                There should be always one pending request to BOSH CM.
-               '''
+               """
                log.debug('on_http_req possible, state:\n%s' % 
self.get_current_state())
                if self.get_state()==DISCONNECTED: return
 
@@ -149,14 +150,18 @@
 
 
        def get_socket_in(self, state):
-               ''' gets sockets in desired state '''
+               """
+               Get sockets in desired state
+               """
                for s in self.http_socks:
                        if s.get_state()==state: return s
                return None
 
 
        def get_free_socket(self):
-               ''' Selects and returns socket eligible for sending a data 
to.'''
+               """
+               Select and returns socket eligible for sending a data to
+               """
                if self.http_pipelining:
                        return self.get_socket_in(CONNECTED)
                else:
@@ -176,10 +181,10 @@
 
 
        def send_BOSH(self, payload):
-               '''
+               """
                Tries to send a stanza in payload by appeding it to a buffer 
and plugging a
                free socket for writing.
-               '''
+               """
                total_pending_reqs = sum([s.pending_requests for s in 
self.http_socks])
 
                # when called after HTTP response (Payload=None) and when there 
are already
@@ -236,15 +241,16 @@
                        log.error('=====!!!!!!!!====> Couldn\'t get free socket 
in plug_socket())')
 
        def build_stanza(self, socket):
-               '''
-               Builds a BOSH body tag from data in buffers and adds key, rid 
and ack
-               attributes to it.
+               """
+               Build a BOSH body tag from data in buffers and adds key, rid 
and ack
+               attributes to it
+
                This method is called from _do_send() of underlying transport. 
This is to
-               ensure rid and keys will be processed in correct order. If I 
generate them
-               before  plugging a socket for write (and did it for two 
sockets/HTTP
-               connections) in parallel, they might be sent in wrong order, 
which results
-               in violating the BOSH session and server-side disconnect.
-               '''
+               ensure rid and keys will be processed in correct order. If I 
generate
+               them before     plugging a socket for write (and did it for two 
sockets/HTTP
+               connections) in parallel, they might be sent in wrong order, 
which
+               results in violating the BOSH session and server-side 
disconnect.
+               """
                if self.prio_bosh_stanzas:
                        stanza, add_payload = self.prio_bosh_stanzas.pop(0)
                        if add_payload:
@@ -285,10 +291,11 @@
                                self.wait_cb_time)
 
        def on_persistent_fallback(self, socket):
-               '''
-               Called from underlying transport when server closes TCP 
connection.
+               """
+               Called from underlying transport when server closes TCP 
connection
+
                :param socket: disconnected transport object
-               '''
+               """
                if socket.http_persistent:
                        log.warn('Fallback to nonpersistent HTTP (no pipelining 
as well)')
                        socket.http_persistent = False
@@ -302,9 +309,10 @@
 
 
        def handle_body_attrs(self, stanza_attrs):
-               '''
-               Called for each incoming body stanza from dispatcher. Checks 
body attributes.
-               '''
+               """
+               Called for each incoming body stanza from dispatcher. Checks 
body
+               attributes.
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to