Commit 1c71f6f0 authored by Denis Bilenko's avatar Denis Bilenko

socket: fix 2.7 issue where buffer is no longer accepted as sendall's...

socket: fix 2.7 issue where buffer is no longer accepted as sendall's argument. using memoryview instead. Thanks to Luigi Pugnetti.
parent 10e6643f
...@@ -239,6 +239,13 @@ if sys.version_info[:2] <= (2, 4): ...@@ -239,6 +239,13 @@ if sys.version_info[:2] <= (2, 4):
self._sock = None self._sock = None
if sys.version_info[:2] < (2, 7):
_get_memory = buffer
else:
def _get_memory(string, offset):
return memoryview(string)[offset:]
class _closedsocket(object): class _closedsocket(object):
__slots__ = [] __slots__ = []
def _dummy(*args): def _dummy(*args):
...@@ -452,13 +459,13 @@ class socket(object): ...@@ -452,13 +459,13 @@ class socket(object):
if self.timeout is None: if self.timeout is None:
data_sent = 0 data_sent = 0
while data_sent < len(data): while data_sent < len(data):
data_sent += self.send(buffer(data, data_sent), flags) data_sent += self.send(_get_memory(data, data_sent), flags)
else: else:
timeleft = self.timeout timeleft = self.timeout
end = time.time() + timeleft end = time.time() + timeleft
data_sent = 0 data_sent = 0
while True: while True:
data_sent += self.send(buffer(data, data_sent), flags, timeout=timeleft) data_sent += self.send(_get_memory(data, data_sent), flags, timeout=timeleft)
if data_sent >= len(data): if data_sent >= len(data):
break break
timeleft = end - time.time() timeleft = end - time.time()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment