From 79871542b338bc48ea2db8143bec08ca975787f2 Mon Sep 17 00:00:00 2001 From: Telofy Date: Thu, 12 Dec 2013 01:04:52 +0100 Subject: [PATCH] Refactored streaming API interface maintaining backward compatibility --- twython/streaming/api.py | 5 ++++- twython/streaming/types.py | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/twython/streaming/api.py b/twython/streaming/api.py index c814acb..a16473e 100644 --- a/twython/streaming/api.py +++ b/twython/streaming/api.py @@ -148,6 +148,7 @@ class TwythonStreamer(object): handler = getattr(self, 'on_' + message_type, None) if handler and callable(handler) and not handler(data.get(message_type)): break + yield data response.close() @@ -177,7 +178,9 @@ class TwythonStreamer(object): :param data: Error message sent from stream :type data: dict """ - return + # Include the content + raise requests.exceptions.HTTPError( + response.status_code, response.content) def on_timeout(self): # pragma: no cover """ Called when the request has timed out """ diff --git a/twython/streaming/types.py b/twython/streaming/types.py index 39a9ccb..4dd6e66 100644 --- a/twython/streaming/types.py +++ b/twython/streaming/types.py @@ -28,7 +28,7 @@ class TwythonStreamerTypes(object): """ url = 'https://userstream.twitter.com/%s/user.json' \ % self.streamer.api_version - self.streamer._request(url, params=params) + return self.streamer._request(url, params=params) def site(self, **params): """Stream site @@ -38,7 +38,7 @@ class TwythonStreamerTypes(object): """ url = 'https://sitestream.twitter.com/%s/site.json' \ % self.streamer.api_version - self.streamer._request(url, params=params) + return self.streamer._request(url, params=params) class TwythonStreamerTypesStatuses(object): @@ -62,7 +62,7 @@ class TwythonStreamerTypesStatuses(object): """ url = 'https://stream.twitter.com/%s/statuses/filter.json' \ % self.streamer.api_version - self.streamer._request(url, 'POST', params=params) + return self.streamer._request(url, 'POST', params=params) def sample(self, **params): """Stream statuses/sample @@ -74,7 +74,7 @@ class TwythonStreamerTypesStatuses(object): """ url = 'https://stream.twitter.com/%s/statuses/sample.json' \ % self.streamer.api_version - self.streamer._request(url, params=params) + return self.streamer._request(url, params=params) def firehose(self, **params): """Stream statuses/firehose @@ -86,4 +86,4 @@ class TwythonStreamerTypesStatuses(object): """ url = 'https://stream.twitter.com/%s/statuses/firehose.json' \ % self.streamer.api_version - self.streamer._request(url, params=params) + return self.streamer._request(url, params=params)