Skip to content

Commit bd275cd

Browse files
committed
chore: apply pre-commit fixes
Automated update of shared files from the social-core repository, see https://github.com/python-social-auth/.github/blob/main/repo-sync.py
1 parent a3debe9 commit bd275cd

File tree

4 files changed

+57
-48
lines changed

4 files changed

+57
-48
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
## [1.0.1](https://github.com/python-social-auth/social-storage-mongoengine/releases/tag/1.0.1) - 2017-05-06
1111

1212
### Changed
13+
1314
- Define default `data` attribute in partial pipeline model
1415

1516
## [1.0.0](https://github.com/python-social-auth/social-storage-mongoengine/releases/tag/1.0.0) - 2017-01-22
1617

1718
### Added
19+
1820
- Added partial pipeline db storage solution
1921

2022
## [0.0.1](https://github.com/python-social-auth/social-storage-mongoengine/releases/tag/0.0.1) - 2016-11-27
2123

2224
### Changed
25+
2326
- Split from the monolitic [python-social-auth](https://github.com/omab/python-social-auth)
2427
codebase

setup.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
1-
# -*- coding: utf-8 -*-
21
"""Setup file for easy installation"""
3-
from os.path import join, dirname
2+
3+
from os.path import dirname, join
4+
45
from setuptools import setup
56

67

78
def long_description():
8-
return open(join(dirname(__file__), 'README.md')).read()
9+
return open(join(dirname(__file__), "README.md")).read()
10+
911

1012
def load_requirements():
11-
return open(join(dirname(__file__), 'requirements.txt')).readlines()
13+
return open(join(dirname(__file__), "requirements.txt")).readlines()
14+
1215

1316
setup(
14-
name='social-auth-storage-mongoengine',
15-
version=__import__('social_mongoengine').__version__,
16-
author='Matias Aguirre',
17-
author_email='[email protected]',
18-
description='Python Social Authentication, Mongoengine storage.',
19-
license='BSD',
20-
keywords='mongoengine, social auth',
21-
url='https://github.com/python-social-auth/social-storage-mongoengine',
22-
packages=['social_mongoengine'],
17+
name="social-auth-storage-mongoengine",
18+
version=__import__("social_mongoengine").__version__,
19+
author="Matias Aguirre",
20+
author_email="[email protected]",
21+
description="Python Social Authentication, Mongoengine storage.",
22+
license="BSD",
23+
keywords="mongoengine, social auth",
24+
url="https://github.com/python-social-auth/social-storage-mongoengine",
25+
packages=["social_mongoengine"],
2326
long_description=long_description(),
2427
install_requires=load_requirements(),
2528
classifiers=[
26-
'Development Status :: 4 - Beta',
27-
'Topic :: Internet',
28-
'License :: OSI Approved :: BSD License',
29-
'Intended Audience :: Developers',
30-
'Environment :: Web Environment',
31-
'Programming Language :: Python',
32-
'Programming Language :: Python :: 2.7',
33-
'Programming Language :: Python :: 3'
29+
"Development Status :: 4 - Beta",
30+
"Topic :: Internet",
31+
"License :: OSI Approved :: BSD License",
32+
"Intended Audience :: Developers",
33+
"Environment :: Web Environment",
34+
"Programming Language :: Python",
35+
"Programming Language :: Python :: 2.7",
36+
"Programming Language :: Python :: 3",
3437
],
35-
zip_safe=False
38+
zip_safe=False,
3639
)

social_mongoengine/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.0.1'
1+
__version__ = "1.0.1"

social_mongoengine/storage.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import base64
2-
import six
32

4-
from mongoengine import DictField, IntField, StringField, \
5-
EmailField, BooleanField
3+
import six
4+
from mongoengine import BooleanField, DictField, EmailField, IntField, StringField
65
from mongoengine.queryset import OperationError
6+
from social_core.storage import (
7+
AssociationMixin,
8+
BaseStorage,
9+
CodeMixin,
10+
NonceMixin,
11+
PartialMixin,
12+
UserMixin,
13+
)
714

8-
from social_core.storage import UserMixin, AssociationMixin, NonceMixin, \
9-
CodeMixin, PartialMixin, BaseStorage
10-
11-
12-
UNUSABLE_PASSWORD = '!' # Borrowed from django 1.4
15+
UNUSABLE_PASSWORD = "!" # Borrowed from django 1.4
1316

1417

1518
class MongoengineUserMixin(UserMixin):
1619
"""Social Auth association model"""
20+
1721
user = None
1822
provider = StringField(max_length=32)
19-
uid = StringField(max_length=255, unique_with='provider')
23+
uid = StringField(max_length=255, unique_with="provider")
2024
extra_data = DictField()
2125

2226
def str_id(self):
@@ -45,14 +49,14 @@ def username_max_length(cls):
4549

4650
@classmethod
4751
def username_field(cls):
48-
return getattr(cls.user_model(), 'USERNAME_FIELD', 'username')
52+
return getattr(cls.user_model(), "USERNAME_FIELD", "username")
4953

5054
@classmethod
5155
def create_user(cls, *args, **kwargs):
52-
kwargs['password'] = UNUSABLE_PASSWORD
53-
if 'email' in kwargs:
56+
kwargs["password"] = UNUSABLE_PASSWORD
57+
if "email" in kwargs:
5458
# Empty string makes email regex validation fail
55-
kwargs['email'] = kwargs['email'] or None
59+
kwargs["email"] = kwargs["email"] or None
5660
return cls.user_model().objects.create(*args, **kwargs)
5761

5862
@classmethod
@@ -63,7 +67,7 @@ def allowed_to_disconnect(cls, user, backend_name, association_id=None):
6367
qs = cls.objects.filter(provider__ne=backend_name)
6468
qs = qs.filter(user=user)
6569

66-
if hasattr(user, 'has_usable_password'):
70+
if hasattr(user, "has_usable_password"):
6771
valid_password = user.has_usable_password()
6872
else:
6973
valid_password = True
@@ -88,8 +92,8 @@ def user_exists(cls, *args, **kwargs):
8892
Return True/False if a User instance exists with the given arguments.
8993
Arguments are directly passed to filter() manager method.
9094
"""
91-
if 'username' in kwargs:
92-
kwargs[cls.username_field()] = kwargs.pop('username')
95+
if "username" in kwargs:
96+
kwargs[cls.username_field()] = kwargs.pop("username")
9397
return cls.user_model().objects.filter(*args, **kwargs).count() > 0
9498

9599
@classmethod
@@ -119,19 +123,21 @@ def get_social_auth(cls, provider, uid):
119123

120124
class MongoengineNonceMixin(NonceMixin):
121125
"""One use numbers"""
126+
122127
server_url = StringField(max_length=255)
123128
timestamp = IntField()
124129
salt = StringField(max_length=40)
125130

126131
@classmethod
127132
def use(cls, server_url, timestamp, salt):
128-
return cls.objects.get_or_create(server_url=server_url,
129-
timestamp=timestamp,
130-
salt=salt)[1]
133+
return cls.objects.get_or_create(
134+
server_url=server_url, timestamp=timestamp, salt=salt
135+
)[1]
131136

132137

133138
class MongoengineAssociationMixin(AssociationMixin):
134139
"""OpenId account association"""
140+
135141
server_url = StringField(max_length=255)
136142
handle = StringField(max_length=255)
137143
secret = StringField(max_length=255) # Stored base64 encoded
@@ -143,11 +149,9 @@ class MongoengineAssociationMixin(AssociationMixin):
143149
def store(cls, server_url, association):
144150
# Don't use get_or_create because issued cannot be null
145151
try:
146-
assoc = cls.objects.get(server_url=server_url,
147-
handle=association.handle)
152+
assoc = cls.objects.get(server_url=server_url, handle=association.handle)
148153
except cls.DoesNotExist:
149-
assoc = cls(server_url=server_url,
150-
handle=association.handle)
154+
assoc = cls(server_url=server_url, handle=association.handle)
151155
assoc.secret = base64.encodestring(association.secret).decode()
152156
assoc.issued = association.issued
153157
assoc.lifetime = association.lifetime
@@ -206,5 +210,4 @@ class BaseMongoengineStorage(BaseStorage):
206210

207211
@classmethod
208212
def is_integrity_error(cls, exception):
209-
return exception.__class__ is OperationError and \
210-
'E11000' in exception.message
213+
return exception.__class__ is OperationError and "E11000" in exception.message

0 commit comments

Comments
 (0)