Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions socialauth/lib/oauthtwitter2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
#CONSUMER_KEY = settings.TWITTER_CONSUMER_KEY
#CONSUMER_SECRET = settings.TWITTER_CONSUMER_SECRET

def connection():
try:return connection._connection
except AttributeError:
connection._connection = httplib.HTTPSConnection(TWITTER_URL)
return connection._connection

def oauth_response(req):
connection().request(req.http_method, req.to_url())
return connection().getresponse().read()
connection = httplib.HTTPSConnection(TWITTER_URL)
connection.request(req.http_method, req.to_url())
response = connection.getresponse().read()
connection.close()
return response

class TwitterOAuthClient(oauth.OAuthClient):
def __init__(self, consumer_key, consumer_secret, request_token_url=REQUEST_TOKEN_URL, access_token_url=ACCESS_TOKEN_URL, authorization_url=AUTHORIZATION_URL):
Expand Down Expand Up @@ -67,9 +64,11 @@ def access_resource(self, oauth_request):
# via post body
# -> some protected resources
headers = {'Content-Type' :'application/x-www-form-urlencoded'}
self.connection.request('POST', RESOURCE_URL, body=oauth_request.to_postdata(), headers=headers)
response = self.connection.getresponse()
return response.read()
connection = httplib.HTTPSConnection(TWITTER_URL)
connection.request('POST', RESOURCE_URL, body=oauth_request.to_postdata(), headers=headers)
response = connection.getresponse().read()
connection.close()
return response

def run_example():

Expand Down