From 25ad097ddd485e55a5eb269036ef65c3be594c50 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mat=C3=ADas=20Aguirre?= Date: Thu, 1 Mar 2012 13:42:58 -0200 Subject: [PATCH] PEP8 --- contrib/tests/runtests.py | 4 +++- contrib/tests/test_core.py | 15 ++++++++----- doc/conf.py | 26 ++++++++++++---------- example/app/models.py | 1 + example/app/pipeline.py | 5 +++-- example/app/views.py | 3 +++ example/manage.py | 9 ++++++-- setup.py | 1 + social_auth/backends/__init__.py | 8 ++++--- social_auth/backends/contrib/fitbit.py | 2 +- social_auth/backends/contrib/foursquare.py | 2 +- social_auth/backends/contrib/gae.py | 2 +- social_auth/backends/contrib/github.py | 1 + social_auth/backends/contrib/instagram.py | 2 +- social_auth/backends/facebook.py | 6 ++--- social_auth/backends/google.py | 5 ++--- social_auth/context_processors.py | 2 +- social_auth/signals.py | 3 ++- social_auth/store.py | 2 +- social_auth/tests/facebook.py | 4 +++- social_auth/tests/google.py | 4 +++- social_auth/utils.py | 13 +++++------ social_auth/views.py | 3 ++- 23 files changed, 75 insertions(+), 48 deletions(-) diff --git a/contrib/tests/runtests.py b/contrib/tests/runtests.py index 8e06539..19dc425 100755 --- a/contrib/tests/runtests.py +++ b/contrib/tests/runtests.py @@ -1,8 +1,10 @@ #!/usr/bin/env python -import os, sys +import os +import sys from os.path import dirname, abspath + os.environ['DJANGO_SETTINGS_MODULE'] = 'test_settings' parent = dirname(dirname(dirname(abspath(__file__)))) diff --git a/contrib/tests/test_core.py b/contrib/tests/test_core.py index b1fb590..9f2a60e 100644 --- a/contrib/tests/test_core.py +++ b/contrib/tests/test_core.py @@ -20,7 +20,8 @@ class BackendsTest(TestCase): def test_twitter_backend(self): # We grab the Twitter testing user details from settings file TEST_TWITTER_USER = getattr(settings, 'TEST_TWITTER_USER', None) - TEST_TWITTER_PASSWORD = getattr(settings, 'TEST_TWITTER_PASSWORD', None) + TEST_TWITTER_PASSWORD = getattr(settings, 'TEST_TWITTER_PASSWORD', + None) self.assertTrue(TEST_TWITTER_USER) self.assertTrue(TEST_TWITTER_PASSWORD) @@ -107,7 +108,8 @@ class BackendsTest(TestCase): def test_facebook_backend(self): TEST_FACEBOOK_USER = getattr(settings, 'TEST_FACEBOOK_USER', None) - TEST_FACEBOOK_PASSWORD = getattr(settings, 'TEST_FACEBOOK_PASSWORD', None) + TEST_FACEBOOK_PASSWORD = getattr(settings, 'TEST_FACEBOOK_PASSWORD', + None) self.assertTrue(TEST_FACEBOOK_USER) self.assertTrue(TEST_FACEBOOK_PASSWORD) @@ -135,17 +137,20 @@ class BackendsTest(TestCase): def test_linkedin_backend(self): TEST_LINKEDIN_USER = getattr(settings, 'TEST_LINKEDIN_USER', None) - TEST_LINKEDIN_PASSWORD = getattr(settings, 'TEST_LINKEDIN_PASSWORD', None) + TEST_LINKEDIN_PASSWORD = getattr(settings, 'TEST_LINKEDIN_PASSWORD', + None) self.assertTrue(TEST_LINKEDIN_USER) self.assertTrue(TEST_LINKEDIN_PASSWORD) self.driver.get(self.url('/login/linkedin/')) # We log in - username_field = self.driver.find_element_by_id('session_key-oauthAuthorizeForm') + username_field = self.driver.find_element_by_id( + 'session_key-oauthAuthorizeForm') username_field.send_keys(TEST_LINKEDIN_USER) - password_field = self.driver.find_element_by_id('session_password-oauthAuthorizeForm') + password_field = self.driver.find_element_by_id( + 'session_password-oauthAuthorizeForm') password_field.send_keys(TEST_LINKEDIN_PASSWORD) password_field.submit() diff --git a/doc/conf.py b/doc/conf.py index 8e7a92c..effb854 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -3,7 +3,8 @@ # Django Social Auth documentation build configuration file, created by # sphinx-quickstart on Sun Mar 20 23:07:14 2011. # -# This file is execfile()d with the current directory set to its containing dir. +# This file is execfile()d with the current directory set to its containing +# dir. # # Note that not all possible configuration values are present in this # autogenerated file. @@ -11,21 +12,20 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os - # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) -# -- General configuration ----------------------------------------------------- +# -- General configuration ---------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' -# Add any Sphinx extension module names here, as strings. They can be extensions -# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.viewcode'] +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', + 'sphinx.ext.todo', 'sphinx.ext.viewcode'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -66,7 +66,8 @@ release = '0.6.0' # directories to ignore when looking for source files. exclude_patterns = ['_build'] -# The reST default role (used for this markup: `text`) to use for all documents. +# The reST default role (used for this markup: `text`) to use for all +# documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. @@ -87,7 +88,7 @@ pygments_style = 'sphinx' #modindex_common_prefix = [] -# -- Options for HTML output --------------------------------------------------- +# -- Options for HTML output -------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. @@ -167,7 +168,7 @@ html_static_path = [] htmlhelp_basename = 'DjangoSocialAuthdoc' -# -- Options for LaTeX output -------------------------------------------------- +# -- Options for LaTeX output ------------------------------------------------- # The paper size ('letter' or 'a4'). #latex_paper_size = 'letter' @@ -176,7 +177,8 @@ htmlhelp_basename = 'DjangoSocialAuthdoc' #latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, documentclass [howto/manual]). +# (source start file, target name, title, author, documentclass +# [howto/manual]). latex_documents = [ ('index', 'DjangoSocialAuth.tex', u'Django Social Auth Documentation', u'Matías Aguirre', 'manual'), @@ -206,7 +208,7 @@ latex_documents = [ #latex_domain_indices = True -# -- Options for manual page output -------------------------------------------- +# -- Options for manual page output ------------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). diff --git a/example/app/models.py b/example/app/models.py index 583fa14..17765bd 100644 --- a/example/app/models.py +++ b/example/app/models.py @@ -20,6 +20,7 @@ class CustomUser(models.Model): from social_auth.signals import pre_update from social_auth.backends.facebook import FacebookBackend + def facebook_extra_values(sender, user, response, details, **kwargs): return False diff --git a/example/app/pipeline.py b/example/app/pipeline.py index 0d81b17..b10a665 100644 --- a/example/app/pipeline.py +++ b/example/app/pipeline.py @@ -6,9 +6,10 @@ def username(request, *args, **kwargs): username = kwargs['user'].username else: username = request.session.get('saved_username') - return { 'username': username } + return {'username': username} def redirect_to_form(*args, **kwargs): - if not kwargs['request'].session.get('saved_username') and kwargs.get('user') is None: + if not kwargs['request'].session.get('saved_username') and \ + kwargs.get('user') is None: return HttpResponseRedirect('/form/') diff --git a/example/app/views.py b/example/app/views.py index ef457fc..3c10064 100644 --- a/example/app/views.py +++ b/example/app/views.py @@ -17,6 +17,7 @@ def home(request): return render_to_response('home.html', {'version': version}, RequestContext(request)) + @login_required def done(request): """Login complete view, displays user data""" @@ -26,6 +27,7 @@ def done(request): } return render_to_response('done.html', ctx, RequestContext(request)) + def error(request): """Error view""" messages = get_messages(request) @@ -33,6 +35,7 @@ def error(request): 'messages': messages}, RequestContext(request)) + def logout(request): """Logs out user""" auth_logout(request) diff --git a/example/manage.py b/example/manage.py index 5e78ea9..0eff70a 100755 --- a/example/manage.py +++ b/example/manage.py @@ -1,10 +1,15 @@ #!/usr/bin/env python from django.core.management import execute_manager try: - import settings # Assumed to be in the same directory. + import settings # Assumed to be in the same directory. except ImportError: import sys - sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) + sys.stderr.write(("Error: Can't find the file 'settings.py' in the " + + "directory containing %r. It appears you've " + "customized things.\nYou'll have to run " + "django-admin.py, passing it your settings module.\n" + + "(If the file settings.py does indeed exist, it's " + + "causing an ImportError somehow.)\n") % __file__) sys.exit(1) if __name__ == "__main__": diff --git a/setup.py b/setup.py index 9d6f9b2..8001d48 100644 --- a/setup.py +++ b/setup.py @@ -15,6 +15,7 @@ implements a common interface to define new authentication providers from third parties. """ + def long_description(): """Return long description from README.rst if it's present because it doesn't get installed.""" diff --git a/social_auth/backends/__init__.py b/social_auth/backends/__init__.py index 79469a8..e9c0d7c 100644 --- a/social_auth/backends/__init__.py +++ b/social_auth/backends/__init__.py @@ -170,7 +170,9 @@ class SocialAuthBackend(ModelBackend): raise NotImplementedError('Implement in subclass') def get_user(self, user_id): - """Return user with given ID from the User model used by this backend""" + """ + Return user with given ID from the User model used by this backend + """ try: return User.objects.get(pk=user_id) except User.DoesNotExist: @@ -349,7 +351,7 @@ class BaseAuth(object): setting is per backend and defined by: _REQUEST_TOKEN_EXTRA_ARGUMENTS. """ - backend_name = self.AUTH_BACKEND.name.upper().replace('-','_') + backend_name = self.AUTH_BACKEND.name.upper().replace('-', '_') return setting(backend_name + '_REQUEST_TOKEN_EXTRA_ARGUMENTS', {}) def auth_extra_arguments(self): @@ -357,7 +359,7 @@ class BaseAuth(object): backend and defined by: _AUTH_EXTRA_ARGUMENTS. """ - backend_name = self.AUTH_BACKEND.name.upper().replace('-','_') + backend_name = self.AUTH_BACKEND.name.upper().replace('-', '_') return setting(backend_name + '_AUTH_EXTRA_ARGUMENTS', {}) @property diff --git a/social_auth/backends/contrib/fitbit.py b/social_auth/backends/contrib/fitbit.py index 031f91a..4c7539c 100644 --- a/social_auth/backends/contrib/fitbit.py +++ b/social_auth/backends/contrib/fitbit.py @@ -10,7 +10,7 @@ extra_data field, check OAuthBackend class for details on how to extend it. """ try: from urlparse import parse_qs - parse_qs # placate pyflakes + parse_qs # placate pyflakes except ImportError: # fall back for Python 2.5 from cgi import parse_qs diff --git a/social_auth/backends/contrib/foursquare.py b/social_auth/backends/contrib/foursquare.py index 0ba718a..369bd6b 100644 --- a/social_auth/backends/contrib/foursquare.py +++ b/social_auth/backends/contrib/foursquare.py @@ -40,7 +40,7 @@ class FoursquareAuth(BaseOAuth2): def user_data(self, access_token): """Loads user data from service""" - params = {'oauth_token': access_token,} + params = {'oauth_token': access_token} url = FOURSQUARE_CHECK_AUTH + '?' + urllib.urlencode(params) try: return simplejson.load(urllib.urlopen(url)) diff --git a/social_auth/backends/contrib/gae.py b/social_auth/backends/contrib/gae.py index 72640f5..38bfdb6 100644 --- a/social_auth/backends/contrib/gae.py +++ b/social_auth/backends/contrib/gae.py @@ -49,7 +49,7 @@ class GAEAuth(BaseAuth): # Setting these two are necessary for BaseAuth.authenticate to work kwargs.update({ - 'response' : '', + 'response': '', self.AUTH_BACKEND.name: True }) return authenticate(*args, **kwargs) diff --git a/social_auth/backends/contrib/github.py b/social_auth/backends/contrib/github.py index c80c7c0..bd0b960 100644 --- a/social_auth/backends/contrib/github.py +++ b/social_auth/backends/contrib/github.py @@ -43,6 +43,7 @@ class GithubBackend(OAuthBackend): 'email': response.get('email') or '', 'first_name': response.get('name')} + class GithubAuth(BaseOAuth): """Github OAuth mechanism""" AUTH_BACKEND = GithubBackend diff --git a/social_auth/backends/contrib/instagram.py b/social_auth/backends/contrib/instagram.py index e2fba7d..a40c0ee 100644 --- a/social_auth/backends/contrib/instagram.py +++ b/social_auth/backends/contrib/instagram.py @@ -40,7 +40,7 @@ class InstagramAuth(BaseOAuth2): def user_data(self, access_token): """Loads user data from service""" - params = {'access_token': access_token,} + params = {'access_token': access_token} url = INSTAGRAM_CHECK_AUTH + '?' + urllib.urlencode(params) try: return simplejson.load(urllib.urlopen(url)) diff --git a/social_auth/backends/facebook.py b/social_auth/backends/facebook.py index 9b9e79c..9943e47 100644 --- a/social_auth/backends/facebook.py +++ b/social_auth/backends/facebook.py @@ -109,9 +109,9 @@ class FacebookAuth(BaseOAuth2): if 'expires' in response: data['expires'] = response['expires'][0] - kwargs.update({ 'auth': self, - 'response': data, - self.AUTH_BACKEND.name: True }) + kwargs.update({'auth': self, + 'response': data, + self.AUTH_BACKEND.name: True}) return authenticate(*args, **kwargs) @classmethod diff --git a/social_auth/backends/google.py b/social_auth/backends/google.py index d926f55..c596c49 100644 --- a/social_auth/backends/google.py +++ b/social_auth/backends/google.py @@ -189,9 +189,8 @@ def googleapis_email(url, params): Parameters must be passed in queryset and Authorization header as described on Google OAuth documentation at: - http://groups.google.com/group/oauth/browse_thread/thread/d15add9beb418ebc - and: - http://code.google.com/apis/accounts/docs/OAuth2.html#CallingAnAPI + http://groups.google.com/group/oauth/browse_thread/thread/d15add9beb418ebc + and: http://code.google.com/apis/accounts/docs/OAuth2.html#CallingAnAPI """ request = Request(url + '?' + params, headers={'Authorization': params}) try: diff --git a/social_auth/context_processors.py b/social_auth/context_processors.py index 1355be1..1d1464e 100644 --- a/social_auth/context_processors.py +++ b/social_auth/context_processors.py @@ -22,7 +22,7 @@ def social_auth_by_type_backends(request): data['backends'] = group_backend_by_type(data['backends']) data['not_associated'] = group_backend_by_type(data['not_associated']) data['associated'] = group_backend_by_type(data['associated'], - key=lambda assoc: assoc.provider) + key=lambda assoc: assoc.provider) return {'social_auth': data} diff --git a/social_auth/signals.py b/social_auth/signals.py index 7e5db38..4ff41b8 100644 --- a/social_auth/signals.py +++ b/social_auth/signals.py @@ -19,4 +19,5 @@ pre_update = Signal(providing_args=['user', 'response', 'details']) socialauth_registered = Signal(providing_args=['user', 'response', 'details']) -socialauth_not_registered = Signal(providing_args=['uid', 'response', 'details']) +socialauth_not_registered = Signal(providing_args=['uid', 'response', + 'details']) diff --git a/social_auth/store.py b/social_auth/store.py index a1be029..30aac56 100644 --- a/social_auth/store.py +++ b/social_auth/store.py @@ -50,7 +50,7 @@ class DjangoOpenIDStore(OpenIDStore): if expired: # clear expired associations Association.objects.filter(pk__in=expired).delete() - if associations: # return most recet association + if associations: # return most recet association associations.sort(key=lambda x: x.issued, reverse=True) return associations[0] diff --git a/social_auth/tests/facebook.py b/social_auth/tests/facebook.py index 74d5b47..d0a9601 100644 --- a/social_auth/tests/facebook.py +++ b/social_auth/tests/facebook.py @@ -20,9 +20,11 @@ class FacebookTestCase(SocialAuthTestsCase): REDIRECT_RE = re.compile('window.location.replace\("(.*)"\);') + class FacebookTestLogin(FacebookTestCase): def test_login_succeful(self): - response = self.client.get(self.reverse('socialauth_begin', 'facebook')) + response = self.client.get(self.reverse('socialauth_begin', + 'facebook')) # social_auth must redirect to service page self.assertEqual(response.status_code, 302) diff --git a/social_auth/tests/google.py b/social_auth/tests/google.py index 3beb5a9..e27cf88 100644 --- a/social_auth/tests/google.py +++ b/social_auth/tests/google.py @@ -20,6 +20,7 @@ class GoogleTestCase(SocialAuthTestsCase): REDIRECT_RE = re.compile('window.location.replace\("(.*)"\);') + class GoogleOpenIdTestLogin(GoogleTestCase): SERVER_NAME = 'myapp.com' SERVER_PORT = '8000' @@ -32,7 +33,8 @@ class GoogleOpenIdTestLogin(GoogleTestCase): # Check that action and values were loaded properly self.assertTrue(parser.action) self.assertTrue(parser.values) - content = self.get_content(parser.action, parser.values, use_cookies=True) + content = self.get_content(parser.action, parser.values, + use_cookies=True) parser = FormParserByID('gaia_loginform') parser.feed(content) diff --git a/social_auth/utils.py b/social_auth/utils.py index 747ec3b..b7cebfa 100644 --- a/social_auth/utils.py +++ b/social_auth/utils.py @@ -30,9 +30,8 @@ def sanitize_redirect(host, redirect_to): """ Given the hostname and an untrusted URL to redirect to, this method tests it to make sure it isn't garbage/harmful - and returns it, else returns None. - - See http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/views.py#L36 + and returns it, else returns None, similar as how's it done + on django.contrib.auth.views. >>> print sanitize_redirect('myapp.com', None) None @@ -111,10 +110,10 @@ if not logger: def log(level, *args, **kwargs): """Small wrapper around logger functions.""" - { 'debug': logger.debug, - 'error': logger.error, - 'exception': logger.exception, - 'warn': logger.warn }[level](*args, **kwargs) + {'debug': logger.debug, + 'error': logger.error, + 'exception': logger.exception, + 'warn': logger.warn}[level](*args, **kwargs) def model_to_ctype(val): diff --git a/social_auth/views.py b/social_auth/views.py index b2fdc75..ad92fa2 100644 --- a/social_auth/views.py +++ b/social_auth/views.py @@ -214,4 +214,5 @@ def auth_complete(request, backend, user=None, *args, **kwargs): *args, **kwargs) return backend.continue_pipeline(pipeline_index=idx, *args, **kwargs) else: - return backend.auth_complete(user=user, request=request, *args, **kwargs) + return backend.auth_complete(user=user, request=request, *args, + **kwargs) -- 2.39.5