summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-08-27 11:29:48 -0400
committerLance Stout <lancestout@gmail.com>2010-08-27 11:29:48 -0400
commit6677df39f2ed3a949fa31df847bb08122190a26d (patch)
tree3b7c61b0b31c5f6e7aec94e9c00077bd78ce8be9
parenta2c515bc978cbabb1e6ac4398a8f0a11bbc9d9f8 (diff)
downloadslixmpp-6677df39f2ed3a949fa31df847bb08122190a26d.tar.gz
slixmpp-6677df39f2ed3a949fa31df847bb08122190a26d.tar.bz2
slixmpp-6677df39f2ed3a949fa31df847bb08122190a26d.tar.xz
slixmpp-6677df39f2ed3a949fa31df847bb08122190a26d.zip
Updated xmlstream.filesocket.
-rw-r--r--sleekxmpp/xmlstream/filesocket.py35
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py3
2 files changed, 26 insertions, 12 deletions
diff --git a/sleekxmpp/xmlstream/filesocket.py b/sleekxmpp/xmlstream/filesocket.py
index 07b395dc..b0c15562 100644
--- a/sleekxmpp/xmlstream/filesocket.py
+++ b/sleekxmpp/xmlstream/filesocket.py
@@ -5,21 +5,36 @@
See the file LICENSE for copying permission.
"""
+
from socket import _fileobject
import socket
-class filesocket(_fileobject):
+class FileSocket(_fileobject):
+
+ """
+ Create a file object wrapper for a socket to work around
+ issues present in Python 2.6 when using sockets as file objects.
- def read(self, size=4096):
- data = self._sock.recv(size)
- if data is not None:
- return data
+ The parser for xml.etree.cElementTree requires a file, but we will
+ be reading from the XMPP connection socket instead.
+ """
+
+ def read(self, size=4096):
+ """Read data from the socket as if it were a file."""
+ data = self._sock.recv(size)
+ if data is not None:
+ return data
class Socket26(socket._socketobject):
- def makefile(self, mode='r', bufsize=-1):
- """makefile([mode[, bufsize]]) -> file object
- Return a regular file object corresponding to the socket. The mode
- and bufsize arguments are as for the built-in open() function."""
- return filesocket(self._sock, mode, bufsize)
+ """
+ A custom socket implementation that uses our own FileSocket class
+ to work around issues in Python 2.6 when using sockets as files.
+ """
+
+ def makefile(self, mode='r', bufsize=-1):
+ """makefile([mode[, bufsize]]) -> file object
+ Return a regular file object corresponding to the socket. The mode
+ and bufsize arguments are as for the built-in open() function."""
+ return FileSocket(self._sock, mode, bufsize)
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index bf39bb33..415567e2 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -139,8 +139,7 @@ class XMLStream(object):
self.socket = ssl.wrap_socket(self.socket, ssl_version=ssl.PROTOCOL_TLSv1, do_handshake_on_connect=False)
self.socket.do_handshake()
if sys.version_info < (3,0):
- from . filesocket import filesocket
- self.filesocket = filesocket(self.socket)
+ self.filesocket = filesocket.FileSocket(self.socket)
else:
self.filesocket = self.socket.makefile('rb', 0)
return True