codging standards

This commit is contained in:
Yann Leboulanger 2011-08-21 19:32:52 +02:00
parent 3eb47cded2
commit b5b5e4be27
1 changed files with 49 additions and 43 deletions

View File

@ -150,8 +150,8 @@ class P2PClient(IdleObject):
else:
self.sock_type = TYPE_CLIENT
self.fd = -1
conn = P2PConnection('', _sock, host, port, self._caller, self.on_connect,
self)
conn = P2PConnection('', _sock, host, port, self._caller,
self.on_connect, self)
if not self.conn_holder:
# An error occured, disconnect() has been called
if on_not_ok:
@ -166,15 +166,16 @@ class P2PClient(IdleObject):
if is_message:
if self.fd == -1:
if on_not_ok:
on_not_ok('Connection to host could not be established.')
on_not_ok(
'Connection to host could not be established.')
return
thread_id = stanza.getThread()
id_ = stanza.getID()
if not id_:
id_ = self.Dispatcher.getAnID()
if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
self.conn_holder.ids_of_awaiting_messages[self.fd].append((id_,
thread_id))
self.conn_holder.ids_of_awaiting_messages[self.fd].append((
id_, thread_id))
else:
self.conn_holder.ids_of_awaiting_messages[self.fd] = [(id_,
thread_id)]
@ -235,7 +236,8 @@ class P2PClient(IdleObject):
self.Dispatcher._metastream.setNamespace(self.Namespace)
self.Dispatcher._metastream.setAttr('version', '1.0')
self.Dispatcher._metastream.setAttr('xmlns:stream', NS_STREAMS)
self.Dispatcher._metastream.setAttr('from', self.conn_holder.zeroconf.name)
self.Dispatcher._metastream.setAttr('from',
self.conn_holder.zeroconf.name)
if self.to:
self.Dispatcher._metastream.setAttr('to', self.to)
self.Dispatcher.send("<?xml version='1.0'?>%s>" % str(
@ -243,10 +245,12 @@ class P2PClient(IdleObject):
def _check_stream_start(self, ns, tag, attrs):
if ns != NS_STREAMS or tag != 'stream':
log.error('Incorrect stream start: (%s,%s).Terminating!' % (tag, ns), 'error')
log.error('Incorrect stream start: (%s,%s).Terminating!' % (tag,
ns), 'error')
self.Connection.disconnect()
if self.on_not_ok:
self.on_not_ok('Connection to host could not be established: Incorrect answer from server.')
self.on_not_ok('Connection to host could not be established: '
'Incorrect answer from server.')
return
if self.sock_type == TYPE_SERVER:
if attrs.has_key('from'):
@ -303,8 +307,8 @@ class P2PClient(IdleObject):
def _register_handlers(self):
self._caller.peerhost = self.Connection._sock.getsockname()
self.RegisterHandler('message', lambda conn, data:self._caller._messageCB(
self.Server, conn, data))
self.RegisterHandler('message', lambda conn,
data:self._caller._messageCB(self.Server, conn, data))
self.RegisterHandler('iq', self._caller._siSetCB, 'set',
common.xmpp.NS_SI)
self.RegisterHandler('iq', self._caller._siErrorCB, 'error',
@ -321,7 +325,8 @@ class P2PClient(IdleObject):
common.xmpp.NS_DISCO_ITEMS)
self.RegisterHandler('iq', self._caller._JingleCB, 'result')
self.RegisterHandler('iq', self._caller._JingleCB, 'error')
self.RegisterHandler('iq', self._caller._JingleCB, 'set', common.xmpp.NS_JINGLE)
self.RegisterHandler('iq', self._caller._JingleCB, 'set',
common.xmpp.NS_JINGLE)
class P2PConnection(IdleObject, PlugIn):
def __init__(self, sock_hash, _sock, host=None, port=None, caller=None,
@ -353,8 +358,8 @@ class P2PConnection(IdleObject, PlugIn):
self.ais = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
socket.SOCK_STREAM)
except socket.gaierror, e:
log.info('Lookup failure for %s: %s[%s]', host, e[1], repr(e[0]),
exc_info=True)
log.info('Lookup failure for %s: %s[%s]', host, e[1],
repr(e[0]), exc_info=True)
else:
self.connect_to_next_ip()
@ -392,8 +397,8 @@ class P2PConnection(IdleObject, PlugIn):
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._owner = None
@ -439,8 +444,8 @@ class P2PConnection(IdleObject, PlugIn):
if self.fd in ids and len(ids[self.fd]) > 0:
for (id_, thread_id) in ids[self.fd]:
if hasattr(self._owner, 'Dispatcher'):
self._owner.Dispatcher.Event('', DATA_ERROR, (self.client.to,
thread_id))
self._owner.Dispatcher.Event('', DATA_ERROR, (
self.client.to, thread_id))
else:
self._owner.on_not_ok('conenction timeout')
ids[self.fd] = []
@ -782,10 +787,11 @@ class ClientZeroconf:
"""
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
on_timeout callback if response is not retrieved in time
Send stanza and wait for recipient's response to it. Will call
transports on_timeout callback if response is not retrieved in time
Be aware: Only timeout of latest call of SendAndWait is active.
"""