mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 07:23:00 +00:00
Merge pull request #543 from robnagler:master
Allow jupyterhub-singleuser to run on python 2 install closes #543
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python
|
||||||
"""Extend regular notebook server to be aware of multiuser things."""
|
"""Extend regular notebook server to be aware of multiuser things."""
|
||||||
|
|
||||||
# Copyright (c) Jupyter Development Team.
|
# Copyright (c) Jupyter Development Team.
|
||||||
@@ -47,7 +47,7 @@ class JupyterHubLoginHandler(LoginHandler):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def login_available(settings):
|
def login_available(settings):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def verify_token(self, cookie_name, encrypted_cookie):
|
def verify_token(self, cookie_name, encrypted_cookie):
|
||||||
"""method for token verification"""
|
"""method for token verification"""
|
||||||
@@ -55,7 +55,7 @@ class JupyterHubLoginHandler(LoginHandler):
|
|||||||
if encrypted_cookie in cookie_cache:
|
if encrypted_cookie in cookie_cache:
|
||||||
# we've seen this token before, don't ask upstream again
|
# we've seen this token before, don't ask upstream again
|
||||||
return cookie_cache[encrypted_cookie]
|
return cookie_cache[encrypted_cookie]
|
||||||
|
|
||||||
hub_api_url = self.settings['hub_api_url']
|
hub_api_url = self.settings['hub_api_url']
|
||||||
hub_api_key = self.settings['hub_api_key']
|
hub_api_key = self.settings['hub_api_key']
|
||||||
r = requests.get(url_path_join(
|
r = requests.get(url_path_join(
|
||||||
@@ -78,7 +78,7 @@ class JupyterHubLoginHandler(LoginHandler):
|
|||||||
data = r.json()
|
data = r.json()
|
||||||
cookie_cache[encrypted_cookie] = data
|
cookie_cache[encrypted_cookie] = data
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_user(self):
|
def get_user(self):
|
||||||
"""alternative get_current_user to query the central server"""
|
"""alternative get_current_user to query the central server"""
|
||||||
@@ -87,7 +87,7 @@ class JupyterHubLoginHandler(LoginHandler):
|
|||||||
# since this may be called again when trying to render the error page
|
# since this may be called again when trying to render the error page
|
||||||
if hasattr(self, '_cached_user'):
|
if hasattr(self, '_cached_user'):
|
||||||
return self._cached_user
|
return self._cached_user
|
||||||
|
|
||||||
self._cached_user = None
|
self._cached_user = None
|
||||||
my_user = self.settings['user']
|
my_user = self.settings['user']
|
||||||
encrypted_cookie = self.get_cookie(self.cookie_name)
|
encrypted_cookie = self.get_cookie(self.cookie_name)
|
||||||
@@ -210,37 +210,37 @@ class SingleUserNotebookApp(NotebookApp):
|
|||||||
def _clear_cookie_cache(self):
|
def _clear_cookie_cache(self):
|
||||||
self.log.debug("Clearing cookie cache")
|
self.log.debug("Clearing cookie cache")
|
||||||
self.tornado_settings['cookie_cache'].clear()
|
self.tornado_settings['cookie_cache'].clear()
|
||||||
|
|
||||||
def migrate_config(self):
|
def migrate_config(self):
|
||||||
if self.disable_user_config:
|
if self.disable_user_config:
|
||||||
# disable config-migration when user config is disabled
|
# disable config-migration when user config is disabled
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
super(SingleUserNotebookApp, self).migrate_config()
|
super(SingleUserNotebookApp, self).migrate_config()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def config_file_paths(self):
|
def config_file_paths(self):
|
||||||
path = super(SingleUserNotebookApp, self).config_file_paths
|
path = super(SingleUserNotebookApp, self).config_file_paths
|
||||||
|
|
||||||
if self.disable_user_config:
|
if self.disable_user_config:
|
||||||
# filter out user-writable config dirs if user config is disabled
|
# filter out user-writable config dirs if user config is disabled
|
||||||
path = list(_exclude_home(path))
|
path = list(_exclude_home(path))
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nbextensions_path(self):
|
def nbextensions_path(self):
|
||||||
path = super(SingleUserNotebookApp, self).nbextensions_path
|
path = super(SingleUserNotebookApp, self).nbextensions_path
|
||||||
|
|
||||||
if self.disable_user_config:
|
if self.disable_user_config:
|
||||||
path = list(_exclude_home(path))
|
path = list(_exclude_home(path))
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def _static_custom_path_default(self):
|
def _static_custom_path_default(self):
|
||||||
path = super(SingleUserNotebookApp, self)._static_custom_path_default()
|
path = super(SingleUserNotebookApp, self)._static_custom_path_default()
|
||||||
if self.disable_user_config:
|
if self.disable_user_config:
|
||||||
path = list(_exclude_home(path))
|
path = list(_exclude_home(path))
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
# Start a PeriodicCallback to clear cached cookies. This forces us to
|
# Start a PeriodicCallback to clear cached cookies. This forces us to
|
||||||
# revalidate our user with the Hub at least every
|
# revalidate our user with the Hub at least every
|
||||||
@@ -251,7 +251,7 @@ class SingleUserNotebookApp(NotebookApp):
|
|||||||
self.cookie_cache_lifetime * 1e3,
|
self.cookie_cache_lifetime * 1e3,
|
||||||
).start()
|
).start()
|
||||||
super(SingleUserNotebookApp, self).start()
|
super(SingleUserNotebookApp, self).start()
|
||||||
|
|
||||||
def init_webapp(self):
|
def init_webapp(self):
|
||||||
# load the hub related settings into the tornado settings dict
|
# load the hub related settings into the tornado settings dict
|
||||||
env = os.environ
|
env = os.environ
|
||||||
@@ -267,21 +267,21 @@ class SingleUserNotebookApp(NotebookApp):
|
|||||||
s['csp_report_uri'] = self.hub_host + url_path_join(self.hub_prefix, 'security/csp-report')
|
s['csp_report_uri'] = self.hub_host + url_path_join(self.hub_prefix, 'security/csp-report')
|
||||||
super(SingleUserNotebookApp, self).init_webapp()
|
super(SingleUserNotebookApp, self).init_webapp()
|
||||||
self.patch_templates()
|
self.patch_templates()
|
||||||
|
|
||||||
def patch_templates(self):
|
def patch_templates(self):
|
||||||
"""Patch page templates to add Hub-related buttons"""
|
"""Patch page templates to add Hub-related buttons"""
|
||||||
|
|
||||||
self.jinja_template_vars['logo_url'] = self.hub_host + url_path_join(self.hub_prefix, 'logo')
|
self.jinja_template_vars['logo_url'] = self.hub_host + url_path_join(self.hub_prefix, 'logo')
|
||||||
env = self.web_app.settings['jinja2_env']
|
env = self.web_app.settings['jinja2_env']
|
||||||
|
|
||||||
env.globals['hub_control_panel_url'] = \
|
env.globals['hub_control_panel_url'] = \
|
||||||
self.hub_host + url_path_join(self.hub_prefix, 'home')
|
self.hub_host + url_path_join(self.hub_prefix, 'home')
|
||||||
|
|
||||||
# patch jinja env loading to modify page template
|
# patch jinja env loading to modify page template
|
||||||
def get_page(name):
|
def get_page(name):
|
||||||
if name == 'page.html':
|
if name == 'page.html':
|
||||||
return page_template
|
return page_template
|
||||||
|
|
||||||
orig_loader = env.loader
|
orig_loader = env.loader
|
||||||
env.loader = ChoiceLoader([
|
env.loader = ChoiceLoader([
|
||||||
FunctionLoader(get_page),
|
FunctionLoader(get_page),
|
||||||
|
Reference in New Issue
Block a user