Trying to make this merge-able.

* We don't need RequestException anymore.

* I changed TwythonError to raise TwythonRateLimitError instead of
TwythonAPIError since TwythonRateLimitError is more verbose and in the
belief we should deprecate TwythonAPILimit and ultimately remove it in
2.0

* And I updated the version to 1.7.0 -- I feel like development as far
as versioning seems like it's going fast, but versioning is versioning
and I'm following Twitter's rhythm of versioning
<major>.<minor>.<bugfix>, minor changing when minor features or
significant fixes have been added. In this case, TwythonRateLimitError
should start being caught in place of TwythonAPILimit
This commit is contained in:
Michael Helmick 2012-04-12 11:44:27 -04:00
parent 3f26325ddb
commit a42570b685
2 changed files with 24 additions and 23 deletions

View file

@ -4,7 +4,7 @@ from setuptools import setup
from setuptools import find_packages from setuptools import find_packages
__author__ = 'Ryan McGrath <ryan@venodesigns.net>' __author__ = 'Ryan McGrath <ryan@venodesigns.net>'
__version__ = '1.6.0' __version__ = '1.7.0'
setup( setup(
# Basic package information. # Basic package information.

View file

@ -9,14 +9,13 @@
""" """
__author__ = "Ryan McGrath <ryan@venodesigns.net>" __author__ = "Ryan McGrath <ryan@venodesigns.net>"
__version__ = "1.6.0" __version__ = "1.7.0"
import urllib import urllib
import re import re
import time import time
import requests import requests
from requests.exceptions import RequestException
from oauth_hook import OAuthHook from oauth_hook import OAuthHook
import oauth2 as oauth import oauth2 as oauth
@ -61,6 +60,7 @@ class TwythonError(AttributeError):
""" """
def __init__(self, msg, error_code=None, retry_after=None): def __init__(self, msg, error_code=None, retry_after=None):
self.msg = msg self.msg = msg
self.error_code = error_code
if error_code is not None and error_code in twitter_http_status_codes: if error_code is not None and error_code in twitter_http_status_codes:
self.msg = '%s: %s -- %s' % \ self.msg = '%s: %s -- %s' % \
@ -69,28 +69,29 @@ class TwythonError(AttributeError):
self.msg) self.msg)
if error_code == 400 or error_code == 420: if error_code == 400 or error_code == 420:
raise TwythonRateLimitError(self.msg, retry_after=retry_after) raise TwythonRateLimitError(self.msg,
error_code,
retry_after=retry_after)
def __str__(self): def __str__(self):
return repr(self.msg) return repr(self.msg)
class TwythonAuthError(TwythonError): class TwythonAuthError(TwythonError):
""" Raised when you try to access a protected resource and it fails due to
some issue with your authentication.
""" """
Raised when you try to access a protected resource and it fails due to some issue with def __init__(self, msg, error_code=None):
your authentication.
"""
def __init__(self, msg):
self.msg = msg self.msg = msg
self.error_code = error_code
def __str__(self): def __str__(self):
return repr(self.msg) return repr(self.msg)
class TwythonRateLimitError(TwythonError): class TwythonRateLimitError(TwythonError):
""" """ Raised when you've hit a rate limit.
Raised when you've hit a rate limit. retry_wait_seconds is the number of seconds to retry_wait_seconds is the number of seconds to wait before trying again.
wait before trying again.
""" """
def __init__(self, msg, error_code, retry_after=None): def __init__(self, msg, error_code, retry_after=None):
retry_after = int(retry_after) retry_after = int(retry_after)
@ -107,40 +108,40 @@ class TwythonRateLimitError(TwythonError):
class TwythonAPILimit(TwythonError): class TwythonAPILimit(TwythonError):
""" """ Raised when you've hit an API limit. Try to avoid these, read the API
Raised when you've hit an API limit. Try to avoid these, read the API
docs if you're running into issues here, Twython does not concern itself with docs if you're running into issues here, Twython does not concern itself with
this matter beyond telling you that you've done goofed. this matter beyond telling you that you've done goofed.
""" """
def __init__(self, msg): def __init__(self, msg, error_code=None):
self.msg = msg self.msg = '%s\n Notice: APILimit is deprecated and soon to be removed, catch on TwythonRateLimitLimit instead!' % msg
self.error_code = error_code
def __str__(self): def __str__(self):
return repr(self.msg) return repr(self.msg)
class APILimit(TwythonError): class APILimit(TwythonError):
""" """ Raised when you've hit an API limit. Try to avoid these, read the API
Raised when you've hit an API limit. Try to avoid these, read the API
docs if you're running into issues here, Twython does not concern itself with docs if you're running into issues here, Twython does not concern itself with
this matter beyond telling you that you've done goofed. this matter beyond telling you that you've done goofed.
DEPRECATED, import and catch TwythonAPILimit instead. DEPRECATED, import and catch TwythonAPILimit instead.
""" """
def __init__(self, msg): def __init__(self, msg, error_code=None):
self.msg = '%s\n Notice: APILimit is deprecated and soon to be removed, catch on TwythonAPILimit instead!' % msg self.msg = '%s\n Notice: APILimit is deprecated and soon to be removed, catch on TwythonRateLimitLimit instead!' % msg
self.error_code = error_code
def __str__(self): def __str__(self):
return repr(self.msg) return repr(self.msg)
class AuthError(TwythonError): class AuthError(TwythonError):
""" """ Raised when you try to access a protected resource and it fails due to some issue with
Raised when you try to access a protected resource and it fails due to some issue with
your authentication. your authentication.
""" """
def __init__(self, msg): def __init__(self, msg, error_code=None):
self.msg = '%s\n Notice: AuthError is deprecated and soon to be removed, catch on TwythonAuthError instead!' % msg self.msg = '%s\n Notice: AuthError is deprecated and soon to be removed, catch on TwythonAuthError instead!' % msg
self.error_code = error_code
def __str__(self): def __str__(self):
return repr(self.msg) return repr(self.msg)
@ -414,7 +415,7 @@ class Twython(object):
if request.status_code in [301, 201, 200]: if request.status_code in [301, 201, 200]:
return request.text return request.text
else: else:
raise TwythonError('shortenURL() failed with a %s error code.' % request.status_code) raise TwythonError('shortenURL() failed with a %s error code.' % request.status_code , request.status_code )
@staticmethod @staticmethod
def constructApiURL(base_url, params): def constructApiURL(base_url, params):