More general PEP8 cleanup

This commit is contained in:
Pat Ferate
2016-07-08 13:31:15 -07:00
parent 8eb3aa2f95
commit 6b6c56d3ee
9 changed files with 30 additions and 30 deletions

View File

@@ -10,9 +10,17 @@ import sys
import mock
# See
# (https://read-the-docs.readthedocs.io/en/latest/faq.html#\
# i-get-import-errors-on-libraries-that-depend-on-c-modules)
# In order to load django before 1.7, we need to create a faux
# settings module and load it. This assumes django has been installed
# (but it must be for the docs to build), so if it has not already
# been installed run `pip install -r docs/requirements.txt`.
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.contrib.test_django_settings'
import django
if django.VERSION[1] < 7:
sys.path.insert(0, '.')
# See https://read-the-docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules
class Mock(mock.Mock):
@@ -61,15 +69,6 @@ release = distro.version
exclude_patterns = ['_build']
# In order to load django before 1.7, we need to create a faux
# settings module and load it. This assumes django has been installed
# (but it must be for the docs to build), so if it has not already
# been installed run `pip install -r docs/requirements.txt`.
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.contrib.test_django_settings'
import django
if django.VERSION[1] < 7:
sys.path.insert(0, '.')
# -- Options for HTML output ----------------------------------------------
# We fake our more expensive imports when building the docs.

View File

@@ -124,8 +124,9 @@ To make OAuth2 optional and provide an authorization link in your own views.
return HttpResponse("User email: %s"
% request.oauth.credentials.id_token['email'])
else:
return HttpResponse('Here is an OAuth Authorize link:
<a href="%s">Authorize</a>' % request.oauth.get_authorize_redirect())
return HttpResponse(
'Here is an OAuth Authorize link: <a href="%s">Authorize</a>'
% request.oauth.get_authorize_redirect())
If a view needs a scope not included in the default scopes specified in
the settings, you can use [incremental auth](https://developers.google.com/identity/sign-in/web/incremental-auth)
@@ -144,8 +145,9 @@ and specify additional scopes in the decorator arguments.
events = service.files().list().execute()['items']
return HttpResponse(str(events))
else:
return HttpResponse('Here is an OAuth Authorize link:
<a href="%s">Authorize</a>' % request.oauth.get_authorize_redirect())
return HttpResponse(
'Here is an OAuth Authorize link: <a href="%s">Authorize</a>'
% request.oauth.get_authorize_redirect())
To provide a callback on authorization being completed, use the

View File

@@ -36,7 +36,7 @@ def oauth_required(decorated_function=None, scopes=None, **decorator_kwargs):
developerKey=API_KEY)
events = service.events().list(
calendarId='primary').execute()['items']
return HttpResponse("email: %s , calendar: %s" % (email, str(events)))
return HttpResponse("email: %s, calendar: %s" % (email, str(events)))
:param decorated_function: View function to decorate, must have the Django
request object as the first argument

View File

@@ -604,8 +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,

View File

@@ -23,4 +23,4 @@ class MainPage(webapp2.RequestHandler):
self.response.write(get_instances())
app = webapp2.WSGIApplication([('/', MainPage),], debug=True)
app = webapp2.WSGIApplication([('/', MainPage), ], debug=True)

View File

@@ -36,8 +36,8 @@ USER_INFO = 'https://www.googleapis.com/oauth2/v2/userinfo'
def _require_environ():
if (JSON_KEY_PATH is None or P12_KEY_PATH is None or
P12_KEY_EMAIL is None or USER_KEY_PATH is None or
USER_KEY_EMAIL is None):
P12_KEY_EMAIL is None or USER_KEY_PATH is None or
USER_KEY_EMAIL is None):
raise EnvironmentError('Expected environment variables to be set:',
'OAUTH2CLIENT_TEST_JSON_KEY_PATH',
'OAUTH2CLIENT_TEST_P12_KEY_PATH',

View File

@@ -20,6 +20,9 @@ are not already installed.
from __future__ import print_function
import sys
from setuptools import find_packages
from setuptools import setup
import oauth2client
if sys.version_info < (2, 6):
print('oauth2client requires python2 version >= 2.6.', file=sys.stderr)
@@ -28,9 +31,6 @@ if (3, 1) <= sys.version_info < (3, 3):
print('oauth2client requires python3 version >= 3.3.', file=sys.stderr)
sys.exit(1)
from setuptools import find_packages
from setuptools import setup
install_requires = [
'httplib2>=0.9.1',
'pyasn1>=0.1.7',
@@ -41,7 +41,6 @@ install_requires = [
long_desc = """The oauth2client is a client library for OAuth 2.0."""
import oauth2client
version = oauth2client.__version__
setup(

View File

@@ -474,7 +474,8 @@ class FlaskOAuth2Tests(unittest2.TestCase):
# Starting the authorization flow should include the
# include_granted_scopes parameter as well as the scopes.
response = client.get(response.headers['Location'][17:])
q = urlparse.parse_qs(response.headers['Location'].split('?', 1)[1])
q = urlparse.parse_qs(
response.headers['Location'].split('?', 1)[1])
self.assertIn('include_granted_scopes', q)
self.assertEqual(
set(q['scope'][0].split(' ')),

View File

@@ -147,15 +147,14 @@ class CryptTests(unittest2.TestCase):
def test_verify_id_token_with_certs_uri_fails(self):
jwt = self._create_signed_jwt()
test_email = 'some_audience_address@testing.gserviceaccount.com'
http = HttpMockSequence([
({'status': '404'}, datafile('certs.json')),
])
with self.assertRaises(VerifyJwtTokenError):
verify_id_token(jwt,
'some_audience_address@testing.gserviceaccount.com',
http=http)
verify_id_token(jwt, test_email, http=http)
def test_verify_id_token_bad_tokens(self):
private_key = datafile('privatekey.' + self.format_)