Skip to content

Commit

Permalink
Fix missing TwitterHTTPError in Streaming
Browse files Browse the repository at this point in the history
The existing error was never reached, luckily since it was using
undefined arguments. moved it in its right place and added handling
ssl errors as TwitterHTTPError.

(Fix python-twitter-tools#136)
  • Loading branch information
RouxRC authored and Dennis Kanygin committed Apr 18, 2014
1 parent 8442d80 commit 3051fd5
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions twitter/stream.py
Expand Up @@ -143,7 +143,10 @@ def read(self):

class TwitterJSONIter(object):

def __init__(self, handle, uri, arg_data, block=True, timeout=None, display_sizes=False):
def __init__(self, handle, uri, arg_data, block=True,
timeout=None, display_sizes=False):
self.uri = uri
self.arg_data = arg_data
self.decoder = json.JSONDecoder()
self.handle = handle
self.buf = b""
Expand Down Expand Up @@ -187,12 +190,6 @@ def __iter__(self):
pass
else:
yield None
except urllib_error.HTTPError as e:
self.format = ''
raise TwitterHTTPError(e, self.uri, self.format, self.arg_data)
except Exception:
raise StopIteration

# this is a non-blocking read (ie, it will return if any data is available)
try:
if self.timeout:
Expand All @@ -207,14 +204,15 @@ def __iter__(self):
# Apparently this means there was nothing in the socket buf
pass
else:
print "SSL Error %s" % e
raise StopIteration
break
raise TwitterHTTPError(e, self.uri, self.arg_data)

def handle_stream_response(req, uri, arg_data, block=True, timeout=None):
handle = urllib_request.urlopen(req,)
return iter(TwitterJSONIter(handle, uri, arg_data, block, timeout=timeout,
try:
handle = urllib_request.urlopen(req,)
return iter(TwitterJSONIter(handle, uri, arg_data, block, timeout=timeout,
display_sizes=("delimited=length" in req.get_data().lower())))
except urllib_error.HTTPError as e:
raise TwitterHTTPError(e, uri, arg_data)

class TwitterStreamCallWithTimeout(TwitterCall):
def _handle_response(self, req, uri, arg_data, _timeout=None):
Expand Down

0 comments on commit 3051fd5

Please sign in to comment.