]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/api.py
Merge branch 'master' into py3-2
[z_archive/twitter.git] / twitter / api.py
index 19a561570463f0545674a01dff3b37c999dff866..570c78868c3dbbe1d25323a41b42c12f1c3780e9 100644 (file)
@@ -1,6 +1,4 @@
-import urllib2
-
-from exceptions import Exception
+import urllib.request, urllib.error, urllib.parse
 
 from twitter.twitter_globals import POST_ACTIONS
 from twitter.auth import NoAuth
@@ -77,7 +75,8 @@ def wrap_response(response, headers):
         __doc__ = TwitterResponse.__doc__
 
         def __init__(self, response):
-            response_typ.__init__(self, response)
+            if response_typ is not int:
+                response_typ.__init__(self, response)
             TwitterResponse.__init__(self, headers)
 
     return WrappedTwitterResponse(response)
@@ -111,8 +110,8 @@ class TwitterCall(object):
         for uripart in self.uriparts:
             # If this part matches a keyword argument, use the
             # supplied value otherwise, just use the part.
-            uriparts.append(unicode(kwargs.pop(uripart, uripart)))
-        uri = u'/'.join(uriparts)
+            uriparts.append(str(kwargs.pop(uripart, uripart)))
+        uri = '/'.join(uriparts)
 
         method = "GET"
         for action in POST_ACTIONS:
@@ -145,16 +144,17 @@ class TwitterCall(object):
             else:
                 body = arg_data
 
-        req = urllib2.Request(uriBase, body, headers)
+        req = urllib.request.Request(uriBase, body, headers)
 
         try:
-            handle = urllib2.urlopen(req)
+            handle = urllib.request.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 urllib.error.HTTPError as e:
             if (e.code == 304):
                 return []
             else: