from .api import TwitterCall, wrap_response, TwitterHTTPError
-CRLF = b'\r\n'
-
PY_3_OR_HIGHER = sys.version_info >= (3, 0)
+CRLF = b'\r\n'
+
Timeout = {'timeout': True}
Hangup = {'hangup': True}
HeartbeatTimeout = {'heartbeat_timeout': True, 'hangup': True}
class EndOfStream(Exception):
pass
+range = range if PY_3_OR_HIGHER else xrange
+
class SocketShim(io.IOBase):
"""
Adapts a raw socket to fit the IO protocol.
return self.sock.recv_into(buf)
def recv_chunk(reader): # -> bytearray:
- for headerlen in xrange(12):
+ for headerlen in range(12):
header = reader.peek(headerlen)[:headerlen]
if header.endswith(CRLF):
break
def __iter__(self):
actually_block = self.block and not self.timeout
- sock_timeout = min(self.timeout, self.heartbeat_timeout) if actually_block else None
+ sock_timeout = min(self.timeout or 1000000, self.heartbeat_timeout) if actually_block else None
sock = self.handle.fp.raw._sock if PY_3_OR_HIGHER else self.handle.fp._sock.fp._sock
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
sock.setblocking(actually_block)