]> jfr.im git - z_archive/twitter.git/commitdiff
Merge http://github.com/clarkbw/twitter into patches
authorMike Verdone <redacted>
Mon, 10 May 2010 19:54:55 +0000 (21:54 +0200)
committerMike Verdone <redacted>
Mon, 10 May 2010 19:54:55 +0000 (21:54 +0200)
1  2 
twitter/api.py

diff --cc twitter/api.py
index 06e9ca88eaefdf7708ca3bd55eb409a31a89344a,1bcf17bf06fbe1d01421fb32e833ae3fe37e594c..42d9e53a62aee3f00c8959ac9822805688023c1f
@@@ -22,11 -24,27 +22,26 @@@ class TwitterError(Exception)
      """
      pass
  
+ class TwitterHTTPError(TwitterError):
+     """
+     Exception thrown by the Twitter object when there is an
+     HTTP error interacting with twitter.com.
+     """
+     def __init__(self, e, uri, format, encoded_args):
+       self.e = e
+       self.uri = uri
+       self.format = format
+       self.encoded_args = encoded_args
+     def __str__(self):
+         return "Twitter sent status %i for URL: %s.%s using parameters: (%s)\ndetails: %s" %(
+                     self.e.code, self.uri, self.format, self.encoded_args, self.e.fp.read())
  class TwitterCall(object):
      def __init__(
 -        self, username, password, format, domain, uri="", agent=None,
 +        self, auth, format, domain, uri="", agent=None,
          encoded_args=None, secure=True):
 -        self.username = username
 -        self.password = password
 +        self.auth = auth
          self.format = format
          self.domain = domain
          self.uri = uri
@@@ -168,19 -183,10 +181,19 @@@ class Twitter(TwitterCall)
          credentials (email and password). Format specifies the output
          format ("json" (default) or "xml").
          """
 -        if (format not in ("json", "xml")):
 +        
 +        if email is not None or password is not None:
 +            if auth is not None:
 +                raise ValueError, "can't specify 'email' or 'password' and 'auth' params"
 +            auth = UserPassAuth(email, password)
 +
 +        if not auth:
 +            auth = NoAuth()
 +
 +        if (format not in ("json", "xml", "")):
              raise TwitterError("Unknown data format '%s'" %(format))
          TwitterCall.__init__(
 -            self, email, password, format, domain, "", agent, 
 +            self, auth, format, domain, "", agent, 
              secure=secure)
  
- __all__ = ["Twitter", "TwitterError"]
+ __all__ = ["Twitter", "TwitterError", "TwitterHTTPError"]