Python notebook.utils.url_path_join() Examples
The following are 30
code examples of notebook.utils.url_path_join().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
notebook.utils
, or try the search function
.
Example #1
Source File: extension.py From jupyterlab_commands with Apache License 2.0 | 6 votes |
def load_jupyter_server_extension(nb_server_app): """ Called when the extension is loaded. Args: nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance. """ web_app = nb_server_app.web_app commands = nb_server_app.config.get('JupyterLabCommands', {}).get('commands', {}) base_url = web_app.settings['base_url'] host_pattern = '.*$' print('Installing jupyterlab_commands handler on path %s' % url_path_join(base_url, 'commands')) print('Available commands: %s' % ','.join(k for k in commands)) web_app.add_handlers(host_pattern, [(url_path_join(base_url, 'commands/get'), CommandsListHandler, {'commands': commands})]) web_app.add_handlers(host_pattern, [(url_path_join(base_url, 'commands/run'), CommandsHandler, {'commands': commands})])
Example #2
Source File: conftest.py From elyra with Apache License 2.0 | 6 votes |
def fetch(request, *parts, **kwargs): # Handle URL strings # Since base_url is already escaped, unescape it. path = url_escape(url_path_join(*parts), plus=False) # Make request. method = 'GET' if 'method' in kwargs and kwargs['method']: method = kwargs['method'] body = None if 'body' in kwargs and kwargs['body']: body = kwargs['body'] return request(method, path, data=body) # END - Remove once transition to jupyter_server occurs
Example #3
Source File: handlers.py From elyra with Apache License 2.0 | 6 votes |
def post(self, namespace): namespace = url_unescape(namespace) try: instance = self._validate_body() self.log.debug("MetadataHandler: Creating metadata instance '{}' in namespace '{}'...". format(instance.name, namespace)) metadata_manager = MetadataManager(namespace=namespace) metadata = metadata_manager.add(instance.name, instance, replace=False) except (ValidationError, ValueError, SyntaxError) as err: raise web.HTTPError(400, str(err)) from err except FileNotFoundError as err: raise web.HTTPError(404, str(err)) from err except FileExistsError as err: raise web.HTTPError(409, str(err)) from err except Exception as err: raise web.HTTPError(500, repr(err)) from err self.set_status(201) self.set_header("Content-Type", 'application/json') location = url_path_join(self.base_url, 'elyra', 'metadata', namespace, metadata.name) self.set_header('Location', location) self.finish(metadata.to_dict(trim=True))
Example #4
Source File: __init__.py From jupyter-server-proxy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def load_jupyter_server_extension(nbapp): # Set up handlers picked up via config base_url = nbapp.web_app.settings['base_url'] serverproxy = ServerProxy(parent=nbapp) server_processes = [make_server_process(k, v) for k, v in serverproxy.servers.items()] server_processes += get_entrypoint_server_processes() server_handlers = make_handlers(base_url, server_processes) nbapp.web_app.add_handlers('.*', server_handlers) # Set up default handler setup_handlers(nbapp.web_app, serverproxy.host_whitelist) launcher_entries = [] icons = {} for sp in server_processes: if sp.launcher_entry.enabled and sp.launcher_entry.icon_path: icons[sp.name] = sp.launcher_entry.icon_path nbapp.web_app.add_handlers('.*', [ (ujoin(base_url, 'server-proxy/servers-info'), ServersInfoHandler, {'server_processes': server_processes}), (ujoin(base_url, 'server-proxy/icon/(.*)'), IconHandler, {'icons': icons}) ])
Example #5
Source File: __init__.py From elyra with Apache License 2.0 | 6 votes |
def load_jupyter_server_extension(nb_server_app): web_app = nb_server_app.web_app host_pattern = '.*$' web_app.add_handlers(host_pattern, [ (url_path_join(web_app.settings['base_url'], r'/elyra/{}'.format(YamlSpecHandler.get_resource_metadata()[0])), YamlSpecHandler), (url_path_join(web_app.settings['base_url'], r'/elyra/metadata/%s' % (namespace_regex)), MetadataHandler), (url_path_join(web_app.settings['base_url'], r'/elyra/metadata/%s/%s' % (namespace_regex, resource_regex)), MetadataResourceHandler), (url_path_join(web_app.settings['base_url'], r'/elyra/schema/%s' % (namespace_regex)), SchemaHandler), (url_path_join(web_app.settings['base_url'], r'/elyra/schema/%s/%s' % (namespace_regex, resource_regex)), SchemaResourceHandler), (url_path_join(web_app.settings['base_url'], r'/elyra/namespace'), NamespaceHandler), (url_path_join(web_app.settings['base_url'], r'/elyra/pipeline/schedule'), PipelineSchedulerHandler), (url_path_join(web_app.settings['base_url'], r'/elyra/pipeline/export'), PipelineExportHandler), ]) # Create PipelineProcessorManager instance passing root directory PipelineProcessorManager.instance(root_dir=web_app.settings['server_root_dir'])
Example #6
Source File: __init__.py From jupyterlab-s3-browser with Apache License 2.0 | 6 votes |
def load_jupyter_server_extension(nb_server_app): """ Called when the extension is loaded. Args: nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance. """ web_app = nb_server_app.web_app base_url = web_app.settings["base_url"] endpoint = url_path_join(base_url, "s3") handlers = [ (url_path_join(endpoint, "auth") + "(.*)", AuthHandler), (url_path_join(endpoint, "files") + "(.*)", S3Handler), ] web_app.add_handlers(".*$", handlers)
Example #7
Source File: __init__.py From dask-labextension with BSD 3-Clause "New" or "Revised" License | 6 votes |
def load_jupyter_server_extension(nb_server_app): """ Called when the extension is loaded. Args: nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance. """ cluster_id_regex = r"(?P<cluster_id>\w+-\w+-\w+-\w+-\w+)" web_app = nb_server_app.web_app base_url = web_app.settings["base_url"] get_cluster_path = url_path_join(base_url, "dask/clusters/" + cluster_id_regex) list_clusters_path = url_path_join(base_url, "dask/clusters/" + "?") get_dashboard_path = url_path_join( base_url, f"dask/dashboard/{cluster_id_regex}(?P<proxied_path>.+)" ) handlers = [ (get_cluster_path, DaskClusterHandler), (list_clusters_path, DaskClusterHandler), (get_dashboard_path, DaskDashboardHandler), ] web_app.add_handlers(".*$", handlers)
Example #8
Source File: handlers.py From sagemaker-notebook-container with MIT License | 6 votes |
def get(self, action): example_id = self.get_argument('example_id') if action == 'preview': self.finish(self.manager.preview_example(example_id)) elif action == 'fetch': dest = self.get_argument('dest') dest = self.manager.fetch_example(example_id, dest) self.redirect(ujoin(self.base_url, 'notebooks', dest)) elif action == 'fetchfile': dest = self.get_argument('dest') dest = self.manager.fetch_example(example_id, dest) self.finish(dest) # ----------------------------------------------------------------------------- # URL to handler mappings # -----------------------------------------------------------------------------
Example #9
Source File: __init__.py From nbgitpuller with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #10
Source File: extension.py From nbcelltests with Apache License 2.0 | 6 votes |
def _load_jupyter_server_extension(nb_server_app): """ Called when the extension is loaded. Args: nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance. """ web_app = nb_server_app.web_app host_pattern = '.*$' base_url = web_app.settings['base_url'] # host_pattern = '.*$' print('Installing nbcelltests handler on path %s' % url_path_join(base_url, 'celltests')) rules = nb_server_app.config.get('JupyterLabCelltests', {}).get('rules', {}) test_executable = nb_server_app.config.get('JupyterLabCelltests', {}).get('test_executable', [sys.executable, '-m', 'pytest', '-v']) lint_executable = nb_server_app.config.get('JupyterLabCelltests', {}).get('lint_executable', [sys.executable, '-m', 'flake8', '--ignore=W391']) web_app.add_handlers(host_pattern, [(url_path_join(base_url, 'celltests/test/run'), RunCelltestsHandler, {'rules': rules, 'executable': test_executable})]) web_app.add_handlers(host_pattern, [(url_path_join(base_url, 'celltests/lint/run'), RunLintsHandler, {'rules': rules, 'executable': lint_executable})])
Example #11
Source File: __init__.py From colabtools with Apache License 2.0 | 6 votes |
def load_jupyter_server_extension(nb_server_app): """Called by Jupyter when starting the notebook manager.""" # We only want to import these modules when setting up a server extension, and # want to avoid raising an exception when the `notebook` package isn't # available. # pylint: disable=g-import-not-at-top from notebook import utils from google.colab._serverextension import _handlers # pylint: enable=g-import-not-at-top nb_server_app.log.addFilter(_ColabLoggingFilter()) app = nb_server_app.web_app url_maker = lambda path: utils.url_path_join(app.settings['base_url'], path) monitor_relative_path = '/api/colab/resources' app.add_handlers('.*$', [ (url_maker(monitor_relative_path), _handlers.ResourceUsageHandler, { 'kernel_manager': app.settings['kernel_manager'] }), (url_maker('/api/colab/drive'), _handlers.DriveHandler), ]) nb_server_app.log.info('google.colab serverextension initialized.')
Example #12
Source File: __init__.py From geonotebook with Apache License 2.0 | 6 votes |
def load_jupyter_server_extension(nbapp): nbapp.log.info("geonotebook module enabled!") nbapp.web_app.settings['jinja2_env'].loader = \ get_notebook_jinja2_loader(nbapp) webapp = nbapp.web_app conf = Config() conf.vis_server.initialize_webapp(conf, webapp) base_url = webapp.settings['base_url'] for ep in pkg_resources.iter_entry_points( group='geonotebook.handlers.default'): webapp.add_handlers('.*$', [(url_path_join(base_url, ep.name), ep.load())])
Example #13
Source File: hooks.py From qiime2 with BSD 3-Clause "New" or "Revised" License | 6 votes |
def load_jupyter_server_extension(nb_server): from .handlers import QIIME2RedirectHandler, QIIME2ResultHandler from notebook.utils import url_path_join result_store = {} app = nb_server.web_app def route(path): return url_path_join(app.settings['base_url'], 'qiime2', path) app.add_handlers(r'.*', [ (route(r'redirect'), QIIME2RedirectHandler, {'result_store': result_store}), (route(r'view/(.*)'), QIIME2ResultHandler, # This *is* odd, but it's because we are tricking StaticFileHandler {'path': result_store, 'default_filename': 'index.html'}) ])
Example #14
Source File: extension.py From jupyter-fs with Apache License 2.0 | 6 votes |
def load_jupyter_server_extension(nb_server_app): """ Called when the extension is loaded. Args: nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance. """ web_app = nb_server_app.web_app base_url = web_app.settings['base_url'] host_pattern = '.*$' if not isinstance(nb_server_app.contents_manager, MetaManager): warnings.warn(_mc_config_warning_msg) return # init managers from resources described in notebook server config nb_server_app.contents_manager.initResource( *nb_server_app.config.get('jupyterfs', {}).get('specs', []) ) resources_url = 'jupyterfs/resources' print('Installing jupyter-fs resources handler on path %s' % url_path_join(base_url, resources_url)) web_app.add_handlers(host_pattern, [(url_path_join(base_url, resources_url), MetaManagerHandler)])
Example #15
Source File: __init__.py From jupyterlab-latex with BSD 3-Clause "New" or "Revised" License | 6 votes |
def load_jupyter_server_extension(nb_server_app): """ Called when the extension is loaded. Args: nb_server_app (NotebookApp): handle to the Notebook webserver instance. """ web_app = nb_server_app.web_app # Prepend the base_url so that it works in a jupyterhub setting base_url = web_app.settings['base_url'] latex = url_path_join(base_url, 'latex') build = url_path_join(latex, 'build') synctex = url_path_join(latex, 'synctex') handlers = [(f'{build}{path_regex}', LatexBuildHandler, {"notebook_dir": nb_server_app.notebook_dir} ), (f'{synctex}{path_regex}', LatexSynctexHandler, {"notebook_dir": nb_server_app.notebook_dir} )] web_app.add_handlers('.*$', handlers)
Example #16
Source File: __init__.py From jupyter_http_over_ws with Apache License 2.0 | 5 votes |
def _handler_rule(app, handler_class): return (utils.url_path_join(app.settings['base_url'], handler_class.PATH), handler_class)
Example #17
Source File: handlers.py From jupyter_tensorboard with MIT License | 5 votes |
def load_jupyter_server_extension(nb_app): global notebook_dir # notebook_dir should be root_dir of contents_manager notebook_dir = nb_app.contents_manager.root_dir web_app = nb_app.web_app base_url = web_app.settings['base_url'] try: from .tensorboard_manager import manager except ImportError: nb_app.log.info("import tensorboard error, check tensorflow install") handlers = [ (ujoin( base_url, r"/tensorboard.*"), TensorboardErrorHandler), ] else: web_app.settings["tensorboard_manager"] = manager from . import api_handlers handlers = [ (ujoin( base_url, r"/tensorboard/(?P<name>\w+)%s" % path_regex), TensorboardHandler), (ujoin( base_url, r"/api/tensorboard"), api_handlers.TbRootHandler), (ujoin( base_url, r"/api/tensorboard/(?P<name>\w+)"), api_handlers.TbInstanceHandler), ] web_app.add_handlers('.*$', handlers) nb_app.log.info("jupyter_tensorboard extension loaded.")
Example #18
Source File: __init__.py From nbresuse with BSD 2-Clause "Simplified" License | 5 votes |
def load_jupyter_server_extension(nbapp): """ Called during notebook start """ resuseconfig = ResourceUseDisplay(parent=nbapp) nbapp.web_app.settings["nbresuse_display_config"] = resuseconfig base_url = nbapp.web_app.settings["base_url"] nbapp.web_app.add_handlers( ".*", [(url_path_join(base_url, "/metrics"), ApiHandler)] ) callback = ioloop.PeriodicCallback( PrometheusHandler(PSUtilMetricsLoader(nbapp)), 1000 ) callback.start()
Example #19
Source File: __init__.py From aws-iot-analytics-notebook-containers with Apache License 2.0 | 5 votes |
def load_jupyter_server_extension(nb_server_app): web_app = nb_server_app.web_app host_pattern = '.*$' web_app.add_handlers(host_pattern, [ (url_path_join(web_app.settings['base_url'], r'/create_repo'), CreateNewRepoHandler), (url_path_join(web_app.settings['base_url'], r'/upload_to_repo'), UploadToRepoHandler), (url_path_join(web_app.settings['base_url'], r'/upload_to_repo/is_ongoing'), IsContainerizationOngoingHandler), (url_path_join(web_app.settings['base_url'], r'/extension_version/is_latest'), ExtensionLastModifiedHandler), (url_path_join(web_app.settings['base_url'], r'/list_repos'), ListRepoHandler) ])
Example #20
Source File: server_extension.py From jupyter-ros with BSD 3-Clause "New" or "Revised" License | 5 votes |
def load_jupyter_server_extension(nb_server_app): """ Called when the extension is loaded. Args: nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance. """ web_app = nb_server_app.web_app host_pattern = '.*$' route_pattern = url_path_join(web_app.settings['base_url'], '/rospkg/(.*)') web_app.add_handlers(host_pattern, [(route_pattern, ROSStaticHandler)])
Example #21
Source File: formgrader.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def init_handlers(self, webapp): h = [] h.extend(handlers.default_handlers) h.extend(apihandlers.default_handlers) h.extend([ (r"/formgrader/static/(.*)", web.StaticFileHandler, {'path': handlers.static_path}), (r"/formgrader/.*", handlers.Template404) ]) def rewrite(x): pat = ujoin(webapp.settings['base_url'], x[0].lstrip('/')) return (pat,) + x[1:] webapp.add_handlers(".*$", [rewrite(x) for x in h])
Example #22
Source File: ktile.py From geonotebook with Apache License 2.0 | 5 votes |
def initialize_webapp(self, config, webapp): base_url = webapp.settings['base_url'] webapp.ktile_config_manager = KtileConfigManager( self.default_cache) webapp.add_handlers('.*$', [ # kernel_name (ujoin(base_url, r'/ktile/([^/]*)'), KtileHandler, dict(ktile_config_manager=webapp.ktile_config_manager)), # kernel_name, layer_name (ujoin(base_url, r'/ktile/([^/]*)/([^/]*)'), KtileLayerHandler, dict(ktile_config_manager=webapp.ktile_config_manager)), # kernel_name, layer_name, x, y, z, extension (ujoin(base_url, r'/ktile/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/\.]*)\.(.*)'), KtileTileHandler, dict(ktile_config_manager=webapp.ktile_config_manager)), ]) # get_params should take a generic list of parameters e.g. 'bands', # 'range', 'gamma' and convert these into a list of vis_server specific # parameters which will be passed along to the tile render handler in # add_layer. This is intended to allow the vis_server to include style # parameters and subsetting operations. select bands, set ranges # on a particular dataset etc.
Example #23
Source File: dashboardhandler.py From dask-labextension with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _normalize_dashboard_link(link, request): """ Given a dashboard link, make sure it conforms to what we expect. """ if not link.startswith("http"): # If a local url is given, assume it is using the same host # as the application, and prepend that. link = url_path_join(f"{request.protocol}://{request.host}", link) if link.endswith("/status"): # If the default "status" dashboard is give, strip it. link = link[:-len("/status")] return link
Example #24
Source File: server_extension.py From appmode with MIT License | 5 votes |
def load_jupyter_server_extension(nbapp): tmpl_dir = os.path.dirname(__file__) # 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.") #EOF
Example #25
Source File: handlers.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def load_jupyter_server_extension(nbapp): """Load the nbserver""" nbapp.log.info("Loading the course_list nbgrader serverextension") webapp = nbapp.web_app base_url = webapp.settings['base_url'] webapp.settings['assignment_dir'] = nbapp.notebook_dir webapp.add_handlers(".*$", [ (ujoin(base_url, pat), handler) for pat, handler in default_handlers ])
Example #26
Source File: handlers.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def load_jupyter_server_extension(nbapp): """Load the nbserver""" nbapp.log.info("Loading the validate_assignment nbgrader serverextension") webapp = nbapp.web_app base_url = webapp.settings['base_url'] webapp.settings['notebook_dir'] = nbapp.notebook_dir webapp.add_handlers(".*$", [ (ujoin(base_url, pat), handler) for pat, handler in default_handlers ])
Example #27
Source File: handlers.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def load_jupyter_server_extension(nbapp): """Load the nbserver""" nbapp.log.info("Loading the assignment_list nbgrader serverextension") webapp = nbapp.web_app webapp.settings['assignment_list_manager'] = AssignmentList(parent=nbapp) base_url = webapp.settings['base_url'] webapp.add_handlers(".*$", [ (ujoin(base_url, pat), handler) for pat, handler in default_handlers ])
Example #28
Source File: views.py From MPContribs with MIT License | 5 votes |
def connect_kernel(): # TODO check status busy/idle run_sync(manager.list_kernels()) kernels = { kernel_id: dateparser.parse(kernel["last_activity"]) for kernel_id, kernel in manager._kernels.items() } kernel_id = url_escape(sorted(kernels, key=kernels.get)[0]) client = GatewayClient.instance() url = url_path_join(client.ws_url, client.kernels_endpoint, kernel_id, "channels") ws_req = HTTPRequest(url=url) return run_sync(websocket_connect(ws_req))
Example #29
Source File: nbsrvext.py From jupyter-plotly-dash with GNU Affero General Public License v3.0 | 5 votes |
def do_load_jupyter_server_extension(nb_app): web_app = nb_app.web_app host_pattern = '.*$' root_endpoint = "/app/" web_app.add_handlers(host_pattern, [(url_path_join(web_app.settings['base_url'], '%(rep)sregister/(?P<da_id>\w+)' %{'rep':root_endpoint} ), JPDHandler), (url_path_join(web_app.settings['base_url'], '%(rep)sregistrants'%{'rep':root_endpoint} ), JPDHandler), (url_path_join(web_app.settings['base_url'], '%(rep)sendpoints/(?P<da_id>\w+)/(?P<stem>.*)'%{'rep':root_endpoint} ), RequestRedirectionHandler), (url_path_join(web_app.settings['base_url'], '%(rep)sendpoints/(?P<da_id>\w+)'%{'rep':root_endpoint} ), RequestRedirectionHandler), (url_path_join(web_app.settings['base_url'], '/files%(rep)sendpoints/(?P<da_id>\w+)/(?P<stem>.*)'%{'rep':root_endpoint} ), RequestRedirectionHandler), (url_path_join(web_app.settings['base_url'], '/files%(rep)sendpoints/(?P<da_id>\w+)'%{'rep':root_endpoint} ), RequestRedirectionHandler), (url_path_join(web_app.settings['base_url'], '/api/contents%(rep)sendpoints/(?P<da_id>\w+)/(?P<stem>.*)'%{'rep':root_endpoint} ), RequestRedirectionHandler), (url_path_join(web_app.settings['base_url'], '/api/contents%(rep)sendpoints/(?P<da_id>\w+)'%{'rep':root_endpoint} ), RequestRedirectionHandler), ])
Example #30
Source File: proxyextension.py From jupyter-server-proxy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def load_jupyter_server_extension(nb_server_app): web_app = nb_server_app.web_app base_url = web_app.settings["base_url"] proxy_path = url_path_join(base_url, "newproxy/" + "?") handlers = [(proxy_path, NewHandler)] web_app.add_handlers(".*$", handlers)