X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/ff33f9f1fcc6aaad5f0604d7b655e4c1fa5af0d9..894d371790b2d7f5909061fd71ace11092575516:/twitter/stream.py diff --git a/twitter/stream.py b/twitter/stream.py index a8ac54d..6ecc49e 100644 --- a/twitter/stream.py +++ b/twitter/stream.py @@ -12,7 +12,7 @@ import sys, select, time from .api import TwitterCall, wrap_response, TwitterHTTPError -python26 = sys.version_info < (2, 7) +python27_3 = sys.version_info >= (2, 7) def recv_chunk(sock): # -> bytearray: header = sock.recv(8) # Scan for an up to 16MiB chunk size (0xffffff). @@ -33,11 +33,11 @@ def recv_chunk(sock): # -> bytearray: else: # There is more to read in the chunk. end = len(header) - start chunk[:end] = header[start:] - if python26: # less efficient for python2.6 compatibility - chunk[end:] = sock.recv(max(0, size - end)) - else: # When possible, use less memory by reading directly into the buffer. + if python27_3: # When possible, use less memory by reading directly into the buffer. buffer = memoryview(chunk)[end:] # Create a view into the bytearray to hold the rest of the chunk. sock.recv_into(buffer) + else: # less efficient for python2.6 compatibility + chunk[end:] = sock.recv(max(0, size - end)) sock.recv(2) # Read the trailing CRLF pair. Throw it away. return chunk @@ -70,7 +70,7 @@ class TwitterJSONIter(object): yield wrap_response(res, self.handle.headers) continue except ValueError as e: - if self.block and not self.timeout: pass + if self.block: pass else: yield None try: buf = buf.lstrip() # Remove any keep-alive delimiters to detect hangups.