summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-10-07 19:43:51 -0400
committerLance Stout <lancestout@gmail.com>2010-10-07 19:43:51 -0400
commita8b948cd333e0526440a776598e053ef153aa2bc (patch)
tree18a73b940cabf4453f4088a81c712510b93a2333 /sleekxmpp/xmlstream
parente02ffe854745c6c39127967f5d1dcaff915d7190 (diff)
downloadslixmpp-a8b948cd333e0526440a776598e053ef153aa2bc.tar.gz
slixmpp-a8b948cd333e0526440a776598e053ef153aa2bc.tar.bz2
slixmpp-a8b948cd333e0526440a776598e053ef153aa2bc.tar.xz
slixmpp-a8b948cd333e0526440a776598e053ef153aa2bc.zip
SleekTest may now run against a live stream.
Moved SleekTest to sleekxmpp.test package. Corrected error in XML compare method. Added TestLiveSocket to run stream tests against live streams. Modified XMLStream to work with TestLiveSocket.
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index 60adfb2a..3152ec94 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -166,6 +166,11 @@ class XMLStream(object):
self.filesocket = None
self.set_socket(socket)
+ if sys.version_info < (3, 0):
+ self.socket_class = Socket26
+ else:
+ self.socket_class = socket.socket
+
self.use_ssl = False
self.use_tls = False
@@ -238,14 +243,17 @@ class XMLStream(object):
# Repeatedly attempt to connect until a successful connection
# is established.
while reattempt and not self.state['connected']:
- if sys.version_info < (3, 0):
- self.socket = Socket26(socket.AF_INET, socket.SOCK_STREAM)
- else:
- self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.socket = self.socket_class(socket.AF_INET, socket.SOCK_STREAM)
self.socket.settimeout(None)
if self.use_ssl and self.ssl_support:
logging.debug("Socket Wrapped for SSL")
- self.socket = ssl.wrap_socket(self.socket)
+ ssl_socket = ssl.wrap_socket(self.socket)
+ if hasattr(self.socket, 'socket'):
+ # We are using a testing socket, so preserve the top
+ # layer of wrapping.
+ self.socket.socket = ssl_socket
+ else:
+ self.socket = ssl_socket
try:
self.socket.connect(self.address)
@@ -334,9 +342,15 @@ class XMLStream(object):
"""
if self.ssl_support:
logging.info("Negotiating TLS")
- self.socket = ssl.wrap_socket(self.socket,
- ssl_version=ssl.PROTOCOL_TLSv1,
- do_handshake_on_connect=False)
+ ssl_socket = ssl.wrap_socket(self.socket,
+ ssl_version=ssl.PROTOCOL_TLSv1,
+ do_handshake_on_connect=False)
+ if hasattr(self.socket, 'socket'):
+ # We are using a testing socket, so preserve the top
+ # layer of wrapping.
+ self.socket.socket = ssl_socket
+ else:
+ self.socket = ssl_socket
self.socket.do_handshake()
self.set_socket(self.socket)
return True