Skip to content

Commit a29c9fe

Browse files
authored
Merge pull request #462 from weakish/flake8
flake8
2 parents 2187c22 + b4e3fe2 commit a29c9fe

53 files changed

Lines changed: 2493 additions & 2113 deletions

Some content is hidden

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

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203
4+
exclude = build,docs

.github/workflows/pythonpackage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: [3.5, 3.6, 3.7, 3.8]
18+
python-version: [3.5]
1919

2020
steps:
2121
- uses: actions/checkout@v2

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ Run tests:
4646
nosetests
4747
```
4848

49+
## Linter and Formatter
50+
51+
Currently, flake8 (linter) and black (formatter) are used.
52+
But we are still exploring.
53+
4954
## Release a New Version
5055

5156
1. Edit `changelog` and `setup.py` (`version`).

leancloud/__init__.py

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
import sys
1313
import logging
1414
import warnings
15-
16-
logger = logging.getLogger('iso8601.iso8601')
17-
logger.setLevel(logging.CRITICAL)
18-
1915
from . import client
2016
from . import cloud
2117
from . import cloudfunc
@@ -25,15 +21,15 @@
2521
from .client import use_master_key
2622
from .client import use_production
2723
from .client import use_region
28-
from .conversation import Conversation
24+
from .conversation import Conversation # noqa: F401
2925
from .engine import Engine
3026
from .engine import LeanEngineError
3127
from .engine.https_redirect_middleware import HttpsRedirectMiddleware
3228
from .errors import LeanCloudError
3329
from .errors import LeanCloudWarning
3430
from .file_ import File
3531
from .geo_point import GeoPoint
36-
from .message import Message
32+
from .message import Message # noqa: F401
3733
from .object_ import Object
3834
from .push import Installation
3935
from .query import FriendshipQuery
@@ -46,45 +42,48 @@
4642
from .user import User
4743

4844

49-
__author__ = 'asaka <lan@leancloud.rocks>'
50-
__version__ = '2.1.9'
45+
logger = logging.getLogger("iso8601.iso8601")
46+
logger.setLevel(logging.CRITICAL)
47+
48+
__author__ = "asaka <lan@leancloud.rocks>"
49+
__version__ = "2.1.9"
5150

5251

5352
__all__ = [
54-
'ACL',
55-
'Engine',
56-
'File',
57-
'FriendshipQuery',
58-
'GeoPoint',
59-
'HttpsRedirectMiddleware',
60-
'InboxQuery',
61-
'Installation',
62-
'LeanCloudError',
63-
'LeanEngineError',
64-
'Object',
65-
'Query',
66-
'Relation',
67-
'Role',
68-
'Status',
69-
'SysMessage',
70-
'User',
71-
'client',
72-
'cloud',
73-
'cloudfunc',
74-
'init',
75-
'push',
76-
'use_master_key',
77-
'use_production',
78-
'use_region',
53+
"ACL",
54+
"Engine",
55+
"File",
56+
"FriendshipQuery",
57+
"GeoPoint",
58+
"HttpsRedirectMiddleware",
59+
"InboxQuery",
60+
"Installation",
61+
"LeanCloudError",
62+
"LeanEngineError",
63+
"Object",
64+
"Query",
65+
"Relation",
66+
"Role",
67+
"Status",
68+
"SysMessage",
69+
"User",
70+
"client",
71+
"cloud",
72+
"cloudfunc",
73+
"init",
74+
"push",
75+
"use_master_key",
76+
"use_production",
77+
"use_region",
7978
]
8079

8180

8281
version_info = sys.version_info
8382

8483

8584
if version_info.major == 2 and version_info.minor < 7:
86-
warnings.warn('Python2 version less than 7 is not supported', LeanCloudWarning)
85+
warnings.warn("Python2 version less than 7 is not supported", LeanCloudWarning)
8786

8887

8988
if version_info.minor == 3 and version_info.minor < 4:
90-
warnings.warn('Python3 version less than 4 is not supported', LeanCloudWarning)
89+
warnings.warn("Python3 version less than 4 is not supported", LeanCloudWarning)

leancloud/acl.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
import leancloud
1111

12-
__author__ = 'asaka <lan@leancloud.rocks>'
12+
__author__ = "asaka <lan@leancloud.rocks>"
1313

1414

15-
PUBLIC_KEY = '*'
15+
PUBLIC_KEY = "*"
1616

1717

1818
class ACL(object):
@@ -26,7 +26,7 @@ def _set_access(self, access_type, user_id, allowed):
2626
if isinstance(user_id, leancloud.User):
2727
user_id = user_id.id
2828
elif isinstance(user_id, leancloud.Role):
29-
user_id = 'role:' + user_id.get_name()
29+
user_id = "role:" + user_id.get_name()
3030
permissions = self.permissions_by_id.get(user_id)
3131
if permissions is None:
3232
if not allowed:
@@ -45,23 +45,23 @@ def _get_access(self, access_type, user_id):
4545
if isinstance(user_id, leancloud.User):
4646
user_id = user_id.id
4747
elif isinstance(user_id, leancloud.Role):
48-
user_id = 'role:' + user_id.get_name()
48+
user_id = "role:" + user_id.get_name()
4949
permissions = self.permissions_by_id.get(user_id)
5050
if not permissions:
5151
return False
5252
return permissions.get(access_type, False)
5353

5454
def set_read_access(self, user_id, allowed):
55-
return self._set_access('read', user_id, allowed)
55+
return self._set_access("read", user_id, allowed)
5656

5757
def get_read_access(self, user_id):
58-
return self._get_access('read', user_id)
58+
return self._get_access("read", user_id)
5959

6060
def set_write_access(self, user_id, allowed):
61-
return self._set_access('write', user_id, allowed)
61+
return self._set_access("write", user_id, allowed)
6262

6363
def get_write_access(self, user_id):
64-
return self._get_access('write', user_id)
64+
return self._get_access("write", user_id)
6565

6666
def set_public_read_access(self, allowed):
6767
return self.set_read_access(PUBLIC_KEY, allowed)
@@ -79,26 +79,26 @@ def set_role_read_access(self, role, allowed):
7979
if isinstance(role, leancloud.Role):
8080
role = role.get_name()
8181
if not isinstance(role, six.string_types):
82-
raise TypeError('role must be a leancloud.Role or str')
83-
self.set_read_access('role:{0}'.format(role), allowed)
82+
raise TypeError("role must be a leancloud.Role or str")
83+
self.set_read_access("role:{0}".format(role), allowed)
8484

8585
def get_role_read_access(self, role):
8686
if isinstance(role, leancloud.Role):
8787
role = role.get_name()
8888
if not isinstance(role, six.string_types):
89-
raise TypeError('role must be a leancloud.Role or str')
90-
return self.get_read_access('role:{0}'.format(role))
89+
raise TypeError("role must be a leancloud.Role or str")
90+
return self.get_read_access("role:{0}".format(role))
9191

9292
def set_role_write_access(self, role, allowed):
9393
if isinstance(role, leancloud.Role):
9494
role = role.get_name()
9595
if not isinstance(role, six.string_types):
96-
raise TypeError('role must be a leancloud.Role or str')
97-
self.set_write_access('role:{0}'.format(role), allowed)
96+
raise TypeError("role must be a leancloud.Role or str")
97+
self.set_write_access("role:{0}".format(role), allowed)
9898

9999
def get_role_write_access(self, role):
100100
if isinstance(role, leancloud.Role):
101101
role = role.get_name()
102102
if not isinstance(role, six.string_types):
103-
raise TypeError('role must be a leancloud.Role or str')
104-
return self.get_write_access('role:{0}'.format(role))
103+
raise TypeError("role must be a leancloud.Role or str")
104+
return self.get_write_access("role:{0}".format(role))

leancloud/app_router.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ def __init__(self, app_id, region):
2020
self.session = requests.Session()
2121
self.lock = threading.Lock()
2222
self.expired_at = 0
23-
23+
2424
prefix = app_id[:8].lower()
25-
domain = 'lncld.net'
25+
domain = "lncld.net"
2626

27-
if region == 'US':
28-
domain = 'lncldglobal.com'
29-
elif region == 'CN':
30-
if app_id.endswith('-9Nh9j0Va'):
31-
domain = 'lncldapi.com'
32-
elif app_id.endswith('-MdYXbMMI'):
33-
domain = 'lncldglobal.com'
27+
if region == "US":
28+
domain = "lncldglobal.com"
29+
elif region == "CN":
30+
if app_id.endswith("-9Nh9j0Va"):
31+
domain = "lncldapi.com"
32+
elif app_id.endswith("-MdYXbMMI"):
33+
domain = "lncldglobal.com"
3434
else:
35-
domain = 'lncld.net'
35+
domain = "lncld.net"
3636
else:
37-
raise RuntimeError('invalid region: {}'.format(region))
37+
raise RuntimeError("invalid region: {}".format(region))
3838

39-
self.hosts['api'] = '{}.api.{}'.format(prefix, domain)
40-
self.hosts['engine'] = '{}.engine.{}'.format(prefix, domain)
41-
self.hosts['stats'] = '{}.stats.{}'.format(prefix, domain)
42-
self.hosts['push'] = '{}.push.{}'.format(prefix, domain)
39+
self.hosts["api"] = "{}.api.{}".format(prefix, domain)
40+
self.hosts["engine"] = "{}.engine.{}".format(prefix, domain)
41+
self.hosts["stats"] = "{}.stats.{}".format(prefix, domain)
42+
self.hosts["push"] = "{}.push.{}".format(prefix, domain)
4343

4444
def get(self, type_):
4545
with self.lock:
@@ -49,17 +49,17 @@ def get(self, type_):
4949
return self.hosts[type_]
5050

5151
def refresh(self):
52-
url = 'https://app-router.com/2/route?appId={}'.format(self.app_id)
52+
url = "https://app-router.com/2/route?appId={}".format(self.app_id)
5353
try:
5454
result = self.session.get(url, timeout=5).json()
5555
with self.lock:
5656
self.update(result)
5757
except Exception as e:
58-
print('refresh app router failed:', e, file=sys.stderr)
58+
print("refresh app router failed:", e, file=sys.stderr)
5959

6060
def update(self, content):
61-
self.hosts['api'] = content['api_server']
62-
self.hosts['engine'] = content['engine_server']
63-
self.hosts['stats'] = content['stats_server']
64-
self.hosts['push'] = content['push_server']
65-
self.expired_at = time.time() + content['ttl']
61+
self.hosts["api"] = content["api_server"]
62+
self.hosts["engine"] = content["engine_server"]
63+
self.hosts["stats"] = content["stats_server"]
64+
self.hosts["push"] = content["push_server"]
65+
self.expired_at = time.time() + content["ttl"]

0 commit comments

Comments
 (0)