Yet more doc-string refactoring
This commit is contained in:
parent
6bf2246de5
commit
99472b1702
|
@ -47,7 +47,9 @@ ACTIVITY_TIMEOUT_SECONDS = 30
|
||||||
|
|
||||||
class ZeroconfListener(IdleObject):
|
class ZeroconfListener(IdleObject):
|
||||||
def __init__(self, port, conn_holder):
|
def __init__(self, port, conn_holder):
|
||||||
''' handle all incomming connections on ('0.0.0.0', port)'''
|
"""
|
||||||
|
Handle all incomming connections on ('0.0.0.0', port)
|
||||||
|
"""
|
||||||
self.port = port
|
self.port = port
|
||||||
self.queue_idx = -1
|
self.queue_idx = -1
|
||||||
#~ self.queue = None
|
#~ self.queue = None
|
||||||
|
@ -80,11 +82,15 @@ class ZeroconfListener(IdleObject):
|
||||||
self.started = True
|
self.started = True
|
||||||
|
|
||||||
def pollend(self):
|
def pollend(self):
|
||||||
''' called when we stop listening on (host, port) '''
|
"""
|
||||||
|
Called when we stop listening on (host, port)
|
||||||
|
"""
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
||||||
def pollin(self):
|
def pollin(self):
|
||||||
''' accept a new incomming connection and notify queue'''
|
"""
|
||||||
|
Accept a new incomming connection and notify queue
|
||||||
|
"""
|
||||||
sock = self.accept_conn()
|
sock = self.accept_conn()
|
||||||
# loop through roster to find who has connected to us
|
# loop through roster to find who has connected to us
|
||||||
from_jid = None
|
from_jid = None
|
||||||
|
@ -97,7 +103,9 @@ class ZeroconfListener(IdleObject):
|
||||||
P2PClient(sock[0], ipaddr, sock[1][1], self.conn_holder, [], from_jid)
|
P2PClient(sock[0], ipaddr, sock[1][1], self.conn_holder, [], from_jid)
|
||||||
|
|
||||||
def disconnect(self, message=''):
|
def disconnect(self, message=''):
|
||||||
''' free all resources, we are not listening anymore '''
|
"""
|
||||||
|
Free all resources, we are not listening anymore
|
||||||
|
"""
|
||||||
log.info('Disconnecting ZeroconfListener: %s' % message)
|
log.info('Disconnecting ZeroconfListener: %s' % message)
|
||||||
gajim.idlequeue.remove_timeout(self.fd)
|
gajim.idlequeue.remove_timeout(self.fd)
|
||||||
gajim.idlequeue.unplug_idle(self.fd)
|
gajim.idlequeue.unplug_idle(self.fd)
|
||||||
|
@ -110,14 +118,16 @@ class ZeroconfListener(IdleObject):
|
||||||
self.conn_holder.kill_all_connections()
|
self.conn_holder.kill_all_connections()
|
||||||
|
|
||||||
def accept_conn(self):
|
def accept_conn(self):
|
||||||
''' accepts a new incoming connection '''
|
"""
|
||||||
|
Accept a new incoming connection
|
||||||
|
"""
|
||||||
_sock = self._serv.accept()
|
_sock = self._serv.accept()
|
||||||
_sock[0].setblocking(False)
|
_sock[0].setblocking(False)
|
||||||
return _sock
|
return _sock
|
||||||
|
|
||||||
class P2PClient(IdleObject):
|
class P2PClient(IdleObject):
|
||||||
def __init__(self, _sock, host, port, conn_holder, stanzaqueue=[], to=None,
|
def __init__(self, _sock, host, port, conn_holder, stanzaqueue=[], to=None,
|
||||||
on_ok=None, on_not_ok=None):
|
on_ok=None, on_not_ok=None):
|
||||||
self._owner = self
|
self._owner = self
|
||||||
self.Namespace = 'jabber:client'
|
self.Namespace = 'jabber:client'
|
||||||
self.protocol_type = 'XMPP'
|
self.protocol_type = 'XMPP'
|
||||||
|
@ -207,7 +217,9 @@ class P2PClient(IdleObject):
|
||||||
self._register_handlers()
|
self._register_handlers()
|
||||||
|
|
||||||
def StreamInit(self):
|
def StreamInit(self):
|
||||||
''' Send an initial stream header. '''
|
"""
|
||||||
|
Send an initial stream header
|
||||||
|
"""
|
||||||
self.Dispatcher.Stream = simplexml.NodeBuilder()
|
self.Dispatcher.Stream = simplexml.NodeBuilder()
|
||||||
self.Dispatcher.Stream._dispatch_depth = 2
|
self.Dispatcher.Stream._dispatch_depth = 2
|
||||||
self.Dispatcher.Stream.dispatch = self.Dispatcher.dispatch
|
self.Dispatcher.Stream.dispatch = self.Dispatcher.dispatch
|
||||||
|
@ -374,8 +386,10 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def plugout(self):
|
def plugout(self):
|
||||||
'''Disconnect from the remote server and unregister self.disconnected method from
|
"""
|
||||||
the owner's dispatcher.'''
|
Disconnect from the remote server and unregister self.disconnected method
|
||||||
|
from the owner's dispatcher
|
||||||
|
"""
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
self._owner = None
|
self._owner = None
|
||||||
|
|
||||||
|
@ -392,10 +406,12 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
self.on_receive = recv_handler
|
self.on_receive = recv_handler
|
||||||
|
|
||||||
def send(self, packet, is_message=False, now=False):
|
def send(self, packet, is_message=False, now=False):
|
||||||
'''Append stanza to the queue of messages to be send if now is
|
"""
|
||||||
False, else send it instantly.
|
Append stanza to the queue of messages to be send if now is False, else
|
||||||
If supplied data is unicode string, encode it to utf-8.
|
send it instantly
|
||||||
'''
|
|
||||||
|
If supplied data is unicode string, encode it to UTF-8.
|
||||||
|
"""
|
||||||
print 'ici'
|
print 'ici'
|
||||||
if self.state <= 0:
|
if self.state <= 0:
|
||||||
return
|
return
|
||||||
|
@ -459,7 +475,10 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
||||||
def pollin(self):
|
def pollin(self):
|
||||||
''' Reads all pending incoming data. Calls owner's disconnected() method if appropriate.'''
|
"""
|
||||||
|
Reads all pending incoming data. Call owner's disconnected() method if
|
||||||
|
appropriate
|
||||||
|
"""
|
||||||
received = ''
|
received = ''
|
||||||
errnum = 0
|
errnum = 0
|
||||||
try:
|
try:
|
||||||
|
@ -500,7 +519,9 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def disconnect(self, message=''):
|
def disconnect(self, message=''):
|
||||||
''' Closes the socket. '''
|
"""
|
||||||
|
Close the socket
|
||||||
|
"""
|
||||||
gajim.idlequeue.remove_timeout(self.fd)
|
gajim.idlequeue.remove_timeout(self.fd)
|
||||||
gajim.idlequeue.unplug_idle(self.fd)
|
gajim.idlequeue.unplug_idle(self.fd)
|
||||||
try:
|
try:
|
||||||
|
@ -739,20 +760,24 @@ class ClientZeroconf:
|
||||||
[(stanza, is_message)], to, on_ok=on_ok, on_not_ok=on_not_ok)
|
[(stanza, is_message)], to, on_ok=on_ok, on_not_ok=on_not_ok)
|
||||||
|
|
||||||
def RegisterDisconnectHandler(self, handler):
|
def RegisterDisconnectHandler(self, handler):
|
||||||
''' Register handler that will be called on disconnect.'''
|
"""
|
||||||
|
Register handler that will be called on disconnect
|
||||||
|
"""
|
||||||
self.disconnect_handlers.append(handler)
|
self.disconnect_handlers.append(handler)
|
||||||
|
|
||||||
def UnregisterDisconnectHandler(self, handler):
|
def UnregisterDisconnectHandler(self, handler):
|
||||||
''' Unregister handler that is called on disconnect.'''
|
"""
|
||||||
|
Unregister handler that is called on disconnect
|
||||||
|
"""
|
||||||
self.disconnect_handlers.remove(handler)
|
self.disconnect_handlers.remove(handler)
|
||||||
|
|
||||||
def SendAndWaitForResponse(self, stanza, timeout=None, func=None, args=None):
|
def SendAndWaitForResponse(self, stanza, timeout=None, func=None, args=None):
|
||||||
'''
|
"""
|
||||||
Send stanza and wait for recipient's response to it. Will call transports
|
Send stanza and wait for recipient's response to it. Will call transports
|
||||||
on_timeout callback if response is not retrieved in time.
|
on_timeout callback if response is not retrieved in time
|
||||||
|
|
||||||
Be aware: Only timeout of latest call of SendAndWait is active.
|
Be aware: Only timeout of latest call of SendAndWait is active.
|
||||||
'''
|
"""
|
||||||
# if timeout is None:
|
# if timeout is None:
|
||||||
# timeout = DEFAULT_TIMEOUT_SECONDS
|
# timeout = DEFAULT_TIMEOUT_SECONDS
|
||||||
def on_ok(_waitid):
|
def on_ok(_waitid):
|
||||||
|
@ -773,8 +798,10 @@ class ClientZeroconf:
|
||||||
self.send(stanza, on_ok=on_ok)
|
self.send(stanza, on_ok=on_ok)
|
||||||
|
|
||||||
def SendAndCallForResponse(self, stanza, func=None, args=None):
|
def SendAndCallForResponse(self, stanza, func=None, args=None):
|
||||||
''' Put stanza on the wire and call back when recipient replies.
|
"""
|
||||||
Additional callback arguments can be specified in args. '''
|
Put stanza on the wire and call back when recipient replies. Additional
|
||||||
|
callback arguments can be specified in args.
|
||||||
|
"""
|
||||||
self.SendAndWaitForResponse(stanza, 0, func, args)
|
self.SendAndWaitForResponse(stanza, 0, func, args)
|
||||||
|
|
||||||
# vim: se ts=3:
|
# vim: se ts=3:
|
||||||
|
|
|
@ -98,8 +98,9 @@ ConnectionCommands, ConnectionPEP, connection_handlers.ConnectionHandlersBase):
|
||||||
HAS_IDLE = False
|
HAS_IDLE = False
|
||||||
|
|
||||||
def _messageCB(self, ip, con, msg):
|
def _messageCB(self, ip, con, msg):
|
||||||
'''Called when we receive a message'''
|
"""
|
||||||
|
Called when we receive a message
|
||||||
|
"""
|
||||||
log.debug('Zeroconf MessageCB')
|
log.debug('Zeroconf MessageCB')
|
||||||
|
|
||||||
frm = msg.getFrom()
|
frm = msg.getFrom()
|
||||||
|
@ -178,17 +179,23 @@ ConnectionCommands, ConnectionPEP, connection_handlers.ConnectionHandlersBase):
|
||||||
# END messageCB
|
# END messageCB
|
||||||
|
|
||||||
def store_metacontacts(self, tags):
|
def store_metacontacts(self, tags):
|
||||||
''' fake empty method '''
|
"""
|
||||||
|
Fake empty method
|
||||||
|
"""
|
||||||
# serverside metacontacts are not supported with zeroconf
|
# serverside metacontacts are not supported with zeroconf
|
||||||
# (there is no server)
|
# (there is no server)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def remove_transfers_for_contact(self, contact):
|
def remove_transfers_for_contact(self, contact):
|
||||||
''' stop all active transfer for contact '''
|
"""
|
||||||
|
Stop all active transfer for contact
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def remove_all_transfers(self):
|
def remove_all_transfers(self):
|
||||||
''' stops and removes all active connections from the socks5 pool '''
|
"""
|
||||||
|
Stops and removes all active connections from the socks5 pool
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def remove_transfer(self, file_props, remove_from_list = True):
|
def remove_transfer(self, file_props, remove_from_list = True):
|
||||||
|
|
|
@ -51,7 +51,6 @@ from common.zeroconf import zeroconf
|
||||||
from connection_handlers_zeroconf import *
|
from connection_handlers_zeroconf import *
|
||||||
|
|
||||||
class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
||||||
'''Connection class'''
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
ConnectionHandlersZeroconf.__init__(self)
|
ConnectionHandlersZeroconf.__init__(self)
|
||||||
# system username
|
# system username
|
||||||
|
@ -66,9 +65,10 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
||||||
CommonConnection.__init__(self, name)
|
CommonConnection.__init__(self, name)
|
||||||
|
|
||||||
def get_config_values_or_default(self):
|
def get_config_values_or_default(self):
|
||||||
''' get name, host, port from config, or
|
"""
|
||||||
create zeroconf account with default values'''
|
Get name, host, port from config, or create zeroconf account with default
|
||||||
|
values
|
||||||
|
"""
|
||||||
if not gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'name'):
|
if not gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'name'):
|
||||||
gajim.log.debug('Creating zeroconf account')
|
gajim.log.debug('Creating zeroconf account')
|
||||||
gajim.config.add_per('accounts', gajim.ZEROCONF_ACC_NAME)
|
gajim.config.add_per('accounts', gajim.ZEROCONF_ACC_NAME)
|
||||||
|
@ -157,8 +157,10 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
||||||
self.dispatch('NOTIFY', (jid, 'offline', '', 'local', 0, None, 0, None))
|
self.dispatch('NOTIFY', (jid, 'offline', '', 'local', 0, None, 0, None))
|
||||||
|
|
||||||
def _disconnectedReconnCB(self):
|
def _disconnectedReconnCB(self):
|
||||||
'''Called when we are disconnected. Comes from network manager for example
|
"""
|
||||||
we don't try to reconnect, network manager will tell us when we can'''
|
Called when we are disconnected. Comes from network manager for example
|
||||||
|
we don't try to reconnect, network manager will tell us when we can
|
||||||
|
"""
|
||||||
if gajim.account_is_connected(self.name):
|
if gajim.account_is_connected(self.name):
|
||||||
# we cannot change our status to offline or connecting
|
# we cannot change our status to offline or connecting
|
||||||
# after we auth to server
|
# after we auth to server
|
||||||
|
|
|
@ -37,9 +37,10 @@ class Roster:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def getDiffs(self):
|
def getDiffs(self):
|
||||||
''' update the roster with new data and return dict with
|
"""
|
||||||
jid -> new status pairs to do notifications and stuff '''
|
Update the roster with new data and return dict with jid -> new status
|
||||||
|
pairs to do notifications and stuff
|
||||||
|
"""
|
||||||
diffs = {}
|
diffs = {}
|
||||||
old_data = self._data.copy()
|
old_data = self._data.copy()
|
||||||
self.update_roster()
|
self.update_roster()
|
||||||
|
|
Loading…
Reference in New Issue