Added check for authentication in updateStatus(). Not sure why this was never there; ideally, I should replace all these is_autheticated calls at some point with a decorator. This commit also has a new TangoError Exception class, which updateStatus() will now raise. This should be spread throughout the library in the coming week, when I have a chance to hit these two issues. (Note: The Python 3 version of Tango will most likely incur a lag of a day or so this week, in terms of receiving updates. This will hopefully be made easier in the future...

This commit is contained in:
Ryan McGrath 2009-07-06 03:02:01 -04:00
parent 716fe69e60
commit 4a910f3b80

View file

@ -24,6 +24,12 @@ try:
except ImportError: except ImportError:
print "Tango requires oauth for authentication purposes. http://oauth.googlecode.com/svn/code/python/oauth/oauth.py" print "Tango requires oauth for authentication purposes. http://oauth.googlecode.com/svn/code/python/oauth/oauth.py"
class TangoError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return repr(self.msg)
class setup: class setup:
def __init__(self, authtype = "OAuth", username = None, password = None, oauth_keys = None, debug = False): def __init__(self, authtype = "OAuth", username = None, password = None, oauth_keys = None, debug = False):
self.authtype = authtype self.authtype = authtype
@ -154,6 +160,7 @@ class setup:
print "Failed with a " + str(e.code) + " error code. Does this user hide/protect their updates? If so, you'll need to authenticate and be their friend to get their timeline." print "Failed with a " + str(e.code) + " error code. Does this user hide/protect their updates? If so, you'll need to authenticate and be their friend to get their timeline."
def updateStatus(self, status, in_reply_to_status_id = None): def updateStatus(self, status, in_reply_to_status_id = None):
if self.authenticated is True:
if len(list(status)) > 140: if len(list(status)) > 140:
print "This status message is over 140 characters, but we're gonna try it anyway. Might wanna watch this!" print "This status message is over 140 characters, but we're gonna try it anyway. Might wanna watch this!"
try: try:
@ -161,7 +168,10 @@ class setup:
except HTTPError, e: except HTTPError, e:
if self.debug is True: if self.debug is True:
print e.headers print e.headers
print "updateStatus() failed with a " + str(e.code) + " error code." raise TangoError("updateStatus() failed with a " + str(e.code) + "error code.")
#print "updateStatus() failed with a " + str(e.code) + " error code."
else:
raise TangoError("updateStatus() requires you to be authenticated.")
def destroyStatus(self, id): def destroyStatus(self, id):
if self.authenticated is True: if self.authenticated is True: