]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/api.py
More stuff in gitignore.
[z_archive/twitter.git] / twitter / api.py
index 694d2c4d679ad7e4724ba4f0aaf3f504488243b7..6abdd97ab5783bd148311cb2cd271e97a70b823b 100644 (file)
@@ -1,7 +1,5 @@
 import urllib2
 
-from exceptions import Exception
-
 from twitter.twitter_globals import POST_ACTIONS
 from twitter.auth import NoAuth
 
@@ -72,14 +70,16 @@ def wrap_response(response, headers):
     if response_typ is bool:
         # HURF DURF MY NAME IS PYTHON AND I CAN'T SUBCLASS bool.
         response_typ = int
-    class WrappedTwitterResponse(TwitterResponse, response_typ):
+
+    class WrappedTwitterResponse(response_typ, TwitterResponse):
         __doc__ = TwitterResponse.__doc__
 
-        def __init__(self, response, headers):
-            response_typ.__init__(self, response)
+        def __init__(self, response):
+            if response_typ is not int:
+                response_typ.__init__(self, response)
             TwitterResponse.__init__(self, headers)
 
-    return WrappedTwitterResponse(response, headers)
+    return WrappedTwitterResponse(response)
 
 
 
@@ -149,11 +149,12 @@ class TwitterCall(object):
         try:
             handle = urllib2.urlopen(req)
             if "json" == self.format:
-                res = json.loads(handle.read())
+                res = json.loads(handle.read().decode('utf8'))
                 return wrap_response(res, handle.headers)
             else:
-                return wrap_response(str(handle.read()), handle.headers)
-        except urllib2.HTTPError, e:
+                return wrap_response(
+                    handle.read().decode('utf8'), handle.headers)
+        except urllib2.HTTPError as e:
             if (e.code == 304):
                 return []
             else: