Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def generate_breadcrumbs(self, path):
breadcrumbs = [(url_path_join(self.base_url, 'tree'), '')]
parts = path.split('/')
for i in range(len(parts)):
if parts[i]:
link = url_path_join(self.base_url, 'tree',
url_escape(url_path_join(*parts[:i+1])),
)
breadcrumbs.append((link, parts[i]))
return breadcrumbs
try:
browser = webbrowser.get(self.browser or None)
except webbrowser.Error as e:
self.log.warning(_('No web browser found: %s.') % e)
browser = None
if not browser:
return
if self.file_to_run:
if not os.path.exists(self.file_to_run):
self.log.critical(_("%s does not exist") % self.file_to_run)
self.exit(1)
relpath = os.path.relpath(self.file_to_run, self.notebook_dir)
uri = url_escape(url_path_join('notebooks', *relpath.split(os.sep)))
# Write a temporary file to open in the browser
fd, open_file = tempfile.mkstemp(suffix='.html')
with io.open(fd, 'w', encoding='utf-8') as fh:
self._write_browser_open_file(uri, fh)
else:
open_file = self.browser_open_file
b = lambda: browser.open(
urljoin('file:', pathname2url(open_file)),
new=self.webbrowser_open_new)
threading.Thread(target=b).start()
async def get(self):
data = []
# Pick out and send only metadata
# Don't send anything that might be a callable, or leak sensitive info
for sp in self.server_processes:
# Manually recurse to convert namedtuples into JSONable structures
item = {
'name': sp.name,
'launcher_entry': {
'enabled': sp.launcher_entry.enabled,
'title': sp.launcher_entry.title
}
}
if sp.launcher_entry.icon_path:
icon_url = ujoin(self.base_url, 'server-proxy', 'icon', sp.name)
item['launcher_entry']['icon_url'] = icon_url
data.append(item)
self.write({'server_processes': data})
# does not work, because init_webapp() happens before init_server_extensions()
#nbapp.extra_template_paths.append(tmpl_dir) # dows
# For configuration values that can be set server side
appmode = Appmode(parent=nbapp)
nbapp.web_app.settings['appmode'] = appmode
# slight violation of Demeter's Law
rootloader = nbapp.web_app.settings['jinja2_env'].loader
for loader in getattr(rootloader, 'loaders', [rootloader]):
if hasattr(loader, 'searchpath') and tmpl_dir not in loader.searchpath:
loader.searchpath.append(tmpl_dir)
web_app = nbapp.web_app
host_pattern = '.*$'
route_pattern = url_path_join(web_app.settings['base_url'], r'/apps%s' % path_regex)
web_app.add_handlers(host_pattern, [(route_pattern, AppmodeHandler)])
if appmode.trusted_path:
nbapp.log.info("Appmode server extension loaded with trusted path: %s", appmode.trusted_path)
else:
nbapp.log.info("Appmode server extension loaded.")
def init_webapp(self):
"""initialize tornado webapp and httpserver.
"""
super(ExampleApp, self).init_webapp()
default_handlers = [
(ujoin(self.base_url, r'notebook/(.*)?'), NotebookHandler),
(ujoin(self.base_url, r"build/(.*)"), FileFindHandler,
{'path': os.path.join(HERE, 'build')})
]
self.web_app.add_handlers('.*$', default_handlers)
route_pattern = url_path_join(web_app.settings['base_url'], '/tooling/git/info')
web_app.add_handlers(host_pattern, [(route_pattern, GitInfoHandler)])
route_pattern = url_path_join(web_app.settings['base_url'], '/tooling/git/commit')
web_app.add_handlers(host_pattern, [(route_pattern, GitCommitHandler)])
route_pattern = url_path_join(web_app.settings['base_url'], '/tooling/ssh/setup-script')
web_app.add_handlers(host_pattern, [(route_pattern, SSHScriptHandler)])
route_pattern = url_path_join(web_app.settings['base_url'], '/tooling/ssh/setup-command')
web_app.add_handlers(host_pattern, [(route_pattern, SSHCommandHandler)])
route_pattern = url_path_join(web_app.settings['base_url'], "/tooling/files/link")
web_app.add_handlers(host_pattern, [(route_pattern, SharedFilesHandler)])
route_pattern = url_path_join(web_app.settings['base_url'], SHARED_SSH_SETUP_PATH)
web_app.add_handlers(host_pattern, [(route_pattern, SharedSSHHandler)])
log.info('Extension jupyter-tooling-widget loaded successfully.')
Called when the extension is loaded.
Args:
nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance.
"""
web_app = nb_server_app.web_app
sites = nb_server_app.config.get('JupyterLabIFrame', {}).get('iframes', [])
welcome = nb_server_app.config.get('JupyterLabIFrame', {}).get('welcome', [])
host_pattern = '.*$'
base_url = web_app.settings['base_url']
print('Installing jupyterlab_iframe handler on path %s' % url_path_join(base_url, 'iframes'))
print('Handling iframes: %s' % sites)
web_app.add_handlers(host_pattern, [(url_path_join(base_url, 'iframes/'), IFrameHandler, {'welcome': welcome, 'sites': sites}),
(url_path_join(base_url, 'iframes/proxy'), ProxyHandler),
(url_path_join(base_url, 'iframes/proxy'), ProxyWSHandler),
])
# collapse $HOME to ~
root_dir = '~' + root_dir[len(home):]
settings = dict(
# basics
log_function=log_request,
base_url=base_url,
default_url=default_url,
template_path=template_path,
static_path=jupyter_app.static_file_path,
static_custom_path=jupyter_app.static_custom_path,
static_handler_class = FileFindHandler,
static_url_prefix = url_path_join(base_url,'/static/'),
static_handler_args = {
# don't cache custom.js
'no_cache_paths': [url_path_join(base_url, 'static', 'custom')],
},
version_hash=version_hash,
ignore_minified_js=jupyter_app.ignore_minified_js,
# rate limits
iopub_msg_rate_limit=jupyter_app.iopub_msg_rate_limit,
iopub_data_rate_limit=jupyter_app.iopub_data_rate_limit,
rate_limit_window=jupyter_app.rate_limit_window,
# authentication
cookie_secret=jupyter_app.cookie_secret,
login_url=url_path_join(base_url,'/login'),
login_handler_class=jupyter_app.login_handler_class,
logout_handler_class=jupyter_app.logout_handler_class,
password=jupyter_app.password,
xsrf_cookies=True,
def _get_context_path(self, port):
"""
Some applications need to know where they are being proxied from.
This is either:
- {base_url}/proxy/{port}
- {base_url}/proxy/absolute/{port}
- {base_url}/{proxy_base}
"""
if self.proxy_base:
return url_path_join(self.base_url, self.proxy_base)
if self.absolute_url:
return url_path_join(self.base_url, 'proxy', 'absolute', str(port))
else:
return url_path_join(self.base_url, 'proxy', str(port))
def load_jupyter_server_extension(nbapp):
web_app = nbapp.web_app
base_url = url_path_join(web_app.settings['base_url'], 'git-pull')
handlers = [
(url_path_join(base_url, 'api'), SyncHandler),
(base_url, UIHandler),
(url_path_join(web_app.settings['base_url'], 'git-sync'), LegacyGitSyncRedirectHandler),
(url_path_join(web_app.settings['base_url'], 'interact'), LegacyInteractRedirectHandler),
(
url_path_join(base_url, 'static', '(.*)'),
StaticFileHandler,
{'path': os.path.join(os.path.dirname(__file__), 'static')}
)
]
web_app.settings['nbapp'] = nbapp
web_app.add_handlers('.*', handlers)