coding standards
This commit is contained in:
parent
92690da36b
commit
45211c43f5
|
@ -112,7 +112,8 @@ class ZeroconfListener(IdleObject):
|
|||
return _sock
|
||||
|
||||
class P2PClient(IdleObject):
|
||||
def __init__(self, _sock, host, port, conn_holder, stanzaqueue = [], to = None, on_ok=None, on_not_ok=None):
|
||||
def __init__(self, _sock, host, port, conn_holder, stanzaqueue=[], to=None,
|
||||
on_ok=None, on_not_ok=None):
|
||||
self._owner = self
|
||||
self.Namespace = 'jabber:client'
|
||||
self.defaultNamespace = self.Namespace
|
||||
|
@ -141,7 +142,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:
|
||||
|
@ -210,11 +212,13 @@ class P2PClient(IdleObject):
|
|||
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(self.Dispatcher._metastream)[:-2])
|
||||
self.Dispatcher.send("<?xml version='1.0'?>%s>" % str(
|
||||
self.Dispatcher._metastream)[:-2])
|
||||
|
||||
def _check_stream_start(self, ns, tag, attrs):
|
||||
if ns<>NS_STREAMS or tag<>'stream':
|
||||
self.Connection.DEBUG('Incorrect stream start: (%s,%s).Terminating! ' % (tag, ns), 'error')
|
||||
self.Connection.DEBUG('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.')
|
||||
|
@ -235,7 +239,6 @@ class P2PClient(IdleObject):
|
|||
stanza, is_message = self.stanzaqueue.pop(0)
|
||||
self.send(stanza, is_message)
|
||||
|
||||
|
||||
def on_disconnect(self):
|
||||
if self.conn_holder:
|
||||
if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
|
||||
|
@ -271,7 +274,8 @@ class P2PClient(IdleObject):
|
|||
return True
|
||||
|
||||
def _register_handlers(self):
|
||||
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',
|
||||
|
@ -286,7 +290,8 @@ class P2PClient(IdleObject):
|
|||
common.xmpp.NS_BYTESTREAM)
|
||||
|
||||
class P2PConnection(IdleObject, PlugIn):
|
||||
def __init__(self, sock_hash, _sock, host = None, port = None, caller = None, on_connect = None, client = None):
|
||||
def __init__(self, sock_hash, _sock, host=None, port=None, caller=None,
|
||||
on_connect=None, client=None):
|
||||
IdleObject.__init__(self)
|
||||
self._owner = client
|
||||
PlugIn.__init__(self)
|
||||
|
@ -312,9 +317,11 @@ class P2PConnection(IdleObject, PlugIn):
|
|||
else:
|
||||
self.state = 0
|
||||
try:
|
||||
self.ais = socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM)
|
||||
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()
|
||||
|
||||
|
@ -393,7 +400,7 @@ class P2PConnection(IdleObject, PlugIn):
|
|||
def read_timeout(self):
|
||||
if self.client.conn_holder.number_of_awaiting_messages.has_key(self.fd) \
|
||||
and self.client.conn_holder.number_of_awaiting_messages[self.fd] > 0:
|
||||
self.client._caller.dispatch('MSGERROR',[unicode(self.client.to), -1, \
|
||||
self.client._caller.dispatch('MSGERROR',[unicode(self.client.to), -1,
|
||||
_('Connection to host could not be established: Timeout while sending data.'), None, None])
|
||||
self.client.conn_holder.number_of_awaiting_messages[self.fd] = 0
|
||||
self.pollend()
|
||||
|
@ -419,7 +426,6 @@ class P2PConnection(IdleObject, PlugIn):
|
|||
# we are connected
|
||||
self.on_connect(self)
|
||||
|
||||
|
||||
def pollout(self):
|
||||
if self.state == 0:
|
||||
self.do_connect()
|
||||
|
@ -556,7 +562,6 @@ class P2PConnection(IdleObject, PlugIn):
|
|||
self._owner.disconnected()
|
||||
self.sent_data = None
|
||||
|
||||
|
||||
class ClientZeroconf:
|
||||
def __init__(self, caller):
|
||||
self.caller = caller
|
||||
|
@ -606,11 +611,11 @@ class ClientZeroconf:
|
|||
self.zeroconf.username = self.caller.username
|
||||
return self.announce()
|
||||
|
||||
|
||||
def zeroconf_init(self, show, msg):
|
||||
self.zeroconf = zeroconf.Zeroconf(self.caller._on_new_service,
|
||||
self.caller._on_remove_service, self.caller._on_name_conflictCB,
|
||||
self.caller._on_disconnected, self.caller._on_error, self.caller.username, self.caller.host, self.port)
|
||||
self.caller._on_disconnected, self.caller._on_error,
|
||||
self.caller.username, self.caller.host, self.port)
|
||||
self.zeroconf.txt['msg'] = msg
|
||||
self.zeroconf.txt['status'] = show
|
||||
self.zeroconf.txt['1st'] = self.caller.first
|
||||
|
@ -704,4 +709,5 @@ class ClientZeroconf:
|
|||
return 0
|
||||
|
||||
# otherwise open new connection
|
||||
P2PClient(None, item['address'], item['port'], self, [(stanza, is_message)], to, on_ok=on_ok, on_not_ok=on_not_ok)
|
||||
P2PClient(None, item['address'], item['port'], self,
|
||||
[(stanza, is_message)], to, on_ok=on_ok, on_not_ok=on_not_ok)
|
||||
|
|
Loading…
Reference in New Issue