mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-08 10:34:10 +00:00
apply pyupgrade fixes via ruff
ruff check --fix --select UP
This commit is contained in:
@@ -25,6 +25,4 @@ import os
|
|||||||
|
|
||||||
pg_pass = os.getenv('POSTGRES_ENV_JPY_PSQL_PASSWORD')
|
pg_pass = os.getenv('POSTGRES_ENV_JPY_PSQL_PASSWORD')
|
||||||
pg_host = os.getenv('POSTGRES_PORT_5432_TCP_ADDR')
|
pg_host = os.getenv('POSTGRES_PORT_5432_TCP_ADDR')
|
||||||
c.JupyterHub.db_url = 'postgresql://jupyterhub:{}@{}:5432/jupyterhub'.format(
|
c.JupyterHub.db_url = f'postgresql://jupyterhub:{pg_pass}@{pg_host}:5432/jupyterhub'
|
||||||
pg_pass, pg_host
|
|
||||||
)
|
|
||||||
|
@@ -11,7 +11,7 @@ c = get_config() # noqa
|
|||||||
class DemoFormSpawner(LocalProcessSpawner):
|
class DemoFormSpawner(LocalProcessSpawner):
|
||||||
def _options_form_default(self):
|
def _options_form_default(self):
|
||||||
default_env = "YOURNAME=%s\n" % self.user.name
|
default_env = "YOURNAME=%s\n" % self.user.name
|
||||||
return """
|
return f"""
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="args">Extra notebook CLI arguments</label>
|
<label for="args">Extra notebook CLI arguments</label>
|
||||||
<input name="args" class="form-control"
|
<input name="args" class="form-control"
|
||||||
@@ -19,11 +19,9 @@ class DemoFormSpawner(LocalProcessSpawner):
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="env">Environment variables (one per line)</label>
|
<label for="env">Environment variables (one per line)</label>
|
||||||
<textarea class="form-control" name="env">{env}</textarea>
|
<textarea class="form-control" name="env">{default_env}</textarea>
|
||||||
</div>
|
</div>
|
||||||
""".format(
|
"""
|
||||||
env=default_env
|
|
||||||
)
|
|
||||||
|
|
||||||
def options_from_form(self, formdata):
|
def options_from_form(self, formdata):
|
||||||
options = {}
|
options = {}
|
||||||
|
@@ -29,11 +29,10 @@ def upgrade():
|
|||||||
# fill created date with current time
|
# fill created date with current time
|
||||||
now = utcnow()
|
now = utcnow()
|
||||||
c.execute(
|
c.execute(
|
||||||
"""
|
f"""
|
||||||
UPDATE users
|
UPDATE users
|
||||||
SET created='%s'
|
SET created='{now}'
|
||||||
"""
|
"""
|
||||||
% (now,)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
tables = sa.inspect(c.engine).get_table_names()
|
tables = sa.inspect(c.engine).get_table_names()
|
||||||
@@ -42,12 +41,11 @@ def upgrade():
|
|||||||
op.add_column('spawners', sa.Column('started', sa.DateTime, nullable=True))
|
op.add_column('spawners', sa.Column('started', sa.DateTime, nullable=True))
|
||||||
# fill started value with now for running servers
|
# fill started value with now for running servers
|
||||||
c.execute(
|
c.execute(
|
||||||
"""
|
f"""
|
||||||
UPDATE spawners
|
UPDATE spawners
|
||||||
SET started='%s'
|
SET started='{now}'
|
||||||
WHERE server_id IS NOT NULL
|
WHERE server_id IS NOT NULL
|
||||||
"""
|
"""
|
||||||
% (now,)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ class APIHandler(BaseHandler):
|
|||||||
return 'application/json'
|
return 'application/json'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lru_cache()
|
@lru_cache
|
||||||
def accepts_pagination(self):
|
def accepts_pagination(self):
|
||||||
"""Return whether the client accepts the pagination preview media type"""
|
"""Return whether the client accepts the pagination preview media type"""
|
||||||
accept_header = self.request.headers.get("Accept", "")
|
accept_header = self.request.headers.get("Accept", "")
|
||||||
@@ -460,8 +460,7 @@ class APIHandler(BaseHandler):
|
|||||||
if not isinstance(value, model_types[key]):
|
if not isinstance(value, model_types[key]):
|
||||||
raise web.HTTPError(
|
raise web.HTTPError(
|
||||||
400,
|
400,
|
||||||
"%s.%s must be %s, not: %r"
|
f"{name}.{key} must be {model_types[key]}, not: {type(value)!r}",
|
||||||
% (name, key, model_types[key], type(value)),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def _check_user_model(self, model):
|
def _check_user_model(self, model):
|
||||||
|
@@ -782,7 +782,7 @@ class SpawnProgressAPIHandler(APIHandler):
|
|||||||
'progress': 100,
|
'progress': 100,
|
||||||
'ready': True,
|
'ready': True,
|
||||||
'message': f"Server ready at {url}",
|
'message': f"Server ready at {url}",
|
||||||
'html_message': 'Server ready at <a href="{0}">{0}</a>'.format(url),
|
'html_message': f'Server ready at <a href="{url}">{url}</a>',
|
||||||
'url': url,
|
'url': url,
|
||||||
}
|
}
|
||||||
original_ready_event = ready_event.copy()
|
original_ready_event = ready_event.copy()
|
||||||
@@ -881,9 +881,7 @@ def _parse_timestamp(timestamp):
|
|||||||
if (dt - now) > timedelta(minutes=59):
|
if (dt - now) > timedelta(minutes=59):
|
||||||
raise web.HTTPError(
|
raise web.HTTPError(
|
||||||
400,
|
400,
|
||||||
"Rejecting activity from more than an hour in the future: {}".format(
|
f"Rejecting activity from more than an hour in the future: {isoformat(dt)}",
|
||||||
isoformat(dt)
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return dt
|
return dt
|
||||||
|
|
||||||
|
@@ -24,8 +24,6 @@ from textwrap import dedent
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
from urllib.parse import unquote, urlparse, urlunparse
|
from urllib.parse import unquote, urlparse, urlunparse
|
||||||
|
|
||||||
if sys.version_info[:2] < (3, 3):
|
|
||||||
raise ValueError("Python < 3.3 not supported: %s" % sys.version)
|
|
||||||
|
|
||||||
import tornado.httpserver
|
import tornado.httpserver
|
||||||
import tornado.options
|
import tornado.options
|
||||||
@@ -385,9 +383,7 @@ class JupyterHub(Application):
|
|||||||
def _validate_config_file(self, proposal):
|
def _validate_config_file(self, proposal):
|
||||||
if not self.generate_config and not os.path.isfile(proposal.value):
|
if not self.generate_config and not os.path.isfile(proposal.value):
|
||||||
print(
|
print(
|
||||||
"ERROR: Failed to find specified config file: {}".format(
|
f"ERROR: Failed to find specified config file: {proposal.value}",
|
||||||
proposal.value
|
|
||||||
),
|
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -1581,7 +1577,7 @@ class JupyterHub(Application):
|
|||||||
if change.new:
|
if change.new:
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
dedent(
|
dedent(
|
||||||
"""
|
f"""
|
||||||
extra_log_file is DEPRECATED in jupyterhub-0.8.2.
|
extra_log_file is DEPRECATED in jupyterhub-0.8.2.
|
||||||
|
|
||||||
extra_log_file only redirects logs of the Hub itself,
|
extra_log_file only redirects logs of the Hub itself,
|
||||||
@@ -1591,10 +1587,8 @@ class JupyterHub(Application):
|
|||||||
It is STRONGLY recommended that you redirect process
|
It is STRONGLY recommended that you redirect process
|
||||||
output instead, e.g.
|
output instead, e.g.
|
||||||
|
|
||||||
jupyterhub &>> '{}'
|
jupyterhub &>> '{change.new}'
|
||||||
""".format(
|
"""
|
||||||
change.new
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1962,9 +1956,7 @@ class JupyterHub(Application):
|
|||||||
if urlinfo.password:
|
if urlinfo.password:
|
||||||
# avoid logging the database password
|
# avoid logging the database password
|
||||||
urlinfo = urlinfo._replace(
|
urlinfo = urlinfo._replace(
|
||||||
netloc='{}:[redacted]@{}:{}'.format(
|
netloc=f'{urlinfo.username}:[redacted]@{urlinfo.hostname}:{urlinfo.port}'
|
||||||
urlinfo.username, urlinfo.hostname, urlinfo.port
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
db_log_url = urlinfo.geturl()
|
db_log_url = urlinfo.geturl()
|
||||||
else:
|
else:
|
||||||
@@ -3496,9 +3488,7 @@ class JupyterHub(Application):
|
|||||||
self.internal_ssl = True
|
self.internal_ssl = True
|
||||||
self.init_internal_ssl()
|
self.init_internal_ssl()
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"Certificates written to directory `{}`".format(
|
f"Certificates written to directory `{self.internal_certs_location}`"
|
||||||
self.internal_certs_location
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
loop.stop()
|
loop.stop()
|
||||||
return
|
return
|
||||||
|
@@ -820,13 +820,8 @@ def _deprecated_method(old_name, new_name, version):
|
|||||||
def deprecated(self, *args, **kwargs):
|
def deprecated(self, *args, **kwargs):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
(
|
(
|
||||||
"{cls}.{old_name} is deprecated in JupyterHub {version}."
|
f"{self.__class__.__name__}.{old_name} is deprecated in JupyterHub {version}."
|
||||||
" Please use {cls}.{new_name} instead."
|
f" Please use {self.__class__.__name__}.{new_name} instead."
|
||||||
).format(
|
|
||||||
cls=self.__class__.__name__,
|
|
||||||
old_name=old_name,
|
|
||||||
new_name=new_name,
|
|
||||||
version=version,
|
|
||||||
),
|
),
|
||||||
DeprecationWarning,
|
DeprecationWarning,
|
||||||
stacklevel=2,
|
stacklevel=2,
|
||||||
@@ -961,11 +956,9 @@ class LocalAuthenticator(Authenticator):
|
|||||||
await maybe_future(self.add_system_user(user))
|
await maybe_future(self.add_system_user(user))
|
||||||
else:
|
else:
|
||||||
raise KeyError(
|
raise KeyError(
|
||||||
"User {} does not exist on the system."
|
f"User {user.name} does not exist on the system."
|
||||||
" Set LocalAuthenticator.create_system_users=True"
|
" Set LocalAuthenticator.create_system_users=True"
|
||||||
" to automatically create system users from jupyterhub users.".format(
|
" to automatically create system users from jupyterhub users."
|
||||||
user.name
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
await maybe_future(super().add_user(user))
|
await maybe_future(super().add_user(user))
|
||||||
|
@@ -121,9 +121,7 @@ def upgrade_if_needed(db_url, backup=True, log=None):
|
|||||||
if urlinfo.password:
|
if urlinfo.password:
|
||||||
# avoid logging the database password
|
# avoid logging the database password
|
||||||
urlinfo = urlinfo._replace(
|
urlinfo = urlinfo._replace(
|
||||||
netloc='{}:[redacted]@{}:{}'.format(
|
netloc=f'{urlinfo.username}:[redacted]@{urlinfo.hostname}:{urlinfo.port}'
|
||||||
urlinfo.username, urlinfo.hostname, urlinfo.port
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
db_log_url = urlinfo.geturl()
|
db_log_url = urlinfo.geturl()
|
||||||
else:
|
else:
|
||||||
|
@@ -372,7 +372,7 @@ class BaseHandler(RequestHandler):
|
|||||||
auth_info['auth_state'] = await user.get_auth_state()
|
auth_info['auth_state'] = await user.get_auth_state()
|
||||||
return await self.auth_to_user(auth_info, user)
|
return await self.auth_to_user(auth_info, user)
|
||||||
|
|
||||||
@functools.lru_cache()
|
@functools.lru_cache
|
||||||
def get_token(self):
|
def get_token(self):
|
||||||
"""get token from authorization header"""
|
"""get token from authorization header"""
|
||||||
token = self.get_auth_token()
|
token = self.get_auth_token()
|
||||||
@@ -473,7 +473,7 @@ class BaseHandler(RequestHandler):
|
|||||||
self.expanded_scopes = scopes.get_scopes_for(self.current_user)
|
self.expanded_scopes = scopes.get_scopes_for(self.current_user)
|
||||||
self.parsed_scopes = scopes.parse_scopes(self.expanded_scopes)
|
self.parsed_scopes = scopes.parse_scopes(self.expanded_scopes)
|
||||||
|
|
||||||
@functools.lru_cache()
|
@functools.lru_cache
|
||||||
def get_scope_filter(self, req_scope):
|
def get_scope_filter(self, req_scope):
|
||||||
"""Produce a filter function for req_scope on resources
|
"""Produce a filter function for req_scope on resources
|
||||||
|
|
||||||
@@ -981,9 +981,7 @@ class BaseHandler(RequestHandler):
|
|||||||
)
|
)
|
||||||
err = web.HTTPError(
|
err = web.HTTPError(
|
||||||
429,
|
429,
|
||||||
"Too many users trying to log in right now. Try again in {}.".format(
|
f"Too many users trying to log in right now. Try again in {human_retry_time}.",
|
||||||
human_retry_time
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
# can't call set_header directly here because it gets ignored
|
# can't call set_header directly here because it gets ignored
|
||||||
# when errors are raised
|
# when errors are raised
|
||||||
@@ -1155,8 +1153,7 @@ class BaseHandler(RequestHandler):
|
|||||||
|
|
||||||
raise web.HTTPError(
|
raise web.HTTPError(
|
||||||
500,
|
500,
|
||||||
"Spawner failed to start [status=%s]. The logs for %s may contain details."
|
f"Spawner failed to start [status={status}]. The logs for {spawner._log_name} may contain details.",
|
||||||
% (status, spawner._log_name),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if spawner._waiting_for_response:
|
if spawner._waiting_for_response:
|
||||||
@@ -1295,7 +1292,7 @@ class BaseHandler(RequestHandler):
|
|||||||
home = url_path_join(self.hub.base_url, 'home')
|
home = url_path_join(self.hub.base_url, 'home')
|
||||||
return (
|
return (
|
||||||
"You can try restarting your server from the "
|
"You can try restarting your server from the "
|
||||||
"<a href='{home}'>home page</a>.".format(home=home)
|
f"<a href='{home}'>home page</a>."
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_template(self, name, sync=False):
|
def get_template(self, name, sync=False):
|
||||||
|
@@ -163,9 +163,7 @@ class Server(HasTraits):
|
|||||||
return f"{self.host}{self.base_url}"
|
return f"{self.host}{self.base_url}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "{name}(url={url}, bind_url={bind})".format(
|
return f"{self.__class__.__name__}(url={self.url}, bind_url={self.bind_url})"
|
||||||
name=self.__class__.__name__, url=self.url, bind=self.bind_url
|
|
||||||
)
|
|
||||||
|
|
||||||
def wait_up(self, timeout=10, http=False, ssl_context=None, extra_path=""):
|
def wait_up(self, timeout=10, http=False, ssl_context=None, extra_path=""):
|
||||||
"""Wait for this server to come up"""
|
"""Wait for this server to come up"""
|
||||||
|
@@ -730,7 +730,7 @@ class _Share:
|
|||||||
return cls._apply_filter(frozenset(scopes), spawner.user.name, spawner.name)
|
return cls._apply_filter(frozenset(scopes), spawner.user.name, spawner.name)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@lru_cache()
|
@lru_cache
|
||||||
def _apply_filter(scopes, owner_name, server_name):
|
def _apply_filter(scopes, owner_name, server_name):
|
||||||
"""
|
"""
|
||||||
implementation of Share.apply_filter
|
implementation of Share.apply_filter
|
||||||
@@ -1518,11 +1518,9 @@ def check_db_revision(engine):
|
|||||||
app_log.debug("database schema version found: %s", alembic_revision)
|
app_log.debug("database schema version found: %s", alembic_revision)
|
||||||
else:
|
else:
|
||||||
raise DatabaseSchemaMismatch(
|
raise DatabaseSchemaMismatch(
|
||||||
"Found database schema version {found} != {head}. "
|
f"Found database schema version {alembic_revision} != {head}. "
|
||||||
"Backup your database and run `jupyterhub upgrade-db`"
|
"Backup your database and run `jupyterhub upgrade-db`"
|
||||||
" to upgrade to the latest schema.".format(
|
" to upgrade to the latest schema."
|
||||||
found=alembic_revision, head=head
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -337,8 +337,7 @@ class Proxy(LoggingConfigurable):
|
|||||||
|
|
||||||
if spawner.pending and spawner.pending != 'spawn':
|
if spawner.pending and spawner.pending != 'spawn':
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"%s is pending %s, shouldn't be added to the proxy yet!"
|
f"{spawner._log_name} is pending {spawner.pending}, shouldn't be added to the proxy yet!"
|
||||||
% (spawner._log_name, spawner.pending)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.add_route(
|
await self.add_route(
|
||||||
@@ -941,9 +940,7 @@ class ConfigurableHTTPProxy(Proxy):
|
|||||||
# errors.
|
# errors.
|
||||||
if e.code >= 500:
|
if e.code >= 500:
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
"api_request to the proxy failed with status code {}, retrying...".format(
|
f"api_request to the proxy failed with status code {e.code}, retrying..."
|
||||||
e.code
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
return False # a falsy return value make exponential_backoff retry
|
return False # a falsy return value make exponential_backoff retry
|
||||||
else:
|
else:
|
||||||
|
@@ -212,7 +212,7 @@ def _intersect_expanded_scopes(scopes_a, scopes_b, db=None):
|
|||||||
scopes_b = frozenset(scopes_b)
|
scopes_b = frozenset(scopes_b)
|
||||||
|
|
||||||
# cached lookups for group membership of users and servers
|
# cached lookups for group membership of users and servers
|
||||||
@lru_cache()
|
@lru_cache
|
||||||
def groups_for_user(username):
|
def groups_for_user(username):
|
||||||
"""Get set of group names for a given username"""
|
"""Get set of group names for a given username"""
|
||||||
# if we need a group lookup, the result is not cacheable
|
# if we need a group lookup, the result is not cacheable
|
||||||
@@ -225,7 +225,7 @@ def _intersect_expanded_scopes(scopes_a, scopes_b, db=None):
|
|||||||
)
|
)
|
||||||
return {row[0] for row in group_query}
|
return {row[0] for row in group_query}
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache
|
||||||
def groups_for_server(server):
|
def groups_for_server(server):
|
||||||
"""Get set of group names for a given server"""
|
"""Get set of group names for a given server"""
|
||||||
username, _, servername = server.partition("/")
|
username, _, servername = server.partition("/")
|
||||||
@@ -456,7 +456,7 @@ def expand_share_scopes(share):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache
|
||||||
def _expand_self_scope(username):
|
def _expand_self_scope(username):
|
||||||
"""
|
"""
|
||||||
Users have a metascope 'self' that should be expanded to standard user privileges.
|
Users have a metascope 'self' that should be expanded to standard user privileges.
|
||||||
|
@@ -1194,7 +1194,7 @@ async def test_progress(request, app, no_patience, slow_spawn):
|
|||||||
assert evt == {
|
assert evt == {
|
||||||
'progress': 100,
|
'progress': 100,
|
||||||
'message': f'Server ready at {url}',
|
'message': f'Server ready at {url}',
|
||||||
'html_message': 'Server ready at <a href="{0}">{0}</a>'.format(url),
|
'html_message': f'Server ready at <a href="{url}">{url}</a>',
|
||||||
'url': url,
|
'url': url,
|
||||||
'ready': True,
|
'ready': True,
|
||||||
}
|
}
|
||||||
@@ -1307,7 +1307,7 @@ async def test_progress_ready_hook_async_func_exception(request, app):
|
|||||||
db = app.db
|
db = app.db
|
||||||
name = 'saga'
|
name = 'saga'
|
||||||
app_user = add_user(db, app=app, name=name)
|
app_user = add_user(db, app=app, name=name)
|
||||||
html_message = 'Server ready at <a href="{0}">{0}</a>'.format(app_user.url)
|
html_message = f'Server ready at <a href="{app_user.url}">{app_user.url}</a>'
|
||||||
spawner = app_user.spawner
|
spawner = app_user.spawner
|
||||||
|
|
||||||
async def custom_progress_ready_hook(spawner, ready_event):
|
async def custom_progress_ready_hook(spawner, ready_event):
|
||||||
|
@@ -85,9 +85,7 @@ async def test_default_server(app, named_servers):
|
|||||||
'pending': None,
|
'pending': None,
|
||||||
'ready': True,
|
'ready': True,
|
||||||
'stopped': False,
|
'stopped': False,
|
||||||
'progress_url': 'PREFIX/hub/api/users/{}/server/progress'.format(
|
'progress_url': f'PREFIX/hub/api/users/{username}/server/progress',
|
||||||
username
|
|
||||||
),
|
|
||||||
'state': {'pid': 0},
|
'state': {'pid': 0},
|
||||||
'user_options': {},
|
'user_options': {},
|
||||||
}
|
}
|
||||||
|
@@ -82,16 +82,12 @@ class ByteSpecification(Integer):
|
|||||||
num = float(value[:-1])
|
num = float(value[:-1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise TraitError(
|
raise TraitError(
|
||||||
'{val} is not a valid memory specification. Must be an int or a string with suffix K, M, G, T'.format(
|
f'{value} is not a valid memory specification. Must be an int or a string with suffix K, M, G, T'
|
||||||
val=value
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
suffix = value[-1]
|
suffix = value[-1]
|
||||||
if suffix not in self.UNIT_SUFFIXES:
|
if suffix not in self.UNIT_SUFFIXES:
|
||||||
raise TraitError(
|
raise TraitError(
|
||||||
'{val} is not a valid memory specification. Must be an int or a string with suffix K, M, G, T'.format(
|
f'{value} is not a valid memory specification. Must be an int or a string with suffix K, M, G, T'
|
||||||
val=value
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return int(float(num) * self.UNIT_SUFFIXES[suffix])
|
return int(float(num) * self.UNIT_SUFFIXES[suffix])
|
||||||
|
@@ -897,9 +897,7 @@ class User:
|
|||||||
self.settings['statsd'].incr('spawner.failure.timeout')
|
self.settings['statsd'].incr('spawner.failure.timeout')
|
||||||
else:
|
else:
|
||||||
self.log.exception(
|
self.log.exception(
|
||||||
"Unhandled error starting {user}'s server: {error}".format(
|
f"Unhandled error starting {self.name}'s server: {e}"
|
||||||
user=self.name, error=e
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
self.settings['statsd'].incr('spawner.failure.error')
|
self.settings['statsd'].incr('spawner.failure.error')
|
||||||
e.reason = 'error'
|
e.reason = 'error'
|
||||||
@@ -907,9 +905,7 @@ class User:
|
|||||||
await self.stop(spawner.name)
|
await self.stop(spawner.name)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.log.exception(
|
self.log.exception(
|
||||||
"Failed to cleanup {user}'s server that failed to start".format(
|
f"Failed to cleanup {self.name}'s server that failed to start",
|
||||||
user=self.name
|
|
||||||
),
|
|
||||||
exc_info=True,
|
exc_info=True,
|
||||||
)
|
)
|
||||||
# raise original exception
|
# raise original exception
|
||||||
@@ -967,9 +963,7 @@ class User:
|
|||||||
await self.stop(spawner.name)
|
await self.stop(spawner.name)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.log.exception(
|
self.log.exception(
|
||||||
"Failed to cleanup {user}'s server that failed to start".format(
|
f"Failed to cleanup {self.name}'s server that failed to start",
|
||||||
user=self.name
|
|
||||||
),
|
|
||||||
exc_info=True,
|
exc_info=True,
|
||||||
)
|
)
|
||||||
# raise original TimeoutError
|
# raise original TimeoutError
|
||||||
|
@@ -253,9 +253,7 @@ async def wait_for_server(ip, port, timeout=10):
|
|||||||
tic = time.perf_counter()
|
tic = time.perf_counter()
|
||||||
await exponential_backoff(
|
await exponential_backoff(
|
||||||
lambda: can_connect(ip, port),
|
lambda: can_connect(ip, port),
|
||||||
"Server at {ip}:{port} didn't respond in {timeout} seconds".format(
|
f"Server at {ip}:{port} didn't respond in {timeout} seconds",
|
||||||
ip=ip, port=port, timeout=timeout
|
|
||||||
),
|
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
toc = time.perf_counter()
|
toc = time.perf_counter()
|
||||||
@@ -301,9 +299,7 @@ async def wait_for_http_server(url, timeout=10, ssl_context=None):
|
|||||||
|
|
||||||
re = await exponential_backoff(
|
re = await exponential_backoff(
|
||||||
is_reachable,
|
is_reachable,
|
||||||
"Server at {url} didn't respond in {timeout} seconds".format(
|
f"Server at {url} didn't respond in {timeout} seconds",
|
||||||
url=url, timeout=timeout
|
|
||||||
),
|
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
toc = time.perf_counter()
|
toc = time.perf_counter()
|
||||||
@@ -507,14 +503,12 @@ def print_ps_info(file=sys.stderr):
|
|||||||
threadlen = len('threads')
|
threadlen = len('threads')
|
||||||
|
|
||||||
print(
|
print(
|
||||||
"%s %s %s %s"
|
"{} {} {} {}".format('%CPU'.ljust(cpulen), 'MEM'.ljust(memlen), 'FDs'.ljust(fdlen), 'threads'),
|
||||||
% ('%CPU'.ljust(cpulen), 'MEM'.ljust(memlen), 'FDs'.ljust(fdlen), 'threads'),
|
|
||||||
file=file,
|
file=file,
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
"%s %s %s %s"
|
"{} {} {} {}".format(
|
||||||
% (
|
|
||||||
cpu_s.ljust(cpulen),
|
cpu_s.ljust(cpulen),
|
||||||
mem_s.ljust(memlen),
|
mem_s.ljust(memlen),
|
||||||
fd_s.ljust(fdlen),
|
fd_s.ljust(fdlen),
|
||||||
@@ -788,7 +782,7 @@ _dns_safe = set(string.ascii_letters + string.digits + '-.')
|
|||||||
_dns_needs_replace = _dns_safe | {"%"}
|
_dns_needs_replace = _dns_safe | {"%"}
|
||||||
|
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache
|
||||||
def _dns_quote(name):
|
def _dns_quote(name):
|
||||||
"""Escape a name for use in a dns label
|
"""Escape a name for use in a dns label
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user