Skip to content

Commit

Permalink
fix python 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
boogheta committed Jan 17, 2014
1 parent ad0aade commit 82c7c43
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions twitter/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

from .api import TwitterCall, wrap_response, TwitterHTTPError

re_clean_hexa = re.compile(r"^[\n\r\s]*[a-f\d]+[\n\r]+")
re_clean_hexa2 = re.compile(r"[\n\r]+[a-f\d]+[\n\r]+")
re_clean_hexa = re.compile(b"^[\n\r\s]*[a-f\d]+[\n\r]+")
re_clean_hexa2 = re.compile(b"[\n\r]+[a-f\d]+[\n\r]+")
def clean_hexa(t):
t = re_clean_hexa.sub('', t)
return re_clean_hexa2.sub('', t)
t = re_clean_hexa.sub(b'', t)
return re_clean_hexa2.sub(b'', t)

class TwitterJSONIter(object):

Expand Down Expand Up @@ -49,7 +49,7 @@ def __iter__(self):
for size in utf8_buf[:pos].split('\n'):
yield wrap_response(size.strip(), self.handle.headers)
utf8_buf = utf8_buf[pos:]
self.buf = utf8_buf.encode('utf8')
self.buf = utf8_buf.strip("\n\r").encode('utf8')
try:
res, ptr = self.decoder.raw_decode(utf8_buf)
self.buf = utf8_buf[ptr:].encode('utf8')
Expand All @@ -69,7 +69,7 @@ def __iter__(self):
if not ready_to_read[0] and time.time() - self.timer > self.timeout:
yield {"timeout":True}
continue
self.buf += clean_hexa(sock.recv(1024)).strip('\n\r')
self.buf += clean_hexa(sock.recv(1024))
if self.timeout and not self.buf and time.time() - self.timer > self.timeout:
yield {"timeout":True}
except SSLError as e:
Expand All @@ -84,7 +84,7 @@ def handle_stream_response(req, uri, arg_data, block=True, timeout=None):
handle = urllib_request.urlopen(req,)
display_sizes = False
if req.data:
display_sizes = ("delimited=length" in req.data.lower())
display_sizes = ("delimited=length" in str(req.data.lower()))
return iter(TwitterJSONIter(handle, uri, arg_data, block, timeout=timeout,
display_sizes=display_sizes))
except urllib_error.HTTPError as e:
Expand Down

0 comments on commit 82c7c43

Please sign in to comment.