From 8382038342afd7f85035e962187658d9bf2fa7c1 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 24 Apr 2009 21:42:19 -0500 Subject: [PATCH] Breaking the read into a seperate function make it look cleaner --- src/rtm_api.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/rtm_api.py b/src/rtm_api.py index c30b5b9..15c5d84 100644 --- a/src/rtm_api.py +++ b/src/rtm_api.py @@ -91,18 +91,14 @@ class RTMapi(object): warnings.warn("Performing download of %s" % url, stacklevel=5) return urllib2.urlopen(url) - def get(self, **params): - "Get the XML response for the passed `params`." - params['api_key'] = self._apiKey - params['format'] = 'json' - params['api_sig'] = self._sign(params) - - connection = self.open_url(SERVICE_URL, params) - + @staticmethod + def read(connection, timeout): # It appears that urllib uses the non-blocking variant of file objects # which means reads might not always be complete, so grabbing as much # of the data as possible with a sleep in between to give it more time # to grab data. + contentLengthField = "Content-Length" + chunks = [] chunk = connection.read() while chunk: @@ -117,6 +113,17 @@ class RTMapi(object): len(json), ) + return json + + def get(self, **params): + "Get the XML response for the passed `params`." + params['api_key'] = self._apiKey + params['format'] = 'json' + params['api_sig'] = self._sign(params) + + connection = self.open_url(SERVICE_URL, params) + json = self.read(connection, 5) + data = DottedDict('ROOT', parse_json(json)) rsp = data.rsp -- 1.7.9.5