+ try:
+ if self.timeout:
+ ready_to_read = select.select([sock], [], [], self.timeout)
+ if ready_to_read[0]:
+ self.buf += sock.recv(1024)
+ if time.time() - self.timer > self.timeout:
+ yield {"timeout":True}
+ else:
+ yield {"timeout":True}
+ else:
+ self.buf += sock.recv(2048)
+ except SSLError as e:
+ if (not self.block or self.timeout) and (e.errno == 2):
+ # Apparently this means there was nothing in the socket buf
+ 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):
+ 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)