33"""
44
55import sys
6+ from textwrap import dedent , indent
67from warnings import warn
78
89if sys .version_info < (3 , 10 ): # pragma: no cover
@@ -349,6 +350,16 @@ def make_server_process(name, server_process_config, serverproxy_config):
349350 return ServerProcess (name = name , ** server_process_config )
350351
351352
353+ def _serverproxy_servers_help ():
354+ serverprocess_help = ""
355+ for k , v in ServerProcess .class_traits ().items ():
356+ help = v .metadata .get ("help" , "" ).lstrip ("\n " ).rstrip ()
357+ if help :
358+ help = indent (dedent (help ), " " )
359+ serverprocess_help += f"{ k } \n { help } \n \n "
360+ return serverprocess_help
361+
362+
352363class ServerProxy (Configurable ):
353364 servers = Dict (
354365 {},
@@ -359,123 +370,9 @@ class ServerProxy(Configurable):
359370 the URL prefix, and all requests matching this prefix are routed to this process.
360371
361372 Value should be a dictionary with the following keys:
362- command
363- An optional list of strings that should be the full command to be executed.
364- The optional template arguments {{port}}, {{unix_socket}} and {{base_url}}
365- will be substituted with the port or Unix socket path the process should
366- listen on and the base-url of the notebook.
367-
368- Could also be a callable. It should return a list.
369-
370- If the command is not specified or is an empty list, the server
371- process is assumed to be started ahead of time and already available
372- to be proxied to.
373-
374- environment
375- A dictionary of environment variable mappings. As with the command
376- traitlet, {{port}}, {{unix_socket}} and {{base_url}} will be substituted.
377-
378- Could also be a callable. It should return a dictionary.
379-
380- timeout
381- Timeout in seconds for the process to become ready, default 5s.
382-
383- absolute_url
384- Proxy requests default to being rewritten to '/'. If this is True,
385- the absolute URL will be sent to the backend instead.
386-
387- port
388- Set the port that the service will listen on. The default is to automatically select an unused port.
389-
390- unix_socket
391- If set, the service will listen on a Unix socket instead of a TCP port.
392- Set to True to use a socket in a new temporary folder, or a string
393- path to a socket. This overrides port.
394-
395- Proxying websockets over a Unix socket requires Tornado >= 6.3.
396-
397- mappath
398- Map request paths to proxied paths.
399- Either a dictionary of request paths to proxied paths,
400- or a callable that takes parameter ``path`` and returns the proxied path.
401-
402- launcher_entry
403- A dictionary of various options for entries in classic notebook / jupyterlab launchers.
404-
405- Keys recognized are:
406-
407- enabled
408- Set to True (default) to make an entry in the launchers. Set to False to have no
409- explicit entry.
410-
411- icon_path
412- Full path to an svg icon that could be used with a launcher. Currently only used by the
413- JupyterLab launcher
414373
415- title
416- Title to be used for the launcher entry. Defaults to the name of the server if missing.
417-
418- path_info
419- The trailing path that is appended to the user's server URL to access the proxied server.
420- By default it is the name of the server followed by a trailing slash.
421-
422- category
423- The category for the launcher item. Currently only used by the JupyterLab launcher.
424- By default it is "Notebook".
425-
426- new_browser_tab
427- Set to True (default) to make the proxied server interface opened as a new browser tab. Set to False
428- to have it open a new JupyterLab tab. This has no effect in classic notebook.
429-
430- request_headers_override
431- A dictionary of additional HTTP headers for the proxy request. As with
432- the command traitlet, {{port}}, {{unix_socket}} and {{base_url}} will be substituted.
433-
434- rewrite_response
435- An optional function to rewrite the response for the given service.
436- Input is a RewritableResponse object which is an argument that MUST be named
437- ``response``. The function should modify one or more of the attributes
438- ``.body``, ``.headers``, ``.code``, or ``.reason`` of the ``response``
439- argument. For example:
440-
441- def dog_to_cat(response):
442- response.headers["I-Like"] = "tacos"
443- response.body = response.body.replace(b'dog', b'cat')
444-
445- c.ServerProxy.servers['my_server']['rewrite_response'] = dog_to_cat
446-
447- The ``rewrite_response`` function can also accept several optional
448- positional arguments. Arguments named ``host``, ``port``, and ``path`` will
449- receive values corresponding to the URL ``/proxy/<host>:<port><path>``. In
450- addition, the original Tornado ``HTTPRequest`` and ``HTTPResponse`` objects
451- are available as arguments named ``request`` and ``orig_response``. (These
452- objects should not be modified.)
453-
454- A list or tuple of functions can also be specified for chaining multiple
455- rewrites. For example:
456-
457- def cats_only(response, path):
458- if path.startswith("/cat-club"):
459- response.code = 403
460- response.body = b"dogs not allowed"
461-
462- c.ServerProxy.servers['my_server']['rewrite_response'] = [dog_to_cat, cats_only]
463-
464- Note that if the order is reversed to ``[cats_only, dog_to_cat]``, then accessing
465- ``/cat-club`` will produce a "403 Forbidden" response with body "cats not allowed"
466- instead of "dogs not allowed".
467-
468- Defaults to the empty tuple ``tuple()``.
469-
470- update_last_activity
471- Will cause the proxy to report activity back to jupyter server.
472-
473- raw_socket_proxy
474- Proxy websocket requests as a raw TCP (or unix socket) stream.
475- In this mode, only websockets are handled, and messages are sent to the backend,
476- similar to running a websockify layer (https://github.com/novnc/websockify).
477- All other HTTP requests return 405 (and thus this will also bypass rewrite_response).
478- """ ,
374+ """
375+ + indent (_serverproxy_servers_help (), " " ),
479376 config = True ,
480377 )
481378
0 commit comments