Resolve lines over 80 characters

This commit is contained in:
Pat Ferate
2016-07-08 09:10:16 -07:00
parent 9f9dbc22f1
commit 5ef8bb0950
8 changed files with 41 additions and 27 deletions

View File

@@ -257,8 +257,8 @@ class Credentials(object):
strip: array, An array of names of members to exclude from the
JSON.
to_serialize: dict, (Optional) The properties for this object
that will be serialized. This allows callers to modify
before serializing.
that will be serialized. This allows callers to
modify before serializing.
Returns:
string, a JSON representation of this instance, suitable to pass to
@@ -357,7 +357,8 @@ class Storage(object):
Args:
lock: An optional threading.Lock-like object. Must implement at
least acquire() and release(). Does not need to be re-entrant.
least acquire() and release(). Does not need to be
re-entrant.
"""
self._lock = lock
@@ -2209,7 +2210,8 @@ def flow_from_clientsecrets(filename, scope, redirect_uri=None,
except clientsecrets.InvalidClientSecretsError as e:
if message is not None:
if e.args:
message = 'The client secrets were invalid: \n{0}\n{1}'.format(e, message)
message = ('The client secrets were invalid: '
'\n{0}\n{1}'.format(e, message))
sys.exit(message)
else:
raise

View File

@@ -15,10 +15,10 @@
"""Utilities for the Django web framework
Provides Django views and helpers the make using the OAuth2 web server
flow easier. It includes an ``oauth_required`` decorator to automatically ensure
that user credentials are available, and an ``oauth_enabled`` decorator to check
if the user has authorized, and helper shortcuts to create the authorization
URL otherwise.
flow easier. It includes an ``oauth_required`` decorator to automatically
ensure that user credentials are available, and an ``oauth_enabled`` decorator
to check if the user has authorized, and helper shortcuts to create the
authorization URL otherwise.
Only Django versions 1.8+ are supported.
@@ -89,8 +89,8 @@ Add the oauth2 routes to your application's urls.py urlpatterns.
urlpatterns += [url(r'^oauth2/', include(oauth2_urls))]
To require OAuth2 credentials for a view, use the `oauth2_required` decorator.
This creates a credentials object with an id_token, and allows you to create an
`http` object to build service clients with. These are all attached to the
This creates a credentials object with an id_token, and allows you to create
an `http` object to build service clients with. These are all attached to the
request.oauth
.. code-block:: python
@@ -202,9 +202,9 @@ def _get_oauth2_client_id_and_secret(settings_instance):
return client_id, client_secret
else:
raise exceptions.ImproperlyConfigured(
"Must specify either GOOGLE_OAUTH2_CLIENT_SECRETS_JSON, or "
" both GOOGLE_OAUTH2_CLIENT_ID and GOOGLE_OAUTH2_CLIENT_SECRET "
"in settings.py")
"Must specify either GOOGLE_OAUTH2_CLIENT_SECRETS_JSON, or "
"both GOOGLE_OAUTH2_CLIENT_ID and "
"GOOGLE_OAUTH2_CLIENT_SECRET in settings.py")
class OAuth2Settings(object):

View File

@@ -87,7 +87,8 @@ def oauth2_callback(request):
try:
server_csrf = request.session[_CSRF_KEY]
except KeyError:
return http.HttpResponseBadRequest("No existing session for this flow.")
return http.HttpResponseBadRequest(
"No existing session for this flow.")
try:
state = json.loads(encoded_state)

View File

@@ -112,7 +112,8 @@ class AppAssertionCredentials(AssertionCredentials):
"""
if self.invalid:
info = _metadata.get_service_account_info(
http_request, service_account=self.service_account_email or 'default')
http_request,
service_account=self.service_account_email or 'default')
self.invalid = False
self.service_account_email = info['email']
self.scopes = info['scopes']

View File

@@ -134,8 +134,8 @@ class ServiceAccountCredentials(AssertionCredentials):
strip: array, An array of names of members to exclude from the
JSON.
to_serialize: dict, (Optional) The properties for this object
that will be serialized. This allows callers to modify
before serializing.
that will be serialized. This allows callers to
modify before serializing.
Returns:
string, a JSON representation of this instance, suitable to pass to
@@ -507,7 +507,8 @@ class ServiceAccountCredentials(AssertionCredentials):
Returns:
ServiceAccountCredentials, a copy of the current service account
credentials with updated claims to use when obtaining access tokens.
credentials with updated claims to use when obtaining access
tokens.
"""
new_kwargs = dict(self._kwargs)
new_kwargs.update(claims)
@@ -603,7 +604,8 @@ class _JWTAccessCredentials(ServiceAccountCredentials):
h = credentials.authorize(h)
"""
request_orig = http.request
request_auth = super(_JWTAccessCredentials, self).authorize(http).request
request_auth = super(_JWTAccessCredentials,
self).authorize(http).request
# The closure that will replace 'httplib2.Http.request'.
def new_request(uri, method='GET', body=None, headers=None,
@@ -691,7 +693,8 @@ class _JWTAccessCredentials(ServiceAccountCredentials):
def _create_token(self, additional_claims=None):
now = _UTCNOW()
expiry = now + datetime.timedelta(seconds=self._MAX_TOKEN_LIFETIME_SECS)
lifetime = datetime.timedelta(seconds=self._MAX_TOKEN_LIFETIME_SECS)
expiry = now + lifetime
payload = {
'iat': _datetime_to_secs(now),
'exp': _datetime_to_secs(expiry),

View File

@@ -79,11 +79,13 @@ class AppAssertionCredentialsTests(unittest2.TestCase):
credentials.get_access_token(http=http_mock)
self.assertEqual(credentials.access_token, 'A')
self.assertTrue(credentials.access_token_expired)
get_token.assert_called_with(http_request, service_account='a@example.com')
get_token.assert_called_with(http_request,
service_account='a@example.com')
credentials.get_access_token(http=http_mock)
self.assertEqual(credentials.access_token, 'B')
self.assertFalse(credentials.access_token_expired)
get_token.assert_called_with(http_request, service_account='a@example.com')
get_token.assert_called_with(http_request,
service_account='a@example.com')
get_info.assert_not_called()
def test_refresh_token_failed_fetch(self):
@@ -125,7 +127,8 @@ class AppAssertionCredentialsTests(unittest2.TestCase):
self.assertFalse(credentials.invalid)
credentials.retrieve_scopes(http_mock)
# Assert scopes weren't refetched
metadata.assert_called_once_with(http_request, service_account='default')
metadata.assert_called_once_with(http_request,
service_account='default')
@mock.patch('oauth2client.contrib._metadata.get_service_account_info',
side_effect=httplib2.HttpLib2Error('No Such Email'))
@@ -136,7 +139,8 @@ class AppAssertionCredentialsTests(unittest2.TestCase):
with self.assertRaises(httplib2.HttpLib2Error):
credentials.retrieve_scopes(http_mock)
metadata.assert_called_once_with(http_request, service_account='b@example.com')
metadata.assert_called_once_with(http_request,
service_account='b@example.com')
def test_save_to_well_known_file(self):
import os

View File

@@ -2149,7 +2149,8 @@ class FlowFromCachedClientsecrets(unittest2.TestCase):
filename = object()
cache = object()
message = 'hi mom'
expected = 'The client secrets were invalid: \n{0}\n{1}'.format('foobar', 'hi mom')
expected = ('The client secrets were invalid: '
'\n{0}\n{1}'.format('foobar', 'hi mom'))
flow_from_clientsecrets(filename, None, cache=cache, message=message)
sys_exit.assert_called_once_with(expected)

View File

@@ -179,12 +179,14 @@ class ServiceAccountCredentialsTests(unittest2.TestCase):
for creds in (creds_from_filename, creds_from_file_contents):
self.assertIsInstance(creds, ServiceAccountCredentials)
self.assertIsNone(creds.client_id)
self.assertEqual(creds._service_account_email, service_account_email)
self.assertEqual(creds._service_account_email,
service_account_email)
self.assertIsNone(creds._private_key_id)
self.assertIsNone(creds._private_key_pkcs8_pem)
self.assertEqual(creds._private_key_pkcs12, key_contents)
if private_key_password is not None:
self.assertEqual(creds._private_key_password, private_key_password)
self.assertEqual(creds._private_key_password,
private_key_password)
self.assertEqual(creds._scopes, ' '.join(scopes))
self.assertEqual(creds.token_uri, token_uri)
self.assertEqual(creds.revoke_uri, revoke_uri)