mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-19 16:03:00 +00:00
Correct style spacing
This commit is contained in:
@@ -26,10 +26,12 @@ def random_port():
|
||||
sock.close()
|
||||
return port
|
||||
|
||||
|
||||
# ISO8601 for strptime with/without milliseconds
|
||||
ISO8601_ms = '%Y-%m-%dT%H:%M:%S.%fZ'
|
||||
ISO8601_s = '%Y-%m-%dT%H:%M:%SZ'
|
||||
|
||||
|
||||
def can_connect(ip, port):
|
||||
"""Check if we can connect to an ip:port.
|
||||
|
||||
@@ -39,13 +41,12 @@ def can_connect(ip, port):
|
||||
socket.create_connection((ip, port))
|
||||
except socket.error as e:
|
||||
if e.errno not in {errno.ECONNREFUSED, errno.ETIMEDOUT}:
|
||||
app_log.error("Unexpected error connecting to %s:%i %s",
|
||||
ip, port, e
|
||||
)
|
||||
app_log.error("Unexpected error connecting to %s:%i %s", ip, port, e)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
@gen.coroutine
|
||||
def wait_for_server(ip, port, timeout=10):
|
||||
"""Wait for any server to show up at ip:port."""
|
||||
@@ -56,9 +57,10 @@ def wait_for_server(ip, port, timeout=10):
|
||||
return
|
||||
else:
|
||||
yield gen.sleep(0.1)
|
||||
raise TimeoutError("Server at {ip}:{port} didn't respond in {timeout} seconds".format(
|
||||
**locals()
|
||||
))
|
||||
raise TimeoutError(
|
||||
"Server at {ip}:{port} didn't respond in {timeout} seconds".format(**locals())
|
||||
)
|
||||
|
||||
|
||||
@gen.coroutine
|
||||
def wait_for_http_server(url, timeout=10):
|
||||
@@ -78,7 +80,8 @@ def wait_for_http_server(url, timeout=10):
|
||||
if e.code != 599:
|
||||
# we expect 599 for no connection,
|
||||
# but 502 or other proxy error is conceivable
|
||||
app_log.warning("Server at %s responded with error: %s", url, e.code)
|
||||
app_log.warning(
|
||||
"Server at %s responded with error: %s", url, e.code)
|
||||
yield gen.sleep(0.1)
|
||||
else:
|
||||
app_log.debug("Server at %s responded with %s", url, e.code)
|
||||
@@ -90,9 +93,9 @@ def wait_for_http_server(url, timeout=10):
|
||||
else:
|
||||
return
|
||||
|
||||
raise TimeoutError("Server at {url} didn't respond in {timeout} seconds".format(
|
||||
**locals()
|
||||
))
|
||||
raise TimeoutError(
|
||||
"Server at {url} didn't respond in {timeout} seconds".format(**locals())
|
||||
)
|
||||
|
||||
|
||||
# Decorators for authenticated Handlers
|
||||
@@ -115,6 +118,7 @@ def auth_decorator(check_auth):
|
||||
decorator.__doc__ = check_auth.__doc__
|
||||
return decorator
|
||||
|
||||
|
||||
@auth_decorator
|
||||
def token_authenticated(self):
|
||||
"""Decorator for method authenticated only by Authorization token header.
|
||||
@@ -124,6 +128,7 @@ def token_authenticated(self):
|
||||
if self.get_current_user_token() is None:
|
||||
raise web.HTTPError(403)
|
||||
|
||||
|
||||
@auth_decorator
|
||||
def authenticated_403(self):
|
||||
"""Decorator for method to raise 403 error instead of redirect to login.
|
||||
@@ -134,6 +139,7 @@ def authenticated_403(self):
|
||||
if self.get_current_user() is None:
|
||||
raise web.HTTPError(403)
|
||||
|
||||
|
||||
@auth_decorator
|
||||
def admin_only(self):
|
||||
"""Decorator for restricting access to admin users."""
|
||||
@@ -208,4 +214,3 @@ def url_path_join(*pieces):
|
||||
result = '/'
|
||||
|
||||
return result
|
||||
|
||||
|
Reference in New Issue
Block a user