From: Ben Darnell Date: Thu, 9 Feb 2012 09:00:11 +0000 (-0800) Subject: Fix weird indentation in auth.py and simple_httpclient_test.py X-Git-Tag: v2.3.0~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=605c521390bba84274b22da3c5b8cda8d984e717;p=thirdparty%2Ftornado.git Fix weird indentation in auth.py and simple_httpclient_test.py --- diff --git a/tornado/auth.py b/tornado/auth.py index 65be566bd..21c8ac880 100644 --- a/tornado/auth.py +++ b/tornado/auth.py @@ -326,7 +326,7 @@ class OAuthMixin(object): oauth_version=getattr(self, "_OAUTH_VERSION", "1.0a"), ) 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": 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, 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:: + + class FacebookGraphLoginHandler(LoginHandler, tornado.auth.FacebookGraphMixin): + @tornado.web.asynchronous + def get(self): + if self.get_argument("code", False): + self.get_authenticated_user( + redirect_uri='/auth/facebookgraph/', + client_id=self.settings["facebook_api_key"], + client_secret=self.settings["facebook_secret"], + code=self.get_argument("code"), + callback=self.async_callback( + self._on_login)) + return + self.authorize_redirect(redirect_uri='/auth/facebookgraph/', + client_id=self.settings["facebook_api_key"], + extra_params={"scope": "read_stream,offline_access"}) + + def _on_login(self, user): + logging.error(user) + self.finish() - Example usage:: + """ + http = httpclient.AsyncHTTPClient() + args = { + "redirect_uri": redirect_uri, + "code": code, + "client_id": client_id, + "client_secret": client_secret, + } - class FacebookGraphLoginHandler(LoginHandler, tornado.auth.FacebookGraphMixin): - @tornado.web.asynchronous - def get(self): - if self.get_argument("code", False): - self.get_authenticated_user( - redirect_uri='/auth/facebookgraph/', - client_id=self.settings["facebook_api_key"], - client_secret=self.settings["facebook_secret"], - code=self.get_argument("code"), - callback=self.async_callback( - self._on_login)) - return - self.authorize_redirect(redirect_uri='/auth/facebookgraph/', - client_id=self.settings["facebook_api_key"], - extra_params={"scope": "read_stream,offline_access"}) - - def _on_login(self, user): - logging.error(user) - self.finish() - - """ - http = httpclient.AsyncHTTPClient() - args = { - "redirect_uri": redirect_uri, - "code": code, - "client_id": client_id, - "client_secret": client_secret, - } - - fields = set(['id', 'name', 'first_name', 'last_name', - 'locale', 'picture', 'link']) - if extra_fields: + fields = set(['id', 'name', 'first_name', 'last_name', + 'locale', 'picture', 'link']) + if extra_fields: fields.update(extra_fields) - http.fetch(self._oauth_request_token_url(**args), - self.async_callback(self._on_access_token, redirect_uri, client_id, - client_secret, callback, fields)) + http.fetch(self._oauth_request_token_url(**args), + self.async_callback(self._on_access_token, redirect_uri, client_id, + client_secret, callback, fields)) def _on_access_token(self, redirect_uri, client_id, client_secret, callback, fields, response): - if response.error: - logging.warning('Facebook auth error: %s' % str(response)) - callback(None) - return - - args = escape.parse_qs_bytes(escape.native_str(response.body)) - session = { - "access_token": args["access_token"][-1], - "expires": args.get("expires") - } - - self.facebook_request( - path="/me", - callback=self.async_callback( - self._on_get_user_info, callback, session, fields), - access_token=session["access_token"], - fields=",".join(fields) - ) + if response.error: + logging.warning('Facebook auth error: %s' % str(response)) + callback(None) + return + + args = escape.parse_qs_bytes(escape.native_str(response.body)) + session = { + "access_token": args["access_token"][-1], + "expires": args.get("expires") + } + + self.facebook_request( + path="/me", + callback=self.async_callback( + self._on_get_user_info, callback, session, fields), + access_token=session["access_token"], + fields=",".join(fields) + ) def _on_get_user_info(self, callback, session, fields, user): if user is None: diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index 0f5d3151f..1d26193fa 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -174,12 +174,12 @@ class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase): self.assertTrue(response.headers["Location"].endswith("/countdown/1")) def test_303_redirect(self): - response = self.fetch("/303_post", method="POST", body="blah") - self.assertEqual(200, response.code) - self.assertTrue(response.request.url.endswith("/303_post")) - self.assertTrue(response.effective_url.endswith("/303_get")) - #request is the original request, is a POST still - self.assertEqual("POST", response.request.method) + response = self.fetch("/303_post", method="POST", body="blah") + self.assertEqual(200, response.code) + self.assertTrue(response.request.url.endswith("/303_post")) + self.assertTrue(response.effective_url.endswith("/303_get")) + #request is the original request, is a POST still + self.assertEqual("POST", response.request.method) def test_request_timeout(self): response = self.fetch('/trigger?wake=false', request_timeout=0.1)