Debian Codegraph @

jupyter_server_terminals/handlers.py

raw symbols SCIP
1 """Tornado handlers for the terminal emulator."""
2 # Copyright (c) Jupyter Development Team.
3 # Distributed under the terms of the Modified BSD License.
4 from __future__scip-python python python-stdlib 3.11 __future__/__init__: import annotationsscip-python python python-stdlib 3.11 __future__/annotations.annotations.
5
6 import typingscip-python python python-stdlib 3.11 typing/__init__: as t
7
8 from jupyter_core.utilsscip-python python jupyter_core 5.9.1 `jupyter_core.utils`/__init__: import ensure_async
9 from jupyter_server._tzscip-python python jupyter_server 2.20.0 `jupyter_server._tz`/__init__: import utcnow
10 from jupyter_server.auth.utilsscip-python python jupyter_server 2.20.0 `jupyter_server.auth.utils`/__init__: import warn_disabled_authorization
11 from jupyter_server.base.handlersscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/__init__: import JupyterHandler
12 from jupyter_server.base.websocketscip-python python jupyter_server 2.20.0 `jupyter_server.base.websocket`/__init__: import WebSocketMixin
13 from terminado.managementscip-python python terminado 0.18.1 `terminado.management`/__init__: import NamedTermManager
14 from terminado.websocketscip-python python terminado 0.18.1 `terminado.websocket`/__init__: import TermSocket as BaseTermSocket
15 from tornadoscip-python python tornado 6.5.5 tornado/__init__: import web
16
17 from .basescip-python python jupyter_server_terminals 0.5.3 base/__init__: import TerminalsMixinscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.base`/TerminalsMixin#
18
19 AUTH_RESOURCEscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/AUTH_RESOURCE. = "terminals"
20
21
22 class TermSocketscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#(TerminalsMixinscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.base`/TerminalsMixin#, WebSocketMixin, JupyterHandler, BaseTermSocket):
23 """A terminal websocket."""
24
25 auth_resourcescip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#auth_resource. = AUTH_RESOURCEscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/AUTH_RESOURCE.
26
27 def initializescip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#initialize().( # type:ignore[override]
28 selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#initialize().(self), namescip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#initialize().(name): strscip-python python python-stdlib 3.11 builtins/str#, term_managerscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#initialize().(term_manager): NamedTermManager, **kwargsscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#initialize().(kwargs): t.Anyscip-python python python-stdlib 3.11 typing/Any.
29 ) -> None:
30 """Initialize the socket."""
31 BaseTermSocket.initialize(selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#initialize().(self), term_managerscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#initialize().(term_manager), **kwargsscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#initialize().(kwargs))
32 TerminalsMixinscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.base`/TerminalsMixin#.initialize(selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#initialize().(self), namescip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#initialize().(name))
33
34 def origin_checkscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#origin_check().(selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#origin_check().(self), originscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#origin_check().(origin): t.Anyscip-python python python-stdlib 3.11 typing/Any. = None) -> boolscip-python python python-stdlib 3.11 builtins/bool#:
35 """Terminado adds redundant origin_check
36 Tornado already calls check_origin, so don't do anything here.
37 """
38 return True
39
40 async def getscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(self), *argsscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(args): t.Anyscip-python python python-stdlib 3.11 typing/Any., **kwargsscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(kwargs): t.Anyscip-python python python-stdlib 3.11 typing/Any.) -> None:
41 """Get the terminal socket."""
42 user = selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(self).current_user
43
44 if not user:
45 raise web.HTTPError(403)
46
47 # authorize the user.
48 if selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(self).authorizer is None:
49 # Warn if an authorizer is unavailable.
50 warn_disabled_authorization() # type:ignore[unreachable]
51 elif not selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(self).authorizer.is_authorized(selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(self), user, "execute", selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(self).auth_resourcescip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#auth_resource.):
52 raise web.HTTPError(403)
53
54 if argsscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(args)[0] not in selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(self).term_manager.terminals: # type:ignore[attr-defined]
55 raise web.HTTPError(404)
56 resp = superscip-python python python-stdlib 3.11 builtins/super#().get(*argsscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(args), **kwargsscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#get().(kwargs))
57 if resp is not None:
58 await ensure_async(resp) # type:ignore[arg-type]
59
60 async def on_messagescip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#on_message().(selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#on_message().(self), messagescip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#on_message().(message): t.Anyscip-python python python-stdlib 3.11 typing/Any.) -> None: # type:ignore[override]
61 """Handle a socket message."""
62 await ensure_async(superscip-python python python-stdlib 3.11 builtins/super#().on_message(messagescip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#on_message().(message))) # type:ignore[arg-type]
63 selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#on_message().(self)._update_activityscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#_update_activity().()
64
65 def write_messagescip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#write_message().(selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#write_message().(self), messagescip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#write_message().(message): t.Anyscip-python python python-stdlib 3.11 typing/Any., binaryscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#write_message().(binary): boolscip-python python python-stdlib 3.11 builtins/bool# = False) -> None: # type:ignore[override]
66 """Write a message to the socket."""
67 superscip-python python python-stdlib 3.11 builtins/super#().write_message(messagescip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#write_message().(message), binary=binaryscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#write_message().(binary))
68 selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#write_message().(self)._update_activityscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#_update_activity().()
69
70 def _update_activityscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#_update_activity().(selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#_update_activity().(self)) -> None:
71 selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#_update_activity().(self).application.settings["terminal_last_activity"] = utcnow()
72 # terminal may not be around on deletion/cull
73 if selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#_update_activity().(self).term_name in selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#_update_activity().(self).terminal_managerscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.base`/TerminalsMixin#terminal_manager()..terminals:
74 selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#_update_activity().(self).terminal_managerscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.base`/TerminalsMixin#terminal_manager()..terminals[selfscip-python python jupyter_server_terminals 0.5.3 `jupyter_server_terminals.handlers`/TermSocket#_update_activity().(self).term_name].last_activity = utcnow() # type:ignore[attr-defined]