]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/api.py
Py3 exception fix
[z_archive/twitter.git] / twitter / api.py
index c61ffc50c56883a48ac048f13c0b2a2f8cd9fac1..9914ce6894a4153f2646c2d3d024cc0e478f7f58 100644 (file)
@@ -22,9 +22,11 @@ try:
 except ImportError:
     import simplejson as json
 
+
 class _DEFAULT(object):
     pass
 
+
 class TwitterError(Exception):
     """
     Base Exception thrown by the Twitter object when there is a
@@ -32,6 +34,7 @@ class TwitterError(Exception):
     """
     pass
 
+
 class TwitterHTTPError(TwitterError):
     """
     Exception thrown by the Twitter object when there is an
@@ -53,10 +56,11 @@ class TwitterHTTPError(TwitterError):
         fmt = ("." + self.format) if self.format else ""
         return (
             "Twitter sent status %i for URL: %s%s using parameters: "
-            "(%s)\ndetails: %s" %(
+            "(%s)\ndetails: %s" % (
                 self.e.code, self.uri, fmt, self.uriparts,
                 self.response_data))
 
+
 class TwitterResponse(object):
     """
     Response from a twitter request. Behaves like a list or a string
@@ -104,19 +108,18 @@ def wrap_response(response, headers):
         def __init__(self, response, headers):
             response_typ.__init__(self, response)
             TwitterResponse.__init__(self, headers)
+
         def __new__(cls, response, headers):
             return response_typ.__new__(cls, response)
 
-
     return WrappedTwitterResponse(response, headers)
 
 
-
 class TwitterCall(object):
 
     def __init__(
-        self, auth, format, domain, callable_cls, uri="",
-        uriparts=None, secure=True):
+            self, auth, format, domain, callable_cls, uri="",
+            uriparts=None, secure=True):
         self.auth = auth
         self.format = format
         self.domain = domain
@@ -132,8 +135,8 @@ class TwitterCall(object):
             def extend_call(arg):
                 return self.callable_cls(
                     auth=self.auth, format=self.format, domain=self.domain,
-                    callable_cls=self.callable_cls, uriparts=self.uriparts \
-                        + (arg,),
+                    callable_cls=self.callable_cls, uriparts=self.uriparts
+                    + (arg,),
                     secure=self.secure)
             if k == "_":
                 return extend_call
@@ -161,7 +164,7 @@ class TwitterCall(object):
         # the list of uriparts, assume the id goes at the end.
         id = kwargs.pop('id', None)
         if id:
-            uri += "/%s" %(id)
+            uri += "/%s" % (id)
 
         # If an _id kwarg is present, this is treated as id as a CGI
         # param.
@@ -178,8 +181,8 @@ class TwitterCall(object):
         dot = ""
         if self.format:
             dot = "."
-        uriBase = "http%s://%s/%s%s%s" %(
-                    secure_str, self.domain, uri, dot, self.format)
+        uriBase = "http%s://%s/%s%s%s" % (
+            secure_str, self.domain, uri, dot, self.format)
 
         headers = {'Accept-Encoding': 'gzip'}
         if self.auth:
@@ -204,7 +207,7 @@ class TwitterCall(object):
                 return handle
             try:
                 data = handle.read()
-            except httplib.IncompleteRead, e:
+            except httplib.IncompleteRead as e:
                 # Even if we don't get all the bytes we should have there
                 # may be a complete response in e.partial
                 data = e.partial
@@ -225,6 +228,7 @@ class TwitterCall(object):
             else:
                 raise TwitterHTTPError(e, uri, self.format, arg_data)
 
+
 class Twitter(TwitterCall):
     """
     The minimalist yet fully featured Twitter API class.
@@ -310,9 +314,9 @@ class Twitter(TwitterCall):
 
     """
     def __init__(
-        self, format="json",
-        domain="api.twitter.com", secure=True, auth=None,
-        api_version=_DEFAULT):
+            self, format="json",
+            domain="api.twitter.com", secure=True, auth=None,
+            api_version=_DEFAULT):
         """
         Create a new twitter API connector.
 
@@ -325,20 +329,19 @@ class Twitter(TwitterCall):
 
 
         `domain` lets you change the domain you are connecting. By
-        default it's `api.twitter.com` but `search.twitter.com` may be
-        useful too.
+        default it's `api.twitter.com`.
 
         If `secure` is False you will connect with HTTP instead of
         HTTPS.
 
         `api_version` is used to set the base uri. By default it's
-        '1'. If you are using "search.twitter.com" set this to None.
+        '1.1'.
         """
         if not auth:
             auth = NoAuth()
 
         if (format not in ("json", "xml", "")):
-            raise ValueError("Unknown data format '%s'" %(format))
+            raise ValueError("Unknown data format '%s'" % (format))
 
         if api_version is _DEFAULT:
             if domain == 'api.twitter.com':