2010-03-26 21:32:16 +00:00
|
|
|
"""
|
|
|
|
SleekXMPP: The Sleek XMPP Library
|
|
|
|
Copyright (C) 2010 Nathanael C. Fritz
|
|
|
|
This file is part of SleekXMPP.
|
|
|
|
|
2010-07-20 15:19:49 +00:00
|
|
|
See the file LICENSE for copying permission.
|
2010-03-26 21:32:16 +00:00
|
|
|
"""
|
2010-08-27 15:29:48 +00:00
|
|
|
|
2010-01-08 15:45:26 +00:00
|
|
|
from socket import _fileobject
|
2010-01-25 18:40:44 +00:00
|
|
|
import socket
|
2010-01-08 15:45:26 +00:00
|
|
|
|
2010-09-01 18:25:30 +00:00
|
|
|
|
2010-08-27 15:29:48 +00:00
|
|
|
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.
|
2010-01-08 15:45:26 +00:00
|
|
|
|
2010-08-27 15:29:48 +00:00
|
|
|
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
|
2010-01-25 18:40:44 +00:00
|
|
|
|
2010-09-01 18:25:30 +00:00
|
|
|
|
2010-01-25 18:40:44 +00:00
|
|
|
class Socket26(socket._socketobject):
|
|
|
|
|
2010-08-27 15:29:48 +00:00
|
|
|
"""
|
|
|
|
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)
|