mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
fixed socket name collision in xmlstream.py and fixed python 3.x compatibility
This commit is contained in:
parent
a41a4369c6
commit
0d0b963fe5
6 changed files with 19 additions and 16 deletions
6
setup.py
6
setup.py
|
@ -44,10 +44,14 @@ packages = [ 'sleekxmpp',
|
||||||
'sleekxmpp/xmlstream',
|
'sleekxmpp/xmlstream',
|
||||||
'sleekxmpp/xmlstream/matcher',
|
'sleekxmpp/xmlstream/matcher',
|
||||||
'sleekxmpp/xmlstream/handler',
|
'sleekxmpp/xmlstream/handler',
|
||||||
'sleekxmpp/xmlstream/tostring',
|
|
||||||
'sleekxmpp/thirdparty',
|
'sleekxmpp/thirdparty',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if sys.version_info < (3, 0):
|
||||||
|
py_modules = ['sleekxmpp.xmlstream.tostring.tostring26']
|
||||||
|
else:
|
||||||
|
py_modules = ['sleekxmpp.xmlstream.tostring.tostring']
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = "sleekxmpp",
|
name = "sleekxmpp",
|
||||||
version = VERSION,
|
version = VERSION,
|
||||||
|
|
|
@ -162,7 +162,8 @@ class ClientXMPP(BaseXMPP):
|
||||||
intmax += answer.priority
|
intmax += answer.priority
|
||||||
addresses[intmax] = (answer.target.to_text()[:-1],
|
addresses[intmax] = (answer.target.to_text()[:-1],
|
||||||
answer.port)
|
answer.port)
|
||||||
priorities = addresses.keys()
|
#python3 returns a generator for dictionary keys
|
||||||
|
priorities = [x for x in addresses.keys()]
|
||||||
priorities.sort()
|
priorities.sort()
|
||||||
|
|
||||||
picked = random.randint(0, intmax)
|
picked = random.randint(0, intmax)
|
||||||
|
|
|
@ -290,7 +290,6 @@ class DefaultConfig(ElementBase):
|
||||||
|
|
||||||
def setConfig(self, value):
|
def setConfig(self, value):
|
||||||
self['form'].setStanzaValues(value.getStanzaValues())
|
self['form'].setStanzaValues(value.getStanzaValues())
|
||||||
print self['form']['title']
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
registerStanzaPlugin(PubsubOwner, DefaultConfig)
|
registerStanzaPlugin(PubsubOwner, DefaultConfig)
|
||||||
|
@ -370,7 +369,6 @@ class OwnerDefault(OwnerConfigure):
|
||||||
|
|
||||||
def setConfig(self, value):
|
def setConfig(self, value):
|
||||||
self['form'].setStanzaValues(value.getStanzaValues())
|
self['form'].setStanzaValues(value.getStanzaValues())
|
||||||
print self['from']['title']
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
registerStanzaPlugin(PubsubOwner, OwnerDefault)
|
registerStanzaPlugin(PubsubOwner, OwnerDefault)
|
||||||
|
|
|
@ -53,7 +53,7 @@ class SleekTest(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
xml = ET.fromstring(xml_string)
|
xml = ET.fromstring(xml_string)
|
||||||
return xml
|
return xml
|
||||||
except SyntaxError, e:
|
except SyntaxError as e:
|
||||||
if 'unbound' in e.msg:
|
if 'unbound' in e.msg:
|
||||||
known_prefixes = {
|
known_prefixes = {
|
||||||
'stream': 'http://etherx.jabber.org/streams'}
|
'stream': 'http://etherx.jabber.org/streams'}
|
||||||
|
|
8
sleekxmpp/thirdparty/statemachine.py
vendored
8
sleekxmpp/thirdparty/statemachine.py
vendored
|
@ -268,11 +268,11 @@ class _StateCtx:
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
def callback(s, s2):
|
def callback(s, s2):
|
||||||
print 1, s.transition('on', 'off', wait=0.0, func=callback, args=[s,s2])
|
print((1, s.transition('on', 'off', wait=0.0, func=callback, args=[s,s2])))
|
||||||
print 2, s2.transition('off', 'on', func=callback, args=[s,s2])
|
print((2, s2.transition('off', 'on', func=callback, args=[s,s2])))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
s = StateMachine(('off', 'on'))
|
s = StateMachine(('off', 'on'))
|
||||||
s2 = StateMachine(('off', 'on'))
|
s2 = StateMachine(('off', 'on'))
|
||||||
print 3, s.transition('off', 'on', wait=0.0, func=callback, args=[s,s2]),
|
print((3, s.transition('off', 'on', wait=0.0, func=callback, args=[s,s2]),))
|
||||||
print s.current_state(), s2.current_state()
|
print((s.current_state(), s2.current_state()))
|
||||||
|
|
|
@ -10,7 +10,7 @@ from __future__ import with_statement, unicode_literals
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket as Socket
|
||||||
import ssl
|
import ssl
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
@ -165,7 +165,7 @@ class XMLStream(object):
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
self.socket_class = Socket26
|
self.socket_class = Socket26
|
||||||
else:
|
else:
|
||||||
self.socket_class = socket.socket
|
self.socket_class = Socket.socket
|
||||||
|
|
||||||
self.use_ssl = False
|
self.use_ssl = False
|
||||||
self.use_tls = False
|
self.use_tls = False
|
||||||
|
@ -247,7 +247,7 @@ class XMLStream(object):
|
||||||
|
|
||||||
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")
|
||||||
|
@ -265,7 +265,7 @@ class XMLStream(object):
|
||||||
#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. Socket Error #%s: %s"
|
error_msg = "Could not connect. Socket Error #%s: %s"
|
||||||
logging.error(error_msg % (serr.errno, serr.strerror))
|
logging.error(error_msg % (serr.errno, serr.strerror))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
@ -297,8 +297,8 @@ class XMLStream(object):
|
||||||
try:
|
try:
|
||||||
self.socket.close()
|
self.socket.close()
|
||||||
self.filesocket.close()
|
self.filesocket.close()
|
||||||
self.socket.shutdown(socket.SHUT_RDWR)
|
self.socket.shutdown(Socket.SHUT_RDWR)
|
||||||
except socket.error as serr:
|
except Socket.error as serr:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
#clear your application state
|
#clear your application state
|
||||||
|
@ -670,7 +670,7 @@ class XMLStream(object):
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
logging.debug("SystemExit in _process")
|
logging.debug("SystemExit in _process")
|
||||||
self.stop.set()
|
self.stop.set()
|
||||||
except socket.error:
|
except Socket.error:
|
||||||
logging.exception('Socket Error')
|
logging.exception('Socket Error')
|
||||||
except:
|
except:
|
||||||
logging.exception('Connection error. Reconnecting.')
|
logging.exception('Connection error. Reconnecting.')
|
||||||
|
|
Loading…
Reference in a new issue