Permalink
Browse files

Stupid bug when inheriting from str.

  • Loading branch information...
1 parent 0d6c064 commit aef72b31d8e84c39435b720f6124db71109e3f9e @sixohsix committed Jul 13, 2010
Showing with 15 additions and 15 deletions.
  1. +1 −1 setup.py
  2. +14 −14 twitter/api.py
View
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import sys, os
-version = '1.4'
+version = '1.4.1'
install_requires = [
# -*- Extra requirements: -*-
View
@@ -49,16 +49,9 @@ class TwitterResponse(object):
httplib.HTTPHeaders instance. You can do
`response.headers.getheader('h')` to retrieve a header.
"""
- def __init__(self, real_response, headers):
- self._real_response = real_response
+ def __init__(self, headers):
self.headers = headers
- def __getattr__(self, k):
- try:
- return object.__getattr__(self, k)
- except AttributeError:
- return getattr(self._real_response, k)
-
@property
def rate_limit_remaining(self):
"""
@@ -77,10 +70,14 @@ def rate_limit_reset(self):
# 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):
+class TwitterJsonResponse(TwitterResponse, list):
__doc__ = """Twitter JSON Response
""" + TwitterResponse.__doc__
-class TwitterXmlResponse(str, TwitterResponse):
+ def __init__(self, lst, headers):
+ TwitterResponse.__init__(self, headers)
+ list.__init__(self, lst)
+
+class TwitterXmlResponse(TwitterResponse, str):
__doc__ = """Twitter XML Response
""" + TwitterResponse.__doc__
@@ -112,8 +109,8 @@ def __call__(self, **kwargs):
for uripart in self.uriparts:
# If this part matches a keyword argument, use the
# supplied value otherwise, just use the part.
- uriparts.append(kwargs.pop(uripart, uripart))
- uri = '/'.join(uriparts)
+ uriparts.append(unicode(kwargs.pop(uripart, uripart)))
+ uri = u'/'.join(uriparts)
method = "GET"
for action in POST_ACTIONS:
@@ -151,9 +148,12 @@ def __call__(self, **kwargs):
try:
handle = urllib2.urlopen(req)
if "json" == self.format:
- return TwitterJsonResponse(json.loads(handle.read()))
+ return TwitterJsonResponse(json.loads(handle.read()),
+ handle.headers)
else:
- return TwitterXmlResponse(handle.read())
+ r = TwitterXmlResponse(handle.read())
+ r.headers = handle.headers
+ return r
except urllib2.HTTPError, e:
if (e.code == 304):
return []

0 comments on commit aef72b3

Please sign in to comment.