Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f15520b

Browse files
authored
Merge pull request auth0#311 from auth0/code-etyle
[SDK-3182] Add some code style tools
2 parents d07f87b + 0d282f7 commit f15520b

File tree

97 files changed

+4294
-3131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4294
-3131
lines changed

.circleci/config.yml

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,41 @@
1-
version: 2
2-
jobs:
3-
python_2:
1+
version: 2.1
2+
3+
orbs:
4+
python: circleci/[email protected]
5+
6+
executors:
7+
python_3_10:
48
docker:
5-
- image: circleci/python:2.7-jessie
9+
- image: cimg/python:3.10
10+
python_2_7:
11+
docker:
12+
- image: cimg/python:2.7
13+
14+
jobs:
15+
python_3:
16+
executor: python_3_10
617
steps:
718
- checkout
8-
- run:
9-
command: |
10-
sudo chown -R circleci:circleci /usr/local/bin
11-
sudo chown -R circleci:circleci /usr/local/lib/python2.7/site-packages
12-
- restore_cache:
13-
key: deps2-{{ .Branch }}-{{ checksum "setup.py" }}
14-
- run:
15-
command: |
16-
pip install .[test]
17-
pip install codecov
18-
- save_cache:
19-
key: deps2-{{ .Branch }}-{{ checksum "setup.py" }}
20-
paths:
21-
- ".venv"
22-
- "/usr/local/bin"
23-
- "/usr/local/lib/python2.7/site-packages"
24-
- run:
25-
name: Run tests
26-
command: coverage run --include=auth0/v3/*.py --omit=auth0/v3/test/*.py -m unittest discover
27-
- run:
28-
when: on_success
29-
command: bash <(curl -s https://codecov.io/bash)
30-
python_3:
31-
docker:
32-
- image: circleci/python:3.6-jessie
19+
- python/install-packages:
20+
pkg-manager: pip
21+
- run: pre-commit run --all-files
22+
- run: coverage run -m unittest
23+
- run: bash <(curl -s https://codecov.io/bash)
24+
- run: make -C docs html
25+
26+
python_2:
27+
executor: python_2_7
3328
steps:
3429
- checkout
35-
- run:
36-
command: |
37-
sudo chown -R circleci:circleci /usr/local/bin
38-
sudo chown -R circleci:circleci /usr/local/lib/python3.6/site-packages
39-
- restore_cache:
40-
key: deps3-{{ .Branch }}-{{ checksum "setup.py" }}
41-
- run:
42-
command: |
43-
pip install .[test]
44-
pip install codecov
45-
pip install -r docs/requirements.txt
46-
- save_cache:
47-
key: deps3-{{ .Branch }}-{{ checksum "setup.py" }}
48-
paths:
49-
- ".venv"
50-
- "/usr/local/bin"
51-
- "/usr/local/lib/python3.6/site-packages"
52-
- run:
53-
name: Run tests
54-
command: coverage run --include=auth0/v3/*.py --omit=auth0/v3/test/*.py -m unittest discover
55-
- run:
56-
name: Build docs
57-
command: cd docs/ && make html
58-
- run:
59-
when: on_success
60-
command: bash <(curl -s https://codecov.io/bash)
30+
- python/install-packages:
31+
pkg-manager: pip-dist
32+
path-args: ".[test]"
33+
- run: coverage run -m unittest discover
34+
- run: bash <(curl -s https://codecov.io/bash)
6135

6236
workflows:
63-
version: 2
64-
build:
37+
main:
6538
jobs:
39+
- python_3
6640
- python_2
67-
- python_3
41+

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
ignore = E501
3+
max-line-length = 88

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ lib64/
2020
parts/
2121
sdist/
2222
var/
23+
bin/
2324
*.egg-info/
2425
.installed.cfg
2526
*.egg
2627
.pypirc
28+
pyvenv.cfg
2729

2830
# Installer logs
2931
pip-log.txt

.pre-commit-config.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
- repo: https://github.com/asottile/pyupgrade
1+
repos:
2+
- repo: https://gitlab.com/pycqa/flake8
3+
rev: 4.0.1
4+
hooks:
5+
- id: flake8
6+
- repo: https://github.com/asottile/pyupgrade
27
rev: v1.6.1
38
hooks:
4-
- id: pyupgrade
9+
- id: pyupgrade
10+
- repo: https://github.com/PyCQA/isort
11+
rev: 5.10.1
12+
hooks:
13+
- id: isort
14+
args: ["--profile", "black"]
15+
- repo: https://github.com/psf/black
16+
rev: 22.1.0
17+
hooks:
18+
- id: black
19+
additional_dependencies: ['click<8.1.0']
20+

auth0/__init__.py

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

auth0/v3/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from .exceptions import Auth0Error, RateLimitError, TokenValidationError
2+
3+
__all__ = ("Auth0Error", "RateLimitError", "TokenValidationError")

auth0/v3/authentication/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,16 @@
88
from .revoke_token import RevokeToken
99
from .social import Social
1010
from .users import Users
11+
12+
__all__ = (
13+
"AuthorizeClient",
14+
"Database",
15+
"Delegated",
16+
"Enterprise",
17+
"GetToken",
18+
"Logout",
19+
"Passwordless",
20+
"RevokeToken",
21+
"Social",
22+
"Users",
23+
)

auth0/v3/authentication/authorize_client.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,32 @@ class AuthorizeClient(AuthenticationBase):
99
domain (str): Your auth0 domain (e.g: username.auth0.com)
1010
"""
1111

12-
def authorize(self, client_id, audience=None, state=None, redirect_uri=None,
13-
response_type='code', scope='openid', organization=None, invitation=None):
12+
def authorize(
13+
self,
14+
client_id,
15+
audience=None,
16+
state=None,
17+
redirect_uri=None,
18+
response_type="code",
19+
scope="openid",
20+
organization=None,
21+
invitation=None,
22+
):
1423
"""Authorization code grant
1524
1625
This is the OAuth 2.0 grant that regular web apps utilize in order to access an API.
1726
"""
1827
params = {
19-
'client_id': client_id,
20-
'audience': audience,
21-
'response_type': response_type,
22-
'scope': scope,
23-
'state': state,
24-
'redirect_uri': redirect_uri,
25-
'organization': organization,
26-
'invitation': invitation
28+
"client_id": client_id,
29+
"audience": audience,
30+
"response_type": response_type,
31+
"scope": scope,
32+
"state": state,
33+
"redirect_uri": redirect_uri,
34+
"organization": organization,
35+
"invitation": invitation,
2736
}
2837

2938
return self.get(
30-
'{}://{}/authorize'.format(self.protocol, self.domain),
31-
params=params)
39+
"{}://{}/authorize".format(self.protocol, self.domain), params=params
40+
)

auth0/v3/authentication/base.py

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import base64
22
import json
3-
import sys
43
import platform
4+
import sys
5+
56
import requests
7+
68
from ..exceptions import Auth0Error, RateLimitError
79

8-
UNKNOWN_ERROR = 'a0.sdk.internal.unknown'
10+
UNKNOWN_ERROR = "a0.sdk.internal.unknown"
911

1012

1113
class AuthenticationBase(object):
@@ -24,35 +26,43 @@ def __init__(self, domain, telemetry=True, timeout=5.0, protocol="https"):
2426
self.domain = domain
2527
self.timeout = timeout
2628
self.protocol = protocol
27-
self.base_headers = {'Content-Type': 'application/json'}
29+
self.base_headers = {"Content-Type": "application/json"}
2830

2931
if telemetry:
3032
py_version = platform.python_version()
31-
version = sys.modules['auth0'].__version__
32-
33-
auth0_client = json.dumps({
34-
'name': 'auth0-python',
35-
'version': version,
36-
'env': {
37-
'python': py_version,
33+
version = sys.modules["auth0"].__version__
34+
35+
auth0_client = json.dumps(
36+
{
37+
"name": "auth0-python",
38+
"version": version,
39+
"env": {
40+
"python": py_version,
41+
},
3842
}
39-
}).encode('utf-8')
43+
).encode("utf-8")
4044

41-
self.base_headers.update({
42-
'User-Agent': 'Python/{}'.format(py_version),
43-
'Auth0-Client': base64.b64encode(auth0_client),
44-
})
45+
self.base_headers.update(
46+
{
47+
"User-Agent": "Python/{}".format(py_version),
48+
"Auth0-Client": base64.b64encode(auth0_client),
49+
}
50+
)
4551

4652
def post(self, url, data=None, headers=None):
4753
request_headers = self.base_headers.copy()
4854
request_headers.update(headers or {})
49-
response = requests.post(url=url, json=data, headers=request_headers, timeout=self.timeout)
55+
response = requests.post(
56+
url=url, json=data, headers=request_headers, timeout=self.timeout
57+
)
5058
return self._process_response(response)
5159

5260
def get(self, url, params=None, headers=None):
5361
request_headers = self.base_headers.copy()
5462
request_headers.update(headers or {})
55-
response = requests.get(url=url, params=params, headers=request_headers, timeout=self.timeout)
63+
response = requests.get(
64+
url=url, params=params, headers=request_headers, timeout=self.timeout
65+
)
5666
return self._process_response(response)
5767

5868
def _process_response(self, response):
@@ -78,14 +88,18 @@ def content(self):
7888
return self._content
7989

8090
if self._status_code == 429:
81-
reset_at = int(self._headers.get('x-ratelimit-reset', '-1'))
82-
raise RateLimitError(error_code=self._error_code(),
83-
message=self._error_message(),
84-
reset_at=reset_at)
85-
86-
raise Auth0Error(status_code=self._status_code,
87-
error_code=self._error_code(),
88-
message=self._error_message())
91+
reset_at = int(self._headers.get("x-ratelimit-reset", "-1"))
92+
raise RateLimitError(
93+
error_code=self._error_code(),
94+
message=self._error_message(),
95+
reset_at=reset_at,
96+
)
97+
98+
raise Auth0Error(
99+
status_code=self._status_code,
100+
error_code=self._error_code(),
101+
message=self._error_message(),
102+
)
89103

90104
def _is_error(self):
91105
return self._status_code is None or self._status_code >= 400
@@ -101,23 +115,27 @@ def _error_message(self):
101115
class JsonResponse(Response):
102116
def __init__(self, response):
103117
content = json.loads(response.text)
104-
super(JsonResponse, self).__init__(response.status_code, content, response.headers)
118+
super(JsonResponse, self).__init__(
119+
response.status_code, content, response.headers
120+
)
105121

106122
def _error_code(self):
107-
if 'error' in self._content:
108-
return self._content.get('error')
109-
elif 'code' in self._content:
110-
return self._content.get('code')
123+
if "error" in self._content:
124+
return self._content.get("error")
125+
elif "code" in self._content:
126+
return self._content.get("code")
111127
else:
112128
return UNKNOWN_ERROR
113129

114130
def _error_message(self):
115-
return self._content.get('error_description', '')
131+
return self._content.get("error_description", "")
116132

117133

118134
class PlainResponse(Response):
119135
def __init__(self, response):
120-
super(PlainResponse, self).__init__(response.status_code, response.text, response.headers)
136+
super(PlainResponse, self).__init__(
137+
response.status_code, response.text, response.headers
138+
)
121139

122140
def _error_code(self):
123141
return UNKNOWN_ERROR
@@ -128,10 +146,10 @@ def _error_message(self):
128146

129147
class EmptyResponse(Response):
130148
def __init__(self, status_code):
131-
super(EmptyResponse, self).__init__(status_code, '', {})
149+
super(EmptyResponse, self).__init__(status_code, "", {})
132150

133151
def _error_code(self):
134152
return UNKNOWN_ERROR
135153

136154
def _error_message(self):
137-
return ''
155+
return ""

0 commit comments

Comments
 (0)