X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/221bc078584e2131e6a38f6d3fd7b6bb2249d192..3f6ca83dfc697b71974d2fa3b10b4e68c4d4c621:/twitter/stream.py diff --git a/twitter/stream.py b/twitter/stream.py index a0df98e..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