Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Response objects now behave more like lists and strs.

  • Loading branch information...
commit 0d6c06464366d66e458910da81d62ce0eda811a0 1 parent ca24238
@sixohsix authored
Showing with 15 additions and 7 deletions.
  1. +15 −7 twitter/api.py
View
22 twitter/api.py
@@ -59,9 +59,6 @@ def __getattr__(self, k):
except AttributeError:
return getattr(self._real_response, k)
- def __iter__(self):
- return iter(self._real_response)
-
@property
def rate_limit_remaining(self):
"""
@@ -77,6 +74,17 @@ def rate_limit_reset(self):
return int(self.headers.getheader('X-RateLimit-Reset'))
+# Multiple inheritance makes my inner Java nerd cry. Why can't I just
+# add arbitrary attributes to list or str objects?! Guido, we need to
+# talk.
+class TwitterJsonResponse(list, TwitterResponse):
+ __doc__ = """Twitter JSON Response
+ """ + TwitterResponse.__doc__
+class TwitterXmlResponse(str, TwitterResponse):
+ __doc__ = """Twitter XML Response
+ """ + TwitterResponse.__doc__
+
+
class TwitterCall(object):
def __init__(
self, auth, format, domain, uri="", agent=None,
@@ -143,10 +151,9 @@ def __call__(self, **kwargs):
try:
handle = urllib2.urlopen(req)
if "json" == self.format:
- msg_data = json.loads(handle.read())
+ return TwitterJsonResponse(json.loads(handle.read()))
else:
- msg_data = handle.read()
- return TwitterResponse(msg_data, handle.headers)
+ return TwitterXmlResponse(handle.read())
except urllib2.HTTPError, e:
if (e.code == 304):
return []
@@ -272,4 +279,5 @@ def __init__(
secure=secure, uriparts=uriparts)
-__all__ = ["Twitter", "TwitterError", "TwitterHTTPError"]
+__all__ = ["Twitter", "TwitterError", "TwitterHTTPError", "TwitterJsonResponse",
+ "TwitterXmlResponse"]
Please sign in to comment.
Something went wrong with that request. Please try again.