mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
Cleanup, restore PEP8.
This commit is contained in:
parent
93fbcad277
commit
505a63da3a
5 changed files with 48 additions and 42 deletions
|
@ -460,7 +460,7 @@ class BaseXMPP(XMLStream):
|
||||||
def fulljid(self, value):
|
def fulljid(self, value):
|
||||||
logging.warning("fulljid property deprecated. Use boundjid.full")
|
logging.warning("fulljid property deprecated. Use boundjid.full")
|
||||||
self.boundjid.full = value
|
self.boundjid.full = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def resource(self):
|
def resource(self):
|
||||||
"""
|
"""
|
||||||
|
@ -473,7 +473,7 @@ class BaseXMPP(XMLStream):
|
||||||
def resource(self, value):
|
def resource(self, value):
|
||||||
logging.warning("fulljid property deprecated. Use boundjid.full")
|
logging.warning("fulljid property deprecated. Use boundjid.full")
|
||||||
self.boundjid.resource = value
|
self.boundjid.resource = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def username(self):
|
def username(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -117,7 +117,7 @@ class ClientXMPP(BaseXMPP):
|
||||||
self.register_feature(
|
self.register_feature(
|
||||||
"<session xmlns='urn:ietf:params:xml:ns:xmpp-session' />",
|
"<session xmlns='urn:ietf:params:xml:ns:xmpp-session' />",
|
||||||
self._handle_start_session)
|
self._handle_start_session)
|
||||||
|
|
||||||
def handle_connected(self, event=None):
|
def handle_connected(self, event=None):
|
||||||
#TODO: Use stream state here
|
#TODO: Use stream state here
|
||||||
self.authenticated = False
|
self.authenticated = False
|
||||||
|
@ -125,7 +125,6 @@ class ClientXMPP(BaseXMPP):
|
||||||
self.bound = False
|
self.bound = False
|
||||||
self.bindfail = False
|
self.bindfail = False
|
||||||
|
|
||||||
|
|
||||||
def connect(self, address=tuple()):
|
def connect(self, address=tuple()):
|
||||||
"""
|
"""
|
||||||
Connect to the XMPP server.
|
Connect to the XMPP server.
|
||||||
|
@ -319,7 +318,9 @@ class ClientXMPP(BaseXMPP):
|
||||||
sasl_ns,
|
sasl_ns,
|
||||||
auth))
|
auth))
|
||||||
elif 'sasl:ANONYMOUS' in self.features and not self.boundjid.user:
|
elif 'sasl:ANONYMOUS' in self.features and not self.boundjid.user:
|
||||||
self.send("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='ANONYMOUS' />")
|
self.send("<auth xmlns='%s' mechanism='%s' />" % (
|
||||||
|
sasl_ns,
|
||||||
|
'ANONYMOUS'))
|
||||||
else:
|
else:
|
||||||
logging.error("No appropriate login method.")
|
logging.error("No appropriate login method.")
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
|
@ -108,7 +108,6 @@ class Presence(RootStanza):
|
||||||
self._delAttr('type')
|
self._delAttr('type')
|
||||||
self._delSub('show')
|
self._delSub('show')
|
||||||
|
|
||||||
|
|
||||||
def setPriority(self, value):
|
def setPriority(self, value):
|
||||||
"""
|
"""
|
||||||
Set the entity's priority value. Some server use priority to
|
Set the entity's priority value. Some server use priority to
|
||||||
|
|
|
@ -167,10 +167,12 @@ class Scheduler(object):
|
||||||
key=lambda task: task.next)
|
key=lambda task: task.next)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self.run = False
|
self.run = False
|
||||||
if self.parentstop is not None: self.parentstop.set()
|
if self.parentstop is not None:
|
||||||
|
self.parentstop.set()
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
self.run = False
|
self.run = False
|
||||||
if self.parentstop is not None: self.parentstop.set()
|
if self.parentstop is not None:
|
||||||
|
self.parentstop.set()
|
||||||
logging.debug("Qutting Scheduler thread")
|
logging.debug("Qutting Scheduler thread")
|
||||||
if self.parentqueue is not None:
|
if self.parentqueue is not None:
|
||||||
self.parentqueue.put(('quit', None, None))
|
self.parentqueue.put(('quit', None, None))
|
||||||
|
|
|
@ -239,37 +239,39 @@ class XMLStream(object):
|
||||||
|
|
||||||
# Repeatedly attempt to connect until a successful connection
|
# Repeatedly attempt to connect until a successful connection
|
||||||
# is established.
|
# is established.
|
||||||
connected = self.state.transition('disconnected', 'connected', func=self._connect)
|
connected = self.state.transition('disconnected', 'connected',
|
||||||
|
func=self._connect)
|
||||||
while reattempt and not connected:
|
while reattempt and not connected:
|
||||||
connected = self.state.transition('disconnected', 'connected', func=self._connect)
|
connected = self.state.transition('disconnected', 'connected',
|
||||||
|
func=self._connect)
|
||||||
return connected
|
return connected
|
||||||
|
|
||||||
|
|
||||||
def _connect(self):
|
def _connect(self):
|
||||||
self.stop.clear()
|
self.stop.clear()
|
||||||
self.socket = self.socket_class(Socket.AF_INET, Socket.SOCK_STREAM)
|
self.socket = self.socket_class(Socket.AF_INET, Socket.SOCK_STREAM)
|
||||||
self.socket.settimeout(None)
|
self.socket.settimeout(None)
|
||||||
if self.use_ssl and self.ssl_support:
|
if self.use_ssl and self.ssl_support:
|
||||||
logging.debug("Socket Wrapped for SSL")
|
logging.debug("Socket Wrapped for SSL")
|
||||||
ssl_socket = ssl.wrap_socket(self.socket)
|
ssl_socket = ssl.wrap_socket(self.socket)
|
||||||
if hasattr(self.socket, 'socket'):
|
if hasattr(self.socket, 'socket'):
|
||||||
# We are using a testing socket, so preserve the top
|
# We are using a testing socket, so preserve the top
|
||||||
# layer of wrapping.
|
# layer of wrapping.
|
||||||
self.socket.socket = ssl_socket
|
self.socket.socket = ssl_socket
|
||||||
else:
|
else:
|
||||||
self.socket = ssl_socket
|
self.socket = ssl_socket
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.socket.connect(self.address)
|
self.socket.connect(self.address)
|
||||||
self.set_socket(self.socket, ignore=True)
|
self.set_socket(self.socket, ignore=True)
|
||||||
#this event is where you should set your application state
|
#this event is where you should set your application state
|
||||||
self.event("connected", direct=True)
|
self.event("connected", direct=True)
|
||||||
return True
|
return True
|
||||||
except Socket.error as serr:
|
except Socket.error as serr:
|
||||||
error_msg = "Could not connect to %s:%s. Socket Error #%s: %s"
|
error_msg = "Could not connect to %s:%s. Socket Error #%s: %s"
|
||||||
logging.error(error_msg % (self.address[0], self.address[1], serr.errno, serr.strerror))
|
logging.error(error_msg % (self.address[0], self.address[1],
|
||||||
time.sleep(1)
|
serr.errno, serr.strerror))
|
||||||
return False
|
time.sleep(1)
|
||||||
|
return False
|
||||||
|
|
||||||
def disconnect(self, reconnect=False):
|
def disconnect(self, reconnect=False):
|
||||||
"""
|
"""
|
||||||
|
@ -283,8 +285,9 @@ class XMLStream(object):
|
||||||
and processing should be restarted.
|
and processing should be restarted.
|
||||||
Defaults to False.
|
Defaults to False.
|
||||||
"""
|
"""
|
||||||
self.state.transition('connected', 'disconnected', wait=0.0, func=self._disconnect, args=(reconnect,))
|
self.state.transition('connected', 'disconnected', wait=0.0,
|
||||||
|
func=self._disconnect, args=(reconnect,))
|
||||||
|
|
||||||
def _disconnect(self, reconnect=False):
|
def _disconnect(self, reconnect=False):
|
||||||
# Send the end of stream marker.
|
# Send the end of stream marker.
|
||||||
self.send_raw(self.stream_footer)
|
self.send_raw(self.stream_footer)
|
||||||
|
@ -305,14 +308,15 @@ class XMLStream(object):
|
||||||
self.event("disconnected", direct=True)
|
self.event("disconnected", direct=True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def reconnect(self):
|
def reconnect(self):
|
||||||
"""
|
"""
|
||||||
Reset the stream's state and reconnect to the server.
|
Reset the stream's state and reconnect to the server.
|
||||||
"""
|
"""
|
||||||
logging.debug("reconnecting...")
|
logging.debug("reconnecting...")
|
||||||
self.state.transition('connected', 'disconnected', wait=0.0, func=self._disconnect, args=(True,))
|
self.state.transition('connected', 'disconnected', wait=0.0,
|
||||||
return self.state.transition('disconnected', 'connected', wait=0.0, func=self._connect)
|
func=self._disconnect, args=(True,))
|
||||||
|
return self.state.transition('disconnected', 'connected',
|
||||||
|
wait=0.0, func=self._connect)
|
||||||
|
|
||||||
def set_socket(self, socket, ignore=False):
|
def set_socket(self, socket, ignore=False):
|
||||||
"""
|
"""
|
||||||
|
@ -517,8 +521,8 @@ class XMLStream(object):
|
||||||
# processed in the queue.
|
# processed in the queue.
|
||||||
with self.__event_handlers_lock:
|
with self.__event_handlers_lock:
|
||||||
try:
|
try:
|
||||||
handler_index = self.__event_handlers[name].index(handler)
|
h_index = self.__event_handlers[name].index(handler)
|
||||||
self.__event_handlers[name].pop(handler_index)
|
self.__event_handlers[name].pop(h_index)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -754,7 +758,7 @@ class XMLStream(object):
|
||||||
if handler.checkDelete():
|
if handler.checkDelete():
|
||||||
self.__handlers.pop(self.__handlers.index(handler))
|
self.__handlers.pop(self.__handlers.index(handler))
|
||||||
except:
|
except:
|
||||||
pass #not thread safe
|
pass # not thread safe
|
||||||
unhandled = False
|
unhandled = False
|
||||||
|
|
||||||
# Some stanzas require responses, such as Iq queries. A default
|
# Some stanzas require responses, such as Iq queries. A default
|
||||||
|
|
Loading…
Reference in a new issue