Skip to content

Commit db6b426

Browse files
committed
SDK-977: Reformat Python SDK code base
1 parent ad76c7e commit db6b426

File tree

17 files changed

+214
-188
lines changed

17 files changed

+214
-188
lines changed

examples/aml/app.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from yoti_python_sdk import Client
88
from yoti_python_sdk import aml
99

10-
dotenv_path = join(dirname(__file__), '.env')
10+
dotenv_path = join(dirname(__file__), ".env")
1111
load_dotenv(dotenv_path)
1212

13-
YOTI_CLIENT_SDK_ID = environ.get('YOTI_CLIENT_SDK_ID')
14-
YOTI_KEY_FILE_PATH = environ.get('YOTI_KEY_FILE_PATH')
13+
YOTI_CLIENT_SDK_ID = environ.get("YOTI_CLIENT_SDK_ID")
14+
YOTI_KEY_FILE_PATH = environ.get("YOTI_KEY_FILE_PATH")
1515

1616

1717
# The following exits cleanly on Ctrl-C,
@@ -25,11 +25,7 @@ def cli_exception(exception_type, value, tb):
2525
family_name = "Heath"
2626

2727
aml_address = aml.AmlAddress(country="GBR")
28-
aml_profile = aml.AmlProfile(
29-
given_names,
30-
family_name,
31-
aml_address
32-
)
28+
aml_profile = aml.AmlProfile(given_names, family_name, aml_address)
3329

3430
if sys.stdin.isatty():
3531
sys.excepthook = cli_exception
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from os import environ
22

3-
YOTI_SCENARIO_ID = environ.get('YOTI_SCENARIO_ID')
4-
YOTI_CLIENT_SDK_ID = environ.get('YOTI_CLIENT_SDK_ID')
5-
YOTI_KEY_FILE_PATH = environ.get('YOTI_KEY_FILE_PATH')
3+
YOTI_SCENARIO_ID = environ.get("YOTI_SCENARIO_ID")
4+
YOTI_CLIENT_SDK_ID = environ.get("YOTI_CLIENT_SDK_ID")
5+
YOTI_KEY_FILE_PATH = environ.get("YOTI_KEY_FILE_PATH")

examples/yoti_example_django/yoti_example/settings.py

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
2222

2323
# SECURITY WARNING: keep the secret key used in production secret!
24-
SECRET_KEY = 'p3dh1cx&ey8oesy-nj_md-ouo75xi548m22j^zrv((d1@k%%3!'
24+
SECRET_KEY = "p3dh1cx&ey8oesy-nj_md-ouo75xi548m22j^zrv((d1@k%%3!"
2525

2626
# SECURITY WARNING: don't run with debug turned on in production!
2727
DEBUG = True
@@ -31,52 +31,52 @@
3131
# Application definition
3232

3333
INSTALLED_APPS = [
34-
'django.contrib.admin',
35-
'django.contrib.auth',
36-
'django.contrib.contenttypes',
37-
'django.contrib.sessions',
38-
'django.contrib.messages',
39-
'django.contrib.staticfiles',
40-
'sslserver'
34+
"django.contrib.admin",
35+
"django.contrib.auth",
36+
"django.contrib.contenttypes",
37+
"django.contrib.sessions",
38+
"django.contrib.messages",
39+
"django.contrib.staticfiles",
40+
"sslserver",
4141
]
4242

4343
MIDDLEWARE = [
44-
'django.middleware.security.SecurityMiddleware',
45-
'django.contrib.sessions.middleware.SessionMiddleware',
46-
'django.middleware.common.CommonMiddleware',
47-
'django.middleware.csrf.CsrfViewMiddleware',
48-
'django.contrib.auth.middleware.AuthenticationMiddleware',
49-
'django.contrib.messages.middleware.MessageMiddleware',
50-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
44+
"django.middleware.security.SecurityMiddleware",
45+
"django.contrib.sessions.middleware.SessionMiddleware",
46+
"django.middleware.common.CommonMiddleware",
47+
"django.middleware.csrf.CsrfViewMiddleware",
48+
"django.contrib.auth.middleware.AuthenticationMiddleware",
49+
"django.contrib.messages.middleware.MessageMiddleware",
50+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5151
]
5252

53-
ROOT_URLCONF = 'yoti_example.urls'
53+
ROOT_URLCONF = "yoti_example.urls"
5454

5555
TEMPLATES = [
5656
{
57-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
58-
'DIRS': [join(BASE_DIR, 'yoti_example/templates')],
59-
'APP_DIRS': True,
60-
'OPTIONS': {
61-
'context_processors': [
62-
'django.template.context_processors.debug',
63-
'django.template.context_processors.request',
64-
'django.contrib.auth.context_processors.auth',
65-
'django.contrib.messages.context_processors.messages',
66-
],
57+
"BACKEND": "django.template.backends.django.DjangoTemplates",
58+
"DIRS": [join(BASE_DIR, "yoti_example/templates")],
59+
"APP_DIRS": True,
60+
"OPTIONS": {
61+
"context_processors": [
62+
"django.template.context_processors.debug",
63+
"django.template.context_processors.request",
64+
"django.contrib.auth.context_processors.auth",
65+
"django.contrib.messages.context_processors.messages",
66+
]
6767
},
68-
},
68+
}
6969
]
7070

71-
WSGI_APPLICATION = 'yoti_example.wsgi.application'
71+
WSGI_APPLICATION = "yoti_example.wsgi.application"
7272

7373
# Database
7474
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
7575

7676
DATABASES = {
77-
'default': {
78-
'ENGINE': 'django.db.backends.sqlite3',
79-
'NAME': join(BASE_DIR, 'db.sqlite3'),
77+
"default": {
78+
"ENGINE": "django.db.backends.sqlite3",
79+
"NAME": join(BASE_DIR, "db.sqlite3"),
8080
}
8181
}
8282

@@ -85,25 +85,19 @@
8585

8686
AUTH_PASSWORD_VALIDATORS = [
8787
{
88-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
89-
},
90-
{
91-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
92-
},
93-
{
94-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
95-
},
96-
{
97-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
88+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
9889
},
90+
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
91+
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
92+
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
9993
]
10094

10195
# Internationalization
10296
# https://docs.djangoproject.com/en/1.10/topics/i18n/
10397

104-
LANGUAGE_CODE = 'en-us'
98+
LANGUAGE_CODE = "en-us"
10599

106-
TIME_ZONE = 'UTC'
100+
TIME_ZONE = "UTC"
107101

108102
USE_I18N = True
109103

@@ -114,8 +108,8 @@
114108
# Static files (CSS, JavaScript, Images)
115109
# https://docs.djangoproject.com/en/1.10/howto/static-files/
116110

117-
STATIC_URL = '/static/'
118-
STATICFILES_FOLDER_NAME = 'static'
119-
PROJECT_DIR = 'yoti_example/'
111+
STATIC_URL = "/static/"
112+
STATICFILES_FOLDER_NAME = "static"
113+
PROJECT_DIR = "yoti_example/"
120114
STATIC_ROOT = os.path.join(BASE_DIR, STATICFILES_FOLDER_NAME)
121-
STATICFILES_DIRS = os.path.join(PROJECT_DIR, STATICFILES_FOLDER_NAME),
115+
STATICFILES_DIRS = (os.path.join(PROJECT_DIR, STATICFILES_FOLDER_NAME),)

setup.py

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,56 @@
33

44
from yoti_python_sdk import __version__
55

6-
long_description = 'This package contains the tools you need to quickly ' \
7-
'integrate your Python back-end with Yoti, so that your ' \
8-
'users can share their identity details with your ' \
9-
'application in a secure and trusted way.'
6+
long_description = (
7+
"This package contains the tools you need to quickly "
8+
"integrate your Python back-end with Yoti, so that your "
9+
"users can share their identity details with your "
10+
"application in a secure and trusted way."
11+
)
1012

1113
setup(
12-
name='yoti',
14+
name="yoti",
1315
version=__version__,
1416
packages=find_packages(),
15-
license='MIT',
16-
description='The Yoti Python SDK, providing API support for Login, Verify (2FA) and Age Verification.',
17+
license="MIT",
18+
description="The Yoti Python SDK, providing API support for Login, Verify (2FA) and Age Verification.",
1719
long_description=long_description,
18-
url='https://github.com/getyoti/yoti-python-sdk',
19-
author='Yoti',
20-
author_email='[email protected]',
21-
install_requires=['cryptography>=2.2.1', 'protobuf>=3.1.0',
22-
'requests>=2.11.1', 'future>=0.11.0', 'asn1==2.2.0', 'pyopenssl>=18.0.0'],
20+
url="https://github.com/getyoti/yoti-python-sdk",
21+
author="Yoti",
22+
author_email="[email protected]",
23+
install_requires=[
24+
"cryptography>=2.2.1",
25+
"protobuf>=3.1.0",
26+
"requests>=2.11.1",
27+
"future>=0.11.0",
28+
"asn1==2.2.0",
29+
"pyopenssl>=18.0.0",
30+
],
2331
extras_require={
24-
'examples': ['Django>1.11.16', 'Flask>=0.10', 'python-dotenv>=0.7.1', 'django-sslserver>=0.2',
25-
'Werkzeug==0.11.15'],
32+
"examples": [
33+
"Django>1.11.16",
34+
"Flask>=0.10",
35+
"python-dotenv>=0.7.1",
36+
"django-sslserver>=0.2",
37+
"Werkzeug==0.11.15",
38+
]
2639
},
2740
classifiers=[
28-
'Development Status :: 5 - Production/Stable',
29-
'License :: OSI Approved :: MIT License',
30-
'Operating System :: OS Independent',
31-
'Intended Audience :: Developers',
32-
'Programming Language :: Python',
33-
'Programming Language :: Python :: 2',
34-
'Programming Language :: Python :: 2.6',
35-
'Programming Language :: Python :: 2.7',
36-
'Programming Language :: Python :: 3',
37-
'Programming Language :: Python :: 3.3',
38-
'Programming Language :: Python :: 3.4',
39-
'Programming Language :: Python :: 3.5',
40-
'Programming Language :: Python :: 3.6',
41-
'Programming Language :: Python :: 3.7',
42-
'Topic :: Software Development :: Libraries :: Python Modules',
41+
"Development Status :: 5 - Production/Stable",
42+
"License :: OSI Approved :: MIT License",
43+
"Operating System :: OS Independent",
44+
"Intended Audience :: Developers",
45+
"Programming Language :: Python",
46+
"Programming Language :: Python :: 2",
47+
"Programming Language :: Python :: 2.6",
48+
"Programming Language :: Python :: 2.7",
49+
"Programming Language :: Python :: 3",
50+
"Programming Language :: Python :: 3.3",
51+
"Programming Language :: Python :: 3.4",
52+
"Programming Language :: Python :: 3.5",
53+
"Programming Language :: Python :: 3.6",
54+
"Programming Language :: Python :: 3.7",
55+
"Topic :: Software Development :: Libraries :: Python Modules",
4356
],
44-
keywords='yoti sdk 2FA multifactor authentication verification identity login register verify 2Factor',
57+
keywords="yoti sdk 2FA multifactor authentication verification identity login register verify 2Factor",
4558
)

yoti_python_sdk/__init__.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,26 @@
66
from yoti_python_sdk.client import Client
77

88
DEFAULTS = {
9-
'YOTI_API_URL': 'https://api.yoti.com',
10-
'YOTI_API_PORT': 443,
11-
'YOTI_API_VERSION': 'v1',
9+
"YOTI_API_URL": "https://api.yoti.com",
10+
"YOTI_API_PORT": 443,
11+
"YOTI_API_VERSION": "v1",
1212
}
1313

1414
main_ns = {}
1515

1616
directory_name = os.path.dirname(__file__)
17-
version_path = os.path.join(directory_name, 'version.py')
17+
version_path = os.path.join(directory_name, "version.py")
1818

1919
ver_path = convert_path(version_path)
2020
with open(ver_path) as ver_file:
2121
exec(ver_file.read(), main_ns)
2222

23-
__version__ = main_ns['__version__']
24-
YOTI_API_URL = environ.get('YOTI_API_URL', DEFAULTS['YOTI_API_URL'])
25-
YOTI_API_PORT = environ.get('YOTI_API_PORT', DEFAULTS['YOTI_API_PORT'])
26-
YOTI_API_VERSION = environ.get('YOTI_API_VERSION', DEFAULTS['YOTI_API_VERSION'])
27-
YOTI_API_ENDPOINT = '{0}:{1}/api/{2}'.format(YOTI_API_URL, YOTI_API_PORT, YOTI_API_VERSION)
23+
__version__ = main_ns["__version__"]
24+
YOTI_API_URL = environ.get("YOTI_API_URL", DEFAULTS["YOTI_API_URL"])
25+
YOTI_API_PORT = environ.get("YOTI_API_PORT", DEFAULTS["YOTI_API_PORT"])
26+
YOTI_API_VERSION = environ.get("YOTI_API_VERSION", DEFAULTS["YOTI_API_VERSION"])
27+
YOTI_API_ENDPOINT = "{0}:{1}/api/{2}".format(
28+
YOTI_API_URL, YOTI_API_PORT, YOTI_API_VERSION
29+
)
2830

29-
__all__ = [
30-
'Client',
31-
__version__
32-
]
31+
__all__ = ["Client", __version__]

yoti_python_sdk/aml.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ def __init__(self, response_text):
77
raise ValueError("AML Response is not valid")
88

99
try:
10-
self.on_pep_list = json.loads(response_text).get('on_pep_list')
11-
self.on_fraud_list = json.loads(response_text).get('on_fraud_list')
12-
self.on_watch_list = json.loads(response_text).get('on_watch_list')
10+
self.on_pep_list = json.loads(response_text).get("on_pep_list")
11+
self.on_fraud_list = json.loads(response_text).get("on_fraud_list")
12+
self.on_watch_list = json.loads(response_text).get("on_watch_list")
1313

1414
except (AttributeError, IOError, TypeError, OSError) as exc:
15-
error = 'Could not parse AML result from response: "{0}"'.format(response_text)
16-
exception = '{0}: {1}'.format(type(exc).__name__, exc)
17-
raise RuntimeError('{0}: {1}'.format(error, exception))
15+
error = 'Could not parse AML result from response: "{0}"'.format(
16+
response_text
17+
)
18+
exception = "{0}: {1}".format(type(exc).__name__, exc)
19+
raise RuntimeError("{0}: {1}".format(error, exception))
1820

1921
self.__check_for_none_values(self.on_pep_list)
2022
self.__check_for_none_values(self.on_fraud_list)
@@ -23,12 +25,16 @@ def __init__(self, response_text):
2325
@staticmethod
2426
def __check_for_none_values(arg):
2527
if arg is None:
26-
raise TypeError(str.format("{0} argument was unable to be retrieved from the response", arg))
28+
raise TypeError(
29+
str.format(
30+
"{0} argument was unable to be retrieved from the response", arg
31+
)
32+
)
2733

2834
def __iter__(self):
29-
yield 'on_pep_list', self.on_pep_list
30-
yield 'on_fraud_list', self.on_fraud_list
31-
yield 'on_watch_list', self.on_watch_list
35+
yield "on_pep_list", self.on_pep_list
36+
yield "on_fraud_list", self.on_fraud_list
37+
yield "on_watch_list", self.on_watch_list
3238

3339

3440
class AmlAddress:

yoti_python_sdk/attribute.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ def anchors(self):
2323

2424
@property
2525
def sources(self):
26-
return list(filter(lambda a: a.anchor_type == config.ANCHOR_SOURCE, self.__anchors))
26+
return list(
27+
filter(lambda a: a.anchor_type == config.ANCHOR_SOURCE, self.__anchors)
28+
)
2729

2830
@property
2931
def verifiers(self):
30-
return list(filter(lambda a: a.anchor_type == config.ANCHOR_VERIFIER, self.__anchors))
32+
return list(
33+
filter(lambda a: a.anchor_type == config.ANCHOR_VERIFIER, self.__anchors)
34+
)

0 commit comments

Comments
 (0)