]> jfr.im git - z_archive/twitter.git/commitdiff
Change some default attributes and add TwitterHTTPError (ref: RouxRC [3d29eae] &...
authorAndrew W. Donoho <redacted>
Wed, 15 Jan 2014 01:26:27 +0000 (19:26 -0600)
committerAndrew W. Donoho <redacted>
Wed, 15 Jan 2014 01:26:27 +0000 (19:26 -0600)
twitter/stream.py

index b11a89363ff508de6d65d2f3d8eb260af0efc6cb..e4174e59648bbe15a36f3a12a5f5bdbd45f2a197 100644 (file)
@@ -17,6 +17,8 @@ class TwitterJSONIter(object):
     def __init__(self, handle, uri, arg_data, block=True, timeout=None):
         self.decoder = json.JSONDecoder()
         self.handle = handle
     def __init__(self, handle, uri, arg_data, block=True, timeout=None):
         self.decoder = json.JSONDecoder()
         self.handle = handle
+        self.uri = uri
+        self.arg_data = arg_data
         self.buf = b""
         self.block = block
         self.timeout = timeout
         self.buf = b""
         self.block = block
         self.timeout = timeout
@@ -45,7 +47,7 @@ class TwitterJSONIter(object):
                 else:
                     yield None
             except urllib_error.HTTPError as e:
                 else:
                     yield None
             except urllib_error.HTTPError as e:
-                raise TwitterHTTPError(e, uri, self.format, arg_data)
+                raise TwitterHTTPError(e, self.uri, "json", self.arg_data)
             # this is a non-blocking read (ie, it will return if any data is available)
             try:
                 if self.timeout:
             # this is a non-blocking read (ie, it will return if any data is available)
             try:
                 if self.timeout:
@@ -64,18 +66,20 @@ class TwitterJSONIter(object):
                     pass
                 else:
                     raise
                     pass
                 else:
                     raise
+            except urllib_error.HTTPError as e:
+                raise TwitterHTTPError(e, self.uri, "json", self.arg_data)
 
 
-def handle_stream_response(req, uri, arg_data, block, timeout=None):
+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))
 
 class TwitterStreamCallWithTimeout(TwitterCall):
     def _handle_response(self, req, uri, arg_data, _timeout=None):
     handle = urllib_request.urlopen(req,)
     return iter(TwitterJSONIter(handle, uri, arg_data, block, timeout=timeout))
 
 class TwitterStreamCallWithTimeout(TwitterCall):
     def _handle_response(self, req, uri, arg_data, _timeout=None):
-        return handle_stream_response(req, uri, arg_data, block=True, timeout=self.timeout)
+        return handle_stream_response(req, uri, arg_data, timeout=self.timeout)
 
 class TwitterStreamCall(TwitterCall):
     def _handle_response(self, req, uri, arg_data, _timeout=None):
 
 class TwitterStreamCall(TwitterCall):
     def _handle_response(self, req, uri, arg_data, _timeout=None):
-        return handle_stream_response(req, uri, arg_data, block=True)
+        return handle_stream_response(req, uri, arg_data)
 
 class TwitterStreamCallNonBlocking(TwitterCall):
     def _handle_response(self, req, uri, arg_data, _timeout=None):
 
 class TwitterStreamCallNonBlocking(TwitterCall):
     def _handle_response(self, req, uri, arg_data, _timeout=None):