mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 19:19:55 +00:00
removed stupid monkeypatch for filesocket
This commit is contained in:
parent
6e1aa0690f
commit
6e4c1128ec
2 changed files with 20 additions and 7 deletions
|
@ -1,8 +1,18 @@
|
||||||
from socket import _fileobject
|
from socket import _fileobject
|
||||||
|
import socket
|
||||||
|
|
||||||
class filesocket(_fileobject):
|
class filesocket(_fileobject):
|
||||||
|
|
||||||
def read(self, size=-1):
|
def read(self, size=4096):
|
||||||
data = self._sock.recv(size)
|
data = self._sock.recv(size)
|
||||||
if data is not None:
|
if data is not None:
|
||||||
return data
|
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)
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import sys
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
#monkey patch broken filesocket object
|
#monkey patch broken filesocket object
|
||||||
from . import filesocket
|
from . import filesocket
|
||||||
socket._fileobject = filesocket.filesocket
|
#socket._fileobject = filesocket.filesocket
|
||||||
|
|
||||||
|
|
||||||
class RestartStream(Exception):
|
class RestartStream(Exception):
|
||||||
|
@ -96,7 +96,10 @@ class XMLStream(object):
|
||||||
if use_tls is not None:
|
if use_tls is not None:
|
||||||
self.use_tls = use_tls
|
self.use_tls = use_tls
|
||||||
self.state.set('is client', True)
|
self.state.set('is client', True)
|
||||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
if sys.version_info < (3, 0):
|
||||||
|
self.socket = filesocket.Socket26(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
else:
|
||||||
|
self.socket = socket.socket(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")
|
||||||
|
@ -222,10 +225,9 @@ class XMLStream(object):
|
||||||
def sendRaw(self, data):
|
def sendRaw(self, data):
|
||||||
logging.debug("SEND: %s" % data)
|
logging.debug("SEND: %s" % data)
|
||||||
try:
|
try:
|
||||||
self.socket.send(bytes(data, "utf-8"))
|
self.socket.send(data.encode('utf-8'))
|
||||||
except TypeError:
|
#self.socket.send(bytes(data, "utf-8"))
|
||||||
self.socket.send(bytes(data))
|
#except socket.error,(errno, strerror):
|
||||||
#except socket.error,(errno, strerror):
|
|
||||||
except:
|
except:
|
||||||
self.state.set('connected', False)
|
self.state.set('connected', False)
|
||||||
if self.state.reconnect:
|
if self.state.reconnect:
|
||||||
|
@ -303,6 +305,7 @@ class XMLStream(object):
|
||||||
try:
|
try:
|
||||||
handler.run(args[0])
|
handler.run(args[0])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
args[0].exception(e)
|
args[0].exception(e)
|
||||||
elif etype == 'sched':
|
elif etype == 'sched':
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue