Changing verifyCredentials to not auto-fire on class instantiation. No need to waste network resources; if anybody *wants* to verify credentials from this point onwards, you need to explicitly call instance.verifyCredentials(). This'll help with the upcoming change from Basic Auth...
This commit is contained in:
parent
fc6b9e1362
commit
7dbbd954b2
2 changed files with 38 additions and 10 deletions
|
|
@ -93,11 +93,7 @@ class setup:
|
||||||
self.opener = urllib2.build_opener(self.handler)
|
self.opener = urllib2.build_opener(self.handler)
|
||||||
if self.headers is not None:
|
if self.headers is not None:
|
||||||
self.opener.addheaders = [('User-agent', self.headers)]
|
self.opener.addheaders = [('User-agent', self.headers)]
|
||||||
try:
|
self.authenticated = True # Play nice, people can force-check using verifyCredentials()
|
||||||
simplejson.load(self.opener.open("http://api.twitter.com/%d/account/verify_credentials.json" % self.apiVersion))
|
|
||||||
self.authenticated = True
|
|
||||||
except HTTPError, e:
|
|
||||||
raise AuthError("Authentication failed with your provided credentials. Try again? (%s failure)" % `e.code`)
|
|
||||||
else:
|
else:
|
||||||
# Build a non-auth opener so we can allow proxy-auth and/or header swapping
|
# Build a non-auth opener so we can allow proxy-auth and/or header swapping
|
||||||
if self.proxy is not None:
|
if self.proxy is not None:
|
||||||
|
|
@ -124,7 +120,25 @@ class setup:
|
||||||
|
|
||||||
def constructApiURL(self, base_url, params):
|
def constructApiURL(self, base_url, params):
|
||||||
return base_url + "?" + "&".join(["%s=%s" %(key, value) for (key, value) in params.iteritems()])
|
return base_url + "?" + "&".join(["%s=%s" %(key, value) for (key, value) in params.iteritems()])
|
||||||
|
|
||||||
|
def verifyCredentials(self, version = None):
|
||||||
|
""" verifyCredentials(self, version = None):
|
||||||
|
|
||||||
|
Verifies the authenticity of the passed in credentials. Used to be a forced call, now made optional
|
||||||
|
(no need to waste network resources)
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
None
|
||||||
|
"""
|
||||||
|
version = version or self.apiVersion
|
||||||
|
if self.authenticated is True:
|
||||||
|
try:
|
||||||
|
simplejson.load(self.opener.open("http://api.twitter.com/%d/account/verify_credentials.json" % version))
|
||||||
|
except HTTPError, e:
|
||||||
|
raise AuthError("Authentication failed with your provided credentials. Try again? (%s failure)" % `e.code`)
|
||||||
|
else:
|
||||||
|
raise AuthError("verifyCredentials() requires you to actually, y'know, pass in credentials.")
|
||||||
|
|
||||||
def getRateLimitStatus(self, checkRequestingIP = True, version = None):
|
def getRateLimitStatus(self, checkRequestingIP = True, version = None):
|
||||||
"""getRateLimitStatus()
|
"""getRateLimitStatus()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,11 +93,7 @@ class setup:
|
||||||
self.opener = urllib.request.build_opener(self.handler)
|
self.opener = urllib.request.build_opener(self.handler)
|
||||||
if self.headers is not None:
|
if self.headers is not None:
|
||||||
self.opener.addheaders = [('User-agent', self.headers)]
|
self.opener.addheaders = [('User-agent', self.headers)]
|
||||||
try:
|
self.authenticated = True # Play nice, people can force-check using verifyCredentials()
|
||||||
simplejson.load(self.opener.open("http://api.twitter.com/%d/account/verify_credentials.json" % self.apiVersion))
|
|
||||||
self.authenticated = True
|
|
||||||
except HTTPError as e:
|
|
||||||
raise AuthError("Authentication failed with your provided credentials. Try again? (%s failure)" % repr(e.code))
|
|
||||||
else:
|
else:
|
||||||
# Build a non-auth opener so we can allow proxy-auth and/or header swapping
|
# Build a non-auth opener so we can allow proxy-auth and/or header swapping
|
||||||
if self.proxy is not None:
|
if self.proxy is not None:
|
||||||
|
|
@ -124,7 +120,25 @@ class setup:
|
||||||
|
|
||||||
def constructApiURL(self, base_url, params):
|
def constructApiURL(self, base_url, params):
|
||||||
return base_url + "?" + "&".join(["%s=%s" %(key, value) for (key, value) in params.items()])
|
return base_url + "?" + "&".join(["%s=%s" %(key, value) for (key, value) in params.items()])
|
||||||
|
|
||||||
|
def verifyCredentials(self, version = None):
|
||||||
|
""" verifyCredentials(self, version = None):
|
||||||
|
|
||||||
|
Verifies the authenticity of the passed in credentials. Used to be a forced call, now made optional
|
||||||
|
(no need to waste network resources)
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
None
|
||||||
|
"""
|
||||||
|
version = version or self.apiVersion
|
||||||
|
if self.authenticated is True:
|
||||||
|
try:
|
||||||
|
simplejson.load(self.opener.open("http://api.twitter.com/%d/account/verify_credentials.json" % version))
|
||||||
|
except HTTPError as e:
|
||||||
|
raise AuthError("Authentication failed with your provided credentials. Try again? (%s failure)" % repr(e.code))
|
||||||
|
else:
|
||||||
|
raise AuthError("verifyCredentials() requires you to actually, y'know, pass in credentials.")
|
||||||
|
|
||||||
def getRateLimitStatus(self, checkRequestingIP = True, version = None):
|
def getRateLimitStatus(self, checkRequestingIP = True, version = None):
|
||||||
"""getRateLimitStatus()
|
"""getRateLimitStatus()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue