[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot]
2023-02-07 04:40:22 +00:00
parent 637cafcf6e
commit be07c7ef31
17 changed files with 15 additions and 15 deletions

View File

@@ -32,6 +32,7 @@ if os.environ.get("JUPYTERHUB_OAUTH_SCOPES"):
else: else:
access_scopes = ["access:services"] access_scopes = ["access:services"]
### For consideration: optimize performance with a cache instead of ### For consideration: optimize performance with a cache instead of
### always hitting the Hub api? ### always hitting the Hub api?
async def get_current_user( async def get_current_user(

View File

@@ -83,6 +83,7 @@ def lru_cache_key(key_func, maxsize=1024):
def cache_func(func): def cache_func(func):
cache = LRUCache(maxsize=maxsize) cache = LRUCache(maxsize=maxsize)
# the actual decorated function: # the actual decorated function:
@wraps(func) @wraps(func)
def cached(*args, **kwargs): def cached(*args, **kwargs):

View File

@@ -2929,7 +2929,6 @@ class JupyterHub(Application):
init_spawners_future.add_done_callback(log_init_time) init_spawners_future.add_done_callback(log_init_time)
try: try:
# don't allow a zero timeout because we still need to be sure # don't allow a zero timeout because we still need to be sure
# that the Spawner objects are defined and pending # that the Spawner objects are defined and pending
await gen.with_timeout( await gen.with_timeout(

View File

@@ -357,6 +357,7 @@ class Authenticator(LoggingConfigurable):
), ),
DeprecationWarning, DeprecationWarning,
) )
# use old name instead of new # use old name instead of new
# if old name is overridden in subclass # if old name is overridden in subclass
def _new_calls_old(old_name, *args, **kwargs): def _new_calls_old(old_name, *args, **kwargs):

View File

@@ -664,7 +664,12 @@ class BaseHandler(RequestHandler):
next_url = "//" + next_url.lstrip("/") next_url = "//" + next_url.lstrip("/")
parsed_next_url = urlparse(next_url) parsed_next_url = urlparse(next_url)
if (next_url + '/').startswith((f'{proto}://{host}/', f'//{host}/',)) or ( if (next_url + '/').startswith(
(
f'{proto}://{host}/',
f'//{host}/',
)
) or (
self.subdomain_host self.subdomain_host
and parsed_next_url.netloc and parsed_next_url.netloc
and ("." + parsed_next_url.netloc).endswith( and ("." + parsed_next_url.netloc).endswith(

View File

@@ -685,7 +685,7 @@ def _check_scope_access(api_handler, req_scope, **kwargs):
req_scope, req_scope,
) )
return True return True
for (filter_, filter_value) in kwargs.items(): for filter_, filter_value in kwargs.items():
if filter_ in sub_scope and filter_value in sub_scope[filter_]: if filter_ in sub_scope and filter_value in sub_scope[filter_]:
app_log.debug("Argument-based access to %s via %s", api_name, req_scope) app_log.debug("Argument-based access to %s via %s", api_name, req_scope)
return True return True

View File

@@ -1146,6 +1146,7 @@ class HubAuthenticated:
except UserNotAllowed as e: except UserNotAllowed as e:
# cache None, in case get_user is called again while processing the error # cache None, in case get_user is called again while processing the error
self._hub_auth_user_cache = None self._hub_auth_user_cache = None
# Override redirect so if/when tornado @web.authenticated # Override redirect so if/when tornado @web.authenticated
# tries to redirect to login URL, 403 will be raised instead. # tries to redirect to login URL, 403 will be raised instead.
# This is not the best, but avoids problems that can be caused # This is not the best, but avoids problems that can be caused

View File

@@ -957,6 +957,7 @@ def make_singleuser_app(App):
merged_flags = {} merged_flags = {}
merged_flags.update(empty_parent_app.flags or {}) merged_flags.update(empty_parent_app.flags or {})
merged_flags.update(flags) merged_flags.update(flags)
# create mixed-in App class, bringing it all together # create mixed-in App class, bringing it all together
class SingleUserNotebookApp(SingleUserNotebookAppMixin, App): class SingleUserNotebookApp(SingleUserNotebookAppMixin, App):
aliases = merged_aliases aliases = merged_aliases

View File

@@ -290,7 +290,6 @@ async def _mockservice(request, app, external=False, url=False):
spec['url'] = 'http://127.0.0.1:%i' % random_port() spec['url'] = 'http://127.0.0.1:%i' % random_port()
if external: if external:
spec['oauth_redirect_uri'] = 'http://127.0.0.1:%i' % random_port() spec['oauth_redirect_uri'] = 'http://127.0.0.1:%i' % random_port()
event_loop = asyncio.get_running_loop() event_loop = asyncio.get_running_loop()

View File

@@ -168,7 +168,6 @@ async def test_open_url_login(
form_action, form_action,
user, user,
): ):
await open_url(app, browser, path=url) await open_url(app, browser, path=url)
url_new = url_path_join(public_host(app), app.hub.base_url, url_concat(url, params)) url_new = url_path_join(public_host(app), app.hub.base_url, url_concat(url, params))
await in_thread(browser.get, url_new) await in_thread(browser.get, url_new)

View File

@@ -233,7 +233,6 @@ def test_cookie_secret_string_():
async def test_load_groups(tmpdir, request): async def test_load_groups(tmpdir, request):
to_load = { to_load = {
'blue': { 'blue': {
'users': ['cyclops', 'rogue', 'wolverine'], 'users': ['cyclops', 'rogue', 'wolverine'],

View File

@@ -559,7 +559,6 @@ class MockGroupsAuthenticator(auth.Authenticator):
async def test_auth_managed_groups( async def test_auth_managed_groups(
app, user, group, authenticated_groups, refresh_groups app, user, group, authenticated_groups, refresh_groups
): ):
authenticator = MockGroupsAuthenticator( authenticator = MockGroupsAuthenticator(
parent=app, parent=app,
authenticated_groups=authenticated_groups, authenticated_groups=authenticated_groups,

View File

@@ -25,7 +25,6 @@ def test_lru_cache():
def test_lru_cache_key(): def test_lru_cache_key():
call_count = 0 call_count = 0
@lru_cache_key(frozenset) @lru_cache_key(frozenset)
@@ -47,7 +46,6 @@ def test_lru_cache_key():
def test_do_not_cache(): def test_do_not_cache():
call_count = 0 call_count = 0
@lru_cache_key(lambda arg: arg) @lru_cache_key(lambda arg: arg)

View File

@@ -1243,7 +1243,6 @@ async def test_admin_role_respects_config():
], ],
) )
async def test_admin_role_membership(in_db, role_users, admin_users, expected_members): async def test_admin_role_membership(in_db, role_users, admin_users, expected_members):
load_roles = [] load_roles = []
if role_users is not None: if role_users is not None:
load_roles.append({"name": "admin", "users": role_users}) load_roles.append({"name": "admin", "users": role_users})

View File

@@ -971,7 +971,6 @@ def test_intersect_groups(request, db, left, right, expected, groups):
async def test_list_users_filter( async def test_list_users_filter(
app, group, create_service_with_scopes, scopes, expected app, group, create_service_with_scopes, scopes, expected
): ):
# create users: # create users:
for i in (1, 2): for i in (1, 2):
user = add_user(app.db, app, name=f'in-{i}') user = add_user(app.db, app, name=f'in-{i}')
@@ -1028,7 +1027,6 @@ async def test_list_users_filter(
async def test_list_groups_filter( async def test_list_groups_filter(
request, app, create_service_with_scopes, scopes, expected request, app, create_service_with_scopes, scopes, expected
): ):
# create groups: # create groups:
groups = [] groups = []
for i in (1, 2, 3): for i in (1, 2, 3):

View File

@@ -710,7 +710,7 @@ def get_accepted_mimetype(accept_header, choices=None):
Return `None` if choices is given and no match is found, Return `None` if choices is given and no match is found,
or nothing is specified. or nothing is specified.
""" """
for (mime, params, q) in _parse_accept_header(accept_header): for mime, params, q in _parse_accept_header(accept_header):
if choices: if choices:
if mime in choices: if mime in choices:
return mime return mime

View File

@@ -38,7 +38,7 @@ def get_data_files():
"""Get data files in share/jupyter""" """Get data files in share/jupyter"""
data_files = [] data_files = []
for (d, dirs, filenames) in os.walk(share_jupyterhub): for d, dirs, filenames in os.walk(share_jupyterhub):
rel_d = os.path.relpath(d, here) rel_d = os.path.relpath(d, here)
data_files.append((rel_d, [os.path.join(rel_d, f) for f in filenames])) data_files.append((rel_d, [os.path.join(rel_d, f) for f in filenames]))
return data_files return data_files
@@ -237,7 +237,7 @@ class CSS(BaseCommand):
earliest_target = sorted(mtime(t) for t in targets)[0] earliest_target = sorted(mtime(t) for t in targets)[0]
# check if any .less files are newer than the generated targets # check if any .less files are newer than the generated targets
for (dirpath, dirnames, filenames) in os.walk(static): for dirpath, dirnames, filenames in os.walk(static):
for f in filenames: for f in filenames:
if f.endswith('.less'): if f.endswith('.less'):
path = pjoin(static, dirpath, f) path = pjoin(static, dirpath, f)