projects
/
doneit
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4c99ca4
)
Breaking the read into a seperate function make it look cleaner
author
Ed Page
<eopage@byu.net>
Sat, 25 Apr 2009 02:42:19 +0000
(21:42 -0500)
committer
Ed Page
<eopage@byu.net>
Sat, 25 Apr 2009 02:42:19 +0000
(21:42 -0500)
src/rtm_api.py
patch
|
blob
|
history
diff --git
a/src/rtm_api.py
b/src/rtm_api.py
index
c30b5b9
..
15c5d84
100644
(file)
--- 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)
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.
# 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:
chunks = []
chunk = connection.read()
while chunk:
@@
-117,6
+113,17
@@
class RTMapi(object):
len(json),
)
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
data = DottedDict('ROOT', parse_json(json))
rsp = data.rsp