Fix weird indentation in auth.py and simple_httpclient_test.py

This commit is contained in:
Ben Darnell 2012-02-09 01:00:11 -08:00
parent c152b78448
commit 605c521390
2 changed files with 57 additions and 57 deletions

View File

@ -326,7 +326,7 @@ class OAuthMixin(object):
oauth_version=getattr(self, "_OAUTH_VERSION", "1.0a"), oauth_version=getattr(self, "_OAUTH_VERSION", "1.0a"),
) )
if "verifier" in request_token: if "verifier" in request_token:
args["oauth_verifier"] = request_token["verifier"] args["oauth_verifier"] = request_token["verifier"]
if getattr(self, "_OAUTH_VERSION", "1.0a") == "1.0a": if getattr(self, "_OAUTH_VERSION", "1.0a") == "1.0a":
signature = _oauth10a_signature(consumer_token, "GET", url, args, signature = _oauth10a_signature(consumer_token, "GET", url, args,
@ -954,68 +954,68 @@ class FacebookGraphMixin(OAuth2Mixin):
def get_authenticated_user(self, redirect_uri, client_id, client_secret, def get_authenticated_user(self, redirect_uri, client_id, client_secret,
code, callback, extra_fields=None): code, callback, extra_fields=None):
"""Handles the login for the Facebook user, returning a user object. """Handles the login for the Facebook user, returning a user object.
Example usage:: Example usage::
class FacebookGraphLoginHandler(LoginHandler, tornado.auth.FacebookGraphMixin): class FacebookGraphLoginHandler(LoginHandler, tornado.auth.FacebookGraphMixin):
@tornado.web.asynchronous @tornado.web.asynchronous
def get(self): def get(self):
if self.get_argument("code", False): if self.get_argument("code", False):
self.get_authenticated_user( self.get_authenticated_user(
redirect_uri='/auth/facebookgraph/', redirect_uri='/auth/facebookgraph/',
client_id=self.settings["facebook_api_key"], client_id=self.settings["facebook_api_key"],
client_secret=self.settings["facebook_secret"], client_secret=self.settings["facebook_secret"],
code=self.get_argument("code"), code=self.get_argument("code"),
callback=self.async_callback( callback=self.async_callback(
self._on_login)) self._on_login))
return return
self.authorize_redirect(redirect_uri='/auth/facebookgraph/', self.authorize_redirect(redirect_uri='/auth/facebookgraph/',
client_id=self.settings["facebook_api_key"], client_id=self.settings["facebook_api_key"],
extra_params={"scope": "read_stream,offline_access"}) extra_params={"scope": "read_stream,offline_access"})
def _on_login(self, user): def _on_login(self, user):
logging.error(user) logging.error(user)
self.finish() self.finish()
""" """
http = httpclient.AsyncHTTPClient() http = httpclient.AsyncHTTPClient()
args = { args = {
"redirect_uri": redirect_uri, "redirect_uri": redirect_uri,
"code": code, "code": code,
"client_id": client_id, "client_id": client_id,
"client_secret": client_secret, "client_secret": client_secret,
} }
fields = set(['id', 'name', 'first_name', 'last_name', fields = set(['id', 'name', 'first_name', 'last_name',
'locale', 'picture', 'link']) 'locale', 'picture', 'link'])
if extra_fields: if extra_fields:
fields.update(extra_fields) fields.update(extra_fields)
http.fetch(self._oauth_request_token_url(**args), http.fetch(self._oauth_request_token_url(**args),
self.async_callback(self._on_access_token, redirect_uri, client_id, self.async_callback(self._on_access_token, redirect_uri, client_id,
client_secret, callback, fields)) client_secret, callback, fields))
def _on_access_token(self, redirect_uri, client_id, client_secret, def _on_access_token(self, redirect_uri, client_id, client_secret,
callback, fields, response): callback, fields, response):
if response.error: if response.error:
logging.warning('Facebook auth error: %s' % str(response)) logging.warning('Facebook auth error: %s' % str(response))
callback(None) callback(None)
return return
args = escape.parse_qs_bytes(escape.native_str(response.body)) args = escape.parse_qs_bytes(escape.native_str(response.body))
session = { session = {
"access_token": args["access_token"][-1], "access_token": args["access_token"][-1],
"expires": args.get("expires") "expires": args.get("expires")
} }
self.facebook_request( self.facebook_request(
path="/me", path="/me",
callback=self.async_callback( callback=self.async_callback(
self._on_get_user_info, callback, session, fields), self._on_get_user_info, callback, session, fields),
access_token=session["access_token"], access_token=session["access_token"],
fields=",".join(fields) fields=",".join(fields)
) )
def _on_get_user_info(self, callback, session, fields, user): def _on_get_user_info(self, callback, session, fields, user):
if user is None: if user is None:

View File

@ -174,12 +174,12 @@ class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase):
self.assertTrue(response.headers["Location"].endswith("/countdown/1")) self.assertTrue(response.headers["Location"].endswith("/countdown/1"))
def test_303_redirect(self): def test_303_redirect(self):
response = self.fetch("/303_post", method="POST", body="blah") response = self.fetch("/303_post", method="POST", body="blah")
self.assertEqual(200, response.code) self.assertEqual(200, response.code)
self.assertTrue(response.request.url.endswith("/303_post")) self.assertTrue(response.request.url.endswith("/303_post"))
self.assertTrue(response.effective_url.endswith("/303_get")) self.assertTrue(response.effective_url.endswith("/303_get"))
#request is the original request, is a POST still #request is the original request, is a POST still
self.assertEqual("POST", response.request.method) self.assertEqual("POST", response.request.method)
def test_request_timeout(self): def test_request_timeout(self):
response = self.fetch('/trigger?wake=false', request_timeout=0.1) response = self.fetch('/trigger?wake=false', request_timeout=0.1)