]> git.parisson.com Git - django-social-auth.git/commitdiff
A bit of pylint and django-lint
authorMatías Aguirre <matiasaguirre@gmail.com>
Tue, 28 Dec 2010 12:20:07 +0000 (10:20 -0200)
committerMatías Aguirre <matiasaguirre@gmail.com>
Tue, 28 Dec 2010 12:20:07 +0000 (10:20 -0200)
social_auth/auth.py
social_auth/backends.py
social_auth/conf.py
social_auth/models.py
social_auth/store.py
social_auth/views.py

index f91d55d192a9c7755c087148297ead57acfdcba5..0826af0469537138964624b7bfd1f43892eb2fdf 100644 (file)
@@ -36,15 +36,15 @@ class BaseAuth(object):
 
     def auth_url(self):
         """Must return redirect URL to auth provider"""
-        raise NotImplementedError, 'Implement in subclass'
+        raise NotImplementedError('Implement in subclass')
 
     def auth_html(self):
         """Must return login HTML content returned by provider"""
-        raise NotImplementedError, 'Implement in subclass'
+        raise NotImplementedError('Implement in subclass')
 
     def auth_complete(self, *args, **kwargs):
         """Completes loging process, must return user instance"""
-        raise NotImplementedError, 'Implement in subclass'
+        raise NotImplementedError('Implement in subclass')
 
     @property
     def uses_redirect(self):
@@ -81,16 +81,18 @@ class OpenIdAuth(BaseAuth):
         response = self.consumer().complete(dict(self.request.REQUEST.items()),
                                             self.request.build_absolute_uri())
         if not response:
-            raise ValueError, 'This is an OpenID relying party endpoint'
+            raise ValueError('This is an OpenID relying party endpoint')
         elif response.status == SUCCESS:
             kwargs.update({'response': response, self.AUTH_BACKEND.name: True})
             return authenticate(*args, **kwargs)
         elif response.status == FAILURE:
-            raise ValueError, 'OpenID authentication failed: %s' % response.message
+            raise ValueError('OpenID authentication failed: %s' % \
+                             response.message)
         elif response.status == CANCEL:
-            raise ValueError, 'Authentication cancelled'
+            raise ValueError('Authentication cancelled')
         else:
-            raise ValueError, 'Unknown OpenID response type: %r' % response.status
+            raise ValueError('Unknown OpenID response type: %r' % \
+                             response.status)
 
     def setup_request(self):
         """Setup request"""
@@ -99,9 +101,10 @@ class OpenIdAuth(BaseAuth):
         # for attribute exchange, use that.
         if openid_request.endpoint.supportsType(ax.AXMessage.ns_uri):
             fetch_request = ax.FetchRequest()
-            # Mark all attributes as required, since Google ignores optional ones
+            # Mark all attributes as required, Google ignores optional ones
             for attr, alias in AX_ATTRS:
-                fetch_request.add(ax.AttrInfo(attr, alias=alias, required=True))
+                fetch_request.add(ax.AttrInfo(attr, alias=alias,
+                                              required=True))
         else:
             fetch_request = sreg.SRegRequest(optional=SREG_ATTR)
         openid_request.addExtension(fetch_request)
@@ -119,7 +122,8 @@ class OpenIdAuth(BaseAuth):
         HTML content will be returned.
         """
         if not hasattr(self, '_uses_redirect'):
-            setattr(self, '_uses_redirect', self.openid_request().shouldSendRedirect())
+            setattr(self, '_uses_redirect',
+                    self.openid_request().shouldSendRedirect())
         return getattr(self, '_uses_redirect', True)
 
     def openid_request(self):
@@ -128,8 +132,8 @@ class OpenIdAuth(BaseAuth):
             openid_url = self.openid_url()
             try:
                 openid_request = self.consumer().begin(openid_url)
-            except DiscoveryFailure, e:
-                raise ValueError, 'OpenID discovery error: %s' % e
+            except DiscoveryFailure, err:
+                raise ValueError('OpenID discovery error: %s' % err)
             else:
                 setattr(self, '_openid_request', openid_request)
         return getattr(self, '_openid_request', None)
@@ -138,8 +142,9 @@ class OpenIdAuth(BaseAuth):
         """Return service provider URL.
         This base class is generic accepting a POST parameter that specifies
         provider URL."""
-        if self.request.method != 'POST' or OPENID_ID_FIELD not in self.request.POST:
-            raise ValueError, 'Missing openid identifier'
+        if self.request.method != 'POST' or \
+           OPENID_ID_FIELD not in self.request.POST:
+            raise ValueError('Missing openid identifier')
         return self.request.POST[OPENID_ID_FIELD]
 
 
@@ -180,11 +185,11 @@ class ConsumerBasedOAuth(BaseOAuth):
         @AUTH_BACKEND            Authorization backend related with
                                  this service
     """
-    AUTHORIZATION_URL       = ''
-    REQUEST_TOKEN_URL       = ''
-    ACCESS_TOKEN_URL        = ''
-    SERVER_URL              = ''
-    AUTH_BACKEND            = None
+    AUTHORIZATION_URL = ''
+    REQUEST_TOKEN_URL = ''
+    ACCESS_TOKEN_URL = ''
+    SERVER_URL = ''
+    AUTH_BACKEND = None
 
     def auth_url(self):
         """Returns redirect url"""
@@ -198,11 +203,11 @@ class ConsumerBasedOAuth(BaseOAuth):
         name = self.AUTH_BACKEND.name + 'unauthorized_token_name'
         unauthed_token = self.request.session.get(name)
         if not unauthed_token:
-            raise ValueError, 'Missing unauthorized token'
+            raise ValueError('Missing unauthorized token')
 
         token = OAuthToken.from_string(unauthed_token)
         if token.key != self.request.GET.get('oauth_token', 'no-token'):
-            raise ValueError, 'Incorrect tokens'
+            raise ValueError('Incorrect tokens')
 
         access_token = self.access_token(token)
         data = self.user_data(access_token)
@@ -247,7 +252,7 @@ class ConsumerBasedOAuth(BaseOAuth):
 
     def user_data(self, access_token):
         """Loads user data from service"""
-        raise NotImplementedError, 'Implement in subclass'
+        raise NotImplementedError('Implement in subclass')
 
     @property
     def connection(self):
@@ -271,16 +276,16 @@ class ConsumerBasedOAuth(BaseOAuth):
         """Return tuple with Consumer Key and Consumer Secret for current
         service provider. Must return (key, secret), order must be respected.
         """
-        raise NotImplementedError, 'Implement in subclass'
+        raise NotImplementedError('Implement in subclass')
 
 
 class OrkutAuth(ConsumerBasedOAuth):
     """Orkut OAuth authentication mechanism"""
-    AUTHORIZATION_URL       = ORKUT_AUTHORIZATION_URL
-    REQUEST_TOKEN_URL       = ORKUT_REQUEST_TOKEN_URL
-    ACCESS_TOKEN_URL        = ORKUT_ACCESS_TOKEN_URL
-    SERVER_URL              = ORKUT_SERVER
-    AUTH_BACKEND            = OrkutBackend
+    AUTHORIZATION_URL = ORKUT_AUTHORIZATION_URL
+    REQUEST_TOKEN_URL = ORKUT_REQUEST_TOKEN_URL
+    ACCESS_TOKEN_URL = ORKUT_ACCESS_TOKEN_URL
+    SERVER_URL = ORKUT_SERVER
+    AUTH_BACKEND = OrkutBackend
 
     def user_data(self, access_token):
         """Loads user data from Orkut service"""
@@ -308,11 +313,11 @@ class OrkutAuth(ConsumerBasedOAuth):
 
 class TwitterAuth(ConsumerBasedOAuth):
     """Twitter OAuth authentication mechanism"""
-    AUTHORIZATION_URL       = TWITTER_AUTHORIZATION_URL
-    REQUEST_TOKEN_URL       = TWITTER_REQUEST_TOKEN_URL
-    ACCESS_TOKEN_URL        = TWITTER_ACCESS_TOKEN_URL
-    SERVER_URL              = TWITTER_SERVER
-    AUTH_BACKEND            = TwitterBackend
+    AUTHORIZATION_URL = TWITTER_AUTHORIZATION_URL
+    REQUEST_TOKEN_URL = TWITTER_REQUEST_TOKEN_URL
+    ACCESS_TOKEN_URL = TWITTER_ACCESS_TOKEN_URL
+    SERVER_URL = TWITTER_SERVER
+    AUTH_BACKEND = TwitterBackend
 
     def user_data(self, access_token):
         """Return user data provided"""
@@ -356,13 +361,13 @@ class FacebookAuth(BaseOAuth):
             data = self.user_data(access_token)
             if data is not None:
                 if 'error' in data:
-                    raise ValueError, 'Authentication error'
+                    raise ValueError('Authentication error')
                 data['access_token'] = access_token
 
             kwargs.update({'response': data, FacebookBackend.name: True})
             return authenticate(*args, **kwargs)
         else:
-            raise ValueError, 'Authentication error'
+            raise ValueError('Authentication error')
 
     def user_data(self, access_token):
         """Loads user data from service"""
index f4ae7dde699079c00f3630656ba270071ee4b253..ee5ce5a361f308440746d0d540fbe4a798316cde 100644 (file)
@@ -21,7 +21,7 @@ User = UserSocialAuth._meta.get_field('user').rel.to
 class SocialAuthBackend(ModelBackend):
     """A django.contrib.auth backend that authenticates the user based on
     a authentication provider response"""
-    name = '' # provider name, it's stored in database
+    name = ''  # provider name, it's stored in database
 
     def authenticate(self, *args, **kwargs):
         """Authenticate user using social credentials
@@ -46,7 +46,7 @@ class SocialAuthBackend(ModelBackend):
                                                      uid=uid)
         except UserSocialAuth.DoesNotExist:
             user = kwargs.get('user')
-            if user is None: # new user
+            if user is None:  # new user
                 if not getattr(settings, 'SOCIAL_AUTH_CREATE_USERS', True):
                     return None
                 username = self.username(details)
@@ -127,7 +127,7 @@ class SocialAuthBackend(ModelBackend):
 
     def get_user_id(self, details, response):
         """Must return a unique ID from values returned on details"""
-        raise NotImplementedError, 'Implement in subclass'
+        raise NotImplementedError('Implement in subclass')
 
     def get_user_details(self, response):
         """Must return user details in a know internal struct:
@@ -137,7 +137,7 @@ class SocialAuthBackend(ModelBackend):
              'first_name': <user first name if any>,
              'last_name': <user last name if any>}
         """
-        raise NotImplementedError, 'Implement in subclass'
+        raise NotImplementedError('Implement in subclass')
 
     def get_user(self, user_id):
         """Return user instance for @user_id"""
@@ -165,7 +165,7 @@ class TwitterBackend(OAuthBackend):
     def get_user_details(self, response):
         """Return user details from Twitter account"""
         return {USERNAME: response['screen_name'],
-                'email': '', # not supplied
+                'email': '',  # not supplied
                 'fullname': response['name'],
                 'first_name': response['name'],
                 'last_name': ''}
@@ -228,7 +228,7 @@ class OpenIDBackend(SocialAuthBackend):
         if not fullname and first_name and last_name:
             fullname = first_name + ' ' + last_name
         elif fullname:
-            try: # Try to split name for django user storage
+            try:  # Try to split name for django user storage
                 first_name, last_name = fullname.rsplit(' ', 1)
             except ValueError:
                 last_name = fullname
@@ -244,6 +244,7 @@ class GoogleBackend(OpenIDBackend):
     """Google OpenID authentication backend"""
     name = 'google'
 
+
 class YahooBackend(OpenIDBackend):
     """Yahoo OpenID authentication backend"""
     name = 'yahoo'
index 91cf7a5a3a4e4a687ffc2a107effdfc620ce542e..b3b145c2732dad00e2630d6658357397142dea39 100644 (file)
@@ -1,25 +1,28 @@
 """Conf settings"""
 # Twitter configuration
-TWITTER_SERVER                  = 'api.twitter.com'
-TWITTER_REQUEST_TOKEN_URL       = 'https://%s/oauth/request_token' % TWITTER_SERVER
-TWITTER_ACCESS_TOKEN_URL        = 'https://%s/oauth/access_token' % TWITTER_SERVER
-TWITTER_AUTHORIZATION_URL       = 'http://%s/oauth/authorize' % TWITTER_SERVER
-TWITTER_CHECK_AUTH              = 'https://twitter.com/account/verify_credentials.json'
+TWITTER_SERVER = 'api.twitter.com'
+TWITTER_REQUEST_TOKEN_URL = 'https://%s/oauth/request_token' % TWITTER_SERVER
+TWITTER_ACCESS_TOKEN_URL = 'https://%s/oauth/access_token' % TWITTER_SERVER
+TWITTER_AUTHORIZATION_URL = 'http://%s/oauth/authorize' % TWITTER_SERVER
+TWITTER_CHECK_AUTH = 'https://twitter.com/account/verify_credentials.json'
 
 # Facebook configuration
-FACEBOOK_SERVER            = 'graph.facebook.com'
+FACEBOOK_SERVER = 'graph.facebook.com'
 FACEBOOK_AUTHORIZATION_URL = 'https://%s/oauth/authorize' % FACEBOOK_SERVER
-FACEBOOK_ACCESS_TOKEN_URL  = 'https://%s/oauth/access_token' % FACEBOOK_SERVER
-FACEBOOK_CHECK_AUTH        = 'https://%s/me' % FACEBOOK_SERVER
+FACEBOOK_ACCESS_TOKEN_URL = 'https://%s/oauth/access_token' % FACEBOOK_SERVER
+FACEBOOK_CHECK_AUTH = 'https://%s/me' % FACEBOOK_SERVER
 
 # Orkut configuration
-ORKUT_SERVER                  = 'www.google.com'
-ORKUT_REQUEST_TOKEN_URL       = 'https://%s/accounts/OAuthGetRequestToken' % ORKUT_SERVER
-ORKUT_ACCESS_TOKEN_URL        = 'https://%s/accounts/OAuthGetAccessToken' % ORKUT_SERVER
-ORKUT_AUTHORIZATION_URL       = 'https://%s/accounts/OAuthAuthorizeToken' % ORKUT_SERVER
-ORKUT_SCOPE                   = 'http://orkut.gmodules.com/social/'
-ORKUT_REST_ENDPOINT           = 'http://www.orkut.com/social/rpc'
-ORKUT_EXTRA_DATA              = ''
+ORKUT_SERVER = 'www.google.com'
+ORKUT_REQUEST_TOKEN_URL = 'https://%s/accounts/OAuthGetRequestToken' % \
+                            ORKUT_SERVER
+ORKUT_ACCESS_TOKEN_URL = 'https://%s/accounts/OAuthGetAccessToken' % \
+                            ORKUT_SERVER
+ORKUT_AUTHORIZATION_URL = 'https://%s/accounts/OAuthAuthorizeToken' % \
+                            ORKUT_SERVER
+ORKUT_SCOPE = 'http://orkut.gmodules.com/social/'
+ORKUT_REST_ENDPOINT = 'http://www.orkut.com/social/rpc'
+ORKUT_EXTRA_DATA = ''
 
 # OpenID configuration
 OLD_AX_ATTRS = [
@@ -36,9 +39,9 @@ AX_SCHEMA_ATTRS = [
     ('http://axschema.org/namePerson/last', 'last_name'),
     ('http://axschema.org/namePerson/friendly', 'nickname'),
 ]
-AX_ATTRS          = AX_SCHEMA_ATTRS + OLD_AX_ATTRS
-SREG_ATTR         = ['email', 'fullname', 'nickname']
-OPENID_ID_FIELD   = 'openid_identifier'
-SESSION_NAME      = 'openid'
+AX_ATTRS = AX_SCHEMA_ATTRS + OLD_AX_ATTRS
+SREG_ATTR = ['email', 'fullname', 'nickname']
+OPENID_ID_FIELD = 'openid_identifier'
+SESSION_NAME = 'openid'
 OPENID_GOOGLE_URL = 'https://www.google.com/accounts/o8/id'
-OPENID_YAHOO_URL  = 'http://yahoo.com'
+OPENID_YAHOO_URL = 'http://yahoo.com'
index 2008dafbfb88c28abbb816ae0dc6415bd9c2b875..001993e751e0eaee5a1691777aded4baceb33c1b 100644 (file)
@@ -20,7 +20,7 @@ RECOMMENDED_METHODS = ('is_authenticated',)
 
 if getattr(settings, 'SOCIAL_AUTH_USER_MODEL', None):
     User = models.get_model(*settings.SOCIAL_AUTH_USER_MODEL.split('.'))
-    missing = list(set(RECOMMENDED_FIELDS) - 
+    missing = list(set(RECOMMENDED_FIELDS) -
                    set(User._meta.get_all_field_names())) + \
               [name for name in RECOMMENDED_METHODS
                       if not callable(getattr(User, name, None))]
@@ -38,14 +38,14 @@ class UserSocialAuth(models.Model):
     uid = models.CharField(max_length=255)
     extra_data = models.TextField(default='', blank=True)
 
-    def __unicode__(self):
-        """Return associated user unicode representation"""
-        return unicode(self.user)
-
     class Meta:
         """Meta data"""
         unique_together = ('provider', 'uid')
 
+    def __unicode__(self):
+        """Return associated user unicode representation"""
+        return unicode(self.user)
+
 
 class Nonce(models.Model):
     """One use numbers"""
@@ -58,7 +58,7 @@ class Association(models.Model):
     """OpenId account association"""
     server_url = models.TextField()
     handle = models.CharField(max_length=255)
-    secret = models.CharField(max_length=255) # Stored base64 encoded
+    secret = models.CharField(max_length=255)  # Stored base64 encoded
     issued = models.IntegerField()
     lifetime = models.IntegerField()
     assoc_type = models.CharField(max_length=64)
index faab9617e6eb8c578502ecf61e79842f091b0d25..142428934842a70f4a242f760468a47ccb528ea1 100644 (file)
@@ -14,7 +14,7 @@ class DjangoOpenIDStore(OpenIDStore):
     def __init__(self):
         """Init method"""
         super(DjangoOpenIDStore, self).__init__()
-        self.max_nonce_age = 6 * 60 * 60 # Six hours
+        self.max_nonce_age = 6 * 60 * 60  # Six hours
 
     def storeAssociation(self, server_url, association):
         """Store new assocition if doesn't exist"""
@@ -47,7 +47,7 @@ class DjangoOpenIDStore(OpenIDStore):
             else:
                 associations.append(association)
 
-        if expired: # clear expired associations
+        if expired:  # clear expired associations
             Association.objects.filter(pk__in=expired).delete()
 
         if associations:
index c0e8500d13ff48ab128b77a793a85960481d9dd2..1c1d8a9eec06f437f70381b4372c348282929022 100644 (file)
@@ -23,9 +23,10 @@ BACKENDS = {
 
 def auth(request, backend):
     """Start authentication process"""
-    complete = getattr(settings, 'SOCIAL_AUTH_COMPLETE_URL_NAME', 'complete')
+    complete_url = getattr(settings, 'SOCIAL_AUTH_COMPLETE_URL_NAME',
+                           'complete')
     redirect = getattr(settings, 'LOGIN_REDIRECT_URL', '')
-    return auth_process(request, backend, complete, redirect)
+    return auth_process(request, backend, complete_url, redirect)
 
 
 def complete(request, backend):
@@ -46,10 +47,10 @@ def complete(request, backend):
 @login_required
 def associate(request, backend):
     """Authentication starting process"""
-    complete = getattr(settings, 'SOCIAL_AUTH_ASSOCIATE_URL_NAME',
-                       'associate_complete')
+    complete_url = getattr(settings, 'SOCIAL_AUTH_ASSOCIATE_URL_NAME',
+                           'associate_complete')
     redirect = getattr(settings, 'LOGIN_REDIRECT_URL', '')
-    return auth_process(request, backend, complete, redirect)
+    return auth_process(request, backend, complete_url, redirect)
 
 
 @login_required