Debian Codegraph @

jupyter_server/services/contents/handlers.py

raw symbols SCIP
1 """Tornado handlers for the contents web service.
2
3 Preliminary documentation at https://github.com/ipython/ipython/wiki/IPEP-27%3A-Contents-Service
4 """
5
6 # Copyright (c) Jupyter Development Team.
7 # Distributed under the terms of the Modified BSD License.
8 import jsonscip-python python python-stdlib 3.11 json/__init__:
9 from httpscip-python python python-stdlib 3.11 http/__init__: import HTTPStatusscip-python python python-stdlib 3.11 http/HTTPStatus#
10 from typingscip-python python python-stdlib 3.11 typing/__init__: import Anyscip-python python python-stdlib 3.11 typing/Any.
11
12 try:
13 from jupyter_client.jsonutilscip-python python jupyter_client 8.8.0 `jupyter_client.jsonutil`/__init__: import json_default
14 except ImportErrorscip-python python python-stdlib 3.11 builtins/ImportError#:
15 from jupyter_client.jsonutilscip-python python jupyter_client 8.8.0 `jupyter_client.jsonutil`/__init__: import date_default as json_default
16
17 from jupyter_core.utilsscip-python python jupyter_core 5.9.1 `jupyter_core.utils`/__init__: import ensure_async
18 from tornadoscip-python python tornado 6.5.5 tornado/__init__: import web
19
20 from jupyter_server.auth.decoratorscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/__init__: import allow_unauthenticatedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/allow_unauthenticated()., authorizedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().
21 from jupyter_server.base.handlersscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/__init__: import APIHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/APIHandler#, JupyterHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#, path_regexscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/path_regex.
22 from jupyter_server.utilsscip-python python jupyter_server 2.20.0 `jupyter_server.utils`/__init__: import url_escapescip-python python jupyter_server 2.20.0 `jupyter_server.utils`/url_escape()., url_path_joinscip-python python jupyter_server 2.20.0 `jupyter_server.utils`/url_path_join().
23
24 AUTH_RESOURCEscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/AUTH_RESOURCE. = "contents"
25
26
27 def _validate_keysscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(expect_definedscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(expect_defined): boolscip-python python python-stdlib 3.11 builtins/bool#, modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(model): dictscip-python python python-stdlib 3.11 builtins/dict#[strscip-python python python-stdlib 3.11 builtins/str#, Anyscip-python python python-stdlib 3.11 typing/Any.], keysscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(keys): listscip-python python python-stdlib 3.11 builtins/list#[strscip-python python python-stdlib 3.11 builtins/str#]):
28 """
29 Validate that the keys are defined (i.e. not None) or not (i.e. None)
30 """
31
32 if expect_definedscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(expect_defined):
33 errors = [key for key in keysscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(keys) if modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(model)[key] is None]
34 if errors:
35 raise web.HTTPError(
36 500,
37 f"Keys unexpectedly None: {errors}",
38 )
39 else:
40 errors = {key: modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(model)[key] for key in keysscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(keys) if modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(model)[key] is not None} # type: ignore[assignment]
41 if errors:
42 raise web.HTTPError(
43 500,
44 f"Keys unexpectedly not None: {errors}",
45 )
46
47
48 def validate_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(model), expect_contentscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(expect_content)=False, expect_hashscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(expect_hash)=False):
49 """
50 Validate a model returned by a ContentsManager method.
51
52 If expect_content is True, then we expect non-null entries for 'content'
53 and 'format'.
54
55 If expect_hash is True, then we expect non-null entries for 'hash' and 'hash_algorithm'.
56 """
57 required_keys = {
58 "name",
59 "path",
60 "type",
61 "writable",
62 "created",
63 "last_modified",
64 "mimetype",
65 "content",
66 "format",
67 }
68 if expect_hashscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(expect_hash):
69 required_keys.updatescip-python python python-stdlib 3.11 builtins/set#update().(["hash", "hash_algorithm"])
70 missing = required_keys - setscip-python python python-stdlib 3.11 builtins/set#(modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(model).keys())
71 if missing:
72 raise web.HTTPError(
73 500,
74 f"Missing Model Keys: {missing}",
75 )
76
77 content_keys = ["content", "format"]
78 _validate_keysscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(expect_contentscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(expect_content), modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(model), content_keys)
79 if expect_hashscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(expect_hash):
80 _validate_keysscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_validate_keys().(expect_hashscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(expect_hash), modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(model), ["hash", "hash_algorithm"])
81
82
83 class ContentsAPIHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsAPIHandler#(APIHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/APIHandler#):
84 """A contents API handler."""
85
86 auth_resourcescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsAPIHandler#auth_resource. = AUTH_RESOURCEscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/AUTH_RESOURCE.
87
88
89 class ContentsHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#(ContentsAPIHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsAPIHandler#):
90 """A contents handler."""
91
92 def location_urlscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#location_url().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#location_url().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#location_url().(path)):
93 """Return the full URL location of a file.
94
95 Parameters
96 ----------
97 path : unicode
98 The API path of the file, such as "foo/bar.txt".
99 """
100 return url_path_joinscip-python python jupyter_server 2.20.0 `jupyter_server.utils`/url_path_join().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#location_url().(self).base_urlscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/AuthenticatedHandler#base_url()., "api", "contents", url_escapescip-python python jupyter_server 2.20.0 `jupyter_server.utils`/url_escape().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#location_url().(path)))
101
102 def _finish_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(self), modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(model), locationscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(location)=True):
103 """Finish a JSON request with a model, setting relevant headers, etc."""
104 if locationscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(location):
105 locationscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(location) = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(self).location_urlscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#location_url().(modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(model)["path"])
106 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(self).set_header("Location", locationscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(location))
107 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(self).set_header("Last-Modified", modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(model)["last_modified"])
108 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(self).set_header("Content-Type", "application/json")
109 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(self).finishscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/APIHandler#finish().(jsonscip-python python python-stdlib 3.11 json/__init__:.dumpsscip-python python python-stdlib 3.11 json/dumps().(modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(model), defaultscip-python python python-stdlib 3.11 json/dumps().(default)=json_default))
110
111 async def _finish_errorscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_error().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_error().(self), codescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_error().(code), messagescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_error().(message)):
112 """Finish a JSON request with an error code and descriptive message"""
113 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_error().(self).set_status(codescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_error().(code))
114 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_error().(self).write(messagescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_error().(message))
115 await selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_error().(self).finishscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/APIHandler#finish().()
116
117 @web.authenticated
118 @authorizedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().
119 async def getscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(path)=""):
120 """Return a model for a file or directory.
121
122 A directory model contains a list of models (without content)
123 of the files and directories it contains.
124 """
125 pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(path) = pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(path) or ""
126 cm = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager().
127
128 type = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(self).get_query_argument("type", default=None)
129 if type not in {None, "directory", "file", "notebook"}:
130 # fall back to file if unknown type
131 type = "file"
132
133 format = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(self).get_query_argument("format", default=None)
134 if format not in {None, "text", "base64"}:
135 raise web.HTTPError(400, "Format %r is invalid" % format)
136 content_str = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(self).get_query_argument("content", default="1")
137 if content_str not in {"0", "1"}:
138 raise web.HTTPError(400, "Content %r is invalid" % content_str)
139 content = intscip-python python python-stdlib 3.11 builtins/int#(content_str or "")
140
141 hash_str = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(self).get_query_argument("hash", default="0")
142 if hash_str not in {"0", "1"}:
143 raise web.HTTPError(
144 400, f"Hash argument {hash_str!r} is invalid. It must be '0' or '1'."
145 )
146 require_hash = intscip-python python python-stdlib 3.11 builtins/int#(hash_str)
147
148 if not cm.allow_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#allow_hidden. and await ensure_async(cm.is_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#is_hidden().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(path))):
149 await selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(self)._finish_errorscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_error().(
150 HTTPStatusscip-python python python-stdlib 3.11 http/HTTPStatus#.NOT_FOUNDscip-python python python-stdlib 3.11 http/HTTPStatus#NOT_FOUND., f"file or directory {pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(path)!r} does not exist"
151 )
152 return
153
154 try:
155 expect_hash = require_hash
156 try:
157 model = await ensure_async(
158 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager()..getscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#get().(
159 pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#get().(path)=pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(path),
160 typescip-python python python-stdlib 3.11 builtins/type#=type,
161 formatscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#get().(format)=format,
162 contentscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#get().(content)=content,
163 require_hashscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#get().(require_hash)=require_hash,
164 )
165 )
166 except TypeErrorscip-python python python-stdlib 3.11 builtins/TypeError#:
167 # Fallback for ContentsManager not handling the require_hash argument
168 # introduced in 2.11
169 expect_hash = False
170 model = await ensure_async(
171 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager()..getscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#get().(
172 pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#get().(path)=pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(path),
173 typescip-python python python-stdlib 3.11 builtins/type#=type,
174 formatscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#get().(format)=format,
175 contentscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#get().(content)=content,
176 )
177 )
178 validate_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(model, expect_contentscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(expect_content)=content, expect_hashscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(expect_hash)=expect_hash)
179 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(self)._finish_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(model, locationscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(location)=False)
180 except web.HTTPError as exc:
181 # 404 is okay in this context, catch exception and return 404 code to prevent stack trace on client
182 if exc.status_code == HTTPStatusscip-python python python-stdlib 3.11 http/HTTPStatus#.NOT_FOUNDscip-python python python-stdlib 3.11 http/HTTPStatus#NOT_FOUND.:
183 await selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(self)._finish_errorscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_error().(
184 HTTPStatusscip-python python python-stdlib 3.11 http/HTTPStatus#.NOT_FOUNDscip-python python python-stdlib 3.11 http/HTTPStatus#NOT_FOUND., f"file or directory {pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#get().(path)!r} does not exist"
185 )
186 raise
187
188 @web.authenticated
189 @authorizedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().
190 async def patchscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#patch().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#patch().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#patch().(path)=""):
191 """PATCH renames a file or directory without re-uploading content."""
192 cm = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#patch().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager().
193 model = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#patch().(self).get_json_bodyscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#get_json_body().()
194 if model is None:
195 raise web.HTTPError(400, "JSON body missing")
196
197 old_path = model.getscip-python python python-stdlib 3.11 builtins/dict#get().("path")
198 if (
199 old_path
200 and not cm.allow_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#allow_hidden.
201 and (
202 await ensure_async(cm.is_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#is_hidden().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#patch().(path))) or await ensure_async(cm.is_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#is_hidden().(old_path))
203 )
204 ):
205 raise web.HTTPError(400, f"Cannot rename file or directory {pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#patch().(path)!r}")
206
207 model = await ensure_async(cm.updatescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#update().(model, pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#patch().(path)))
208 validate_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(model)
209 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#patch().(self)._finish_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(model)
210
211 async def _copyscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(self), copy_fromscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(copy_from), copy_toscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(copy_to)=None):
212 """Copy a file, optionally specifying a target directory."""
213 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(self).logscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#log()..infoscip-python python python-stdlib 3.11 logging/Logger#info().(
214 "Copying %r to %r",
215 copy_fromscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(copy_from),
216 copy_toscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(copy_to) or "",
217 )
218 model = await ensure_async(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager()..copyscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#copy().(copy_fromscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(copy_from), copy_toscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(copy_to)))
219 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(self).set_status(201)
220 validate_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(model)
221 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(self)._finish_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(model)
222
223 async def _uploadscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(self), modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(model), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(path)):
224 """Handle upload of a new file to path"""
225 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(self).logscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#log()..infoscip-python python python-stdlib 3.11 logging/Logger#info().("Uploading file to %s", pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(path))
226 modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(model) = await ensure_async(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager()..newscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#new().(modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(model), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(path)))
227 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(self).set_status(201)
228 validate_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(model))
229 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(self)._finish_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(model))
230
231 async def _new_untitledscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(path), typescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(type)="", extscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(ext)=""):
232 """Create a new, empty untitled entity"""
233 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(self).logscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#log()..infoscip-python python python-stdlib 3.11 logging/Logger#info().("Creating new %s in %s", typescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(type) or "file", pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(path))
234 model = await ensure_async(
235 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager()..new_untitledscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#new_untitled().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#new_untitled().(path)=pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(path), typescip-python python python-stdlib 3.11 builtins/type#=typescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(type), extscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#new_untitled().(ext)=extscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(ext))
236 )
237 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(self).set_status(201)
238 validate_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(model)
239 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(self)._finish_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(model)
240
241 async def _savescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(self), modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(model), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(path)):
242 """Save an existing file."""
243 chunk = modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(model).get("chunk", None)
244 if not chunk or chunk == -1: # Avoid tedious log information
245 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(self).logscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#log()..infoscip-python python python-stdlib 3.11 logging/Logger#info().("Saving file at %s", pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(path))
246 modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(model) = await ensure_async(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager()..savescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#save().(modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(model), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(path)))
247 validate_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/validate_model().(modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(model))
248 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(self)._finish_modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_finish_model().(modelscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(model))
249
250 @web.authenticated
251 @authorizedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().
252 async def postscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(path)=""):
253 """Create a new file in the specified path.
254
255 POST creates new files. The server always decides on the name.
256
257 POST /api/contents/path
258 New untitled, empty file or directory.
259 POST /api/contents/path
260 with body {"copy_from" : "/path/to/OtherNotebook.ipynb"}
261 New copy of OtherNotebook in path
262 """
263
264 cm = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager().
265
266 file_exists = await ensure_async(cm.file_existsscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#file_exists().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(path)))
267 if file_exists:
268 raise web.HTTPError(400, "Cannot POST to files, use PUT instead.")
269
270 model = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(self).get_json_bodyscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#get_json_body().()
271 if model:
272 copy_from = model.getscip-python python python-stdlib 3.11 builtins/dict#get().("copy_from")
273 if copy_from:
274 if not cm.allow_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#allow_hidden. and (
275 await ensure_async(cm.is_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#is_hidden().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(path)))
276 or await ensure_async(cm.is_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#is_hidden().(copy_from))
277 ):
278 raise web.HTTPError(400, f"Cannot copy file or directory {pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(path)!r}")
279 else:
280 await selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(self)._copyscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_copy().(copy_from, pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(path))
281 else:
282 ext = model.getscip-python python python-stdlib 3.11 builtins/dict#get().("ext", "")
283 type = model.getscip-python python python-stdlib 3.11 builtins/dict#get().("type", "")
284 if type not in {None, "", "directory", "file", "notebook"}:
285 # fall back to file if unknown type
286 type = "file"
287 await selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(self)._new_untitledscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(path), typescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(type)=type, extscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(ext)=ext)
288 else:
289 await selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(self)._new_untitledscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#post().(path))
290
291 @web.authenticated
292 @authorizedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().
293 async def putscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(path)=""):
294 """Saves the file in the location specified by name and path.
295
296 PUT is very similar to POST, but the requester specifies the name,
297 whereas with POST, the server picks the name.
298
299 PUT /api/contents/path/Name.ipynb
300 Save notebook at ``path/Name.ipynb``. Notebook structure is specified
301 in `content` key of JSON request body. If content is not specified,
302 create a new empty notebook.
303 """
304 model = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(self).get_json_bodyscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#get_json_body().()
305 cm = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager().
306
307 if model:
308 if model.getscip-python python python-stdlib 3.11 builtins/dict#get().("copy_from"):
309 raise web.HTTPError(400, "Cannot copy with PUT, only POST")
310 if not cm.allow_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#allow_hidden. and (
311 (model.getscip-python python python-stdlib 3.11 builtins/dict#get().("path") and await ensure_async(cm.is_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#is_hidden().(model.getscip-python python python-stdlib 3.11 builtins/dict#get().("path"))))
312 or await ensure_async(cm.is_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#is_hidden().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(path)))
313 ):
314 raise web.HTTPError(400, f"Cannot create file or directory {pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(path)!r}")
315
316 exists = await ensure_async(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager()..file_existsscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#file_exists().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(path)))
317 if model.getscip-python python python-stdlib 3.11 builtins/dict#get().("type", "") not in {None, "", "directory", "file", "notebook"}:
318 # fall back to file if unknown type
319 model["type"] = "file"
320 if exists:
321 await selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(self)._savescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_save().(model, pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(path))
322 else:
323 await selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(self)._uploadscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_upload().(model, pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(path))
324 else:
325 await selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(self)._new_untitledscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#_new_untitled().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#put().(path))
326
327 @web.authenticated
328 @authorizedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().
329 async def deletescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#delete().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#delete().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#delete().(path)=""):
330 """delete a file in the given path"""
331 cm = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#delete().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager().
332
333 if not cm.allow_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#allow_hidden. and await ensure_async(cm.is_hiddenscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#is_hidden().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#delete().(path))):
334 raise web.HTTPError(400, f"Cannot delete file or directory {pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#delete().(path)!r}")
335
336 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#delete().(self).logscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#log()..warningscip-python python python-stdlib 3.11 logging/Logger#warning().("delete %s", pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#delete().(path))
337 await ensure_async(cm.deletescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#delete().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#delete().(path)))
338 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#delete().(self).set_status(204)
339 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#delete().(self).finishscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/APIHandler#finish().()
340
341
342 class CheckpointsHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#(ContentsAPIHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsAPIHandler#):
343 """A checkpoints API handler."""
344
345 @web.authenticated
346 @authorizedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().
347 async def getscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#get().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#get().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#get().(path)=""):
348 """get lists checkpoints for a file"""
349 cm = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#get().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager().
350 checkpoints = await ensure_async(cm.list_checkpointsscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#list_checkpoints().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#get().(path)))
351 data = jsonscip-python python python-stdlib 3.11 json/__init__:.dumpsscip-python python python-stdlib 3.11 json/dumps().(checkpoints, defaultscip-python python python-stdlib 3.11 json/dumps().(default)=json_default)
352 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#get().(self).finishscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/APIHandler#finish().(data)
353
354 @web.authenticated
355 @authorizedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().
356 async def postscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#post().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#post().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#post().(path)=""):
357 """post creates a new checkpoint"""
358 cm = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#post().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager().
359 checkpoint = await ensure_async(cm.create_checkpointscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#create_checkpoint().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#post().(path)))
360 data = jsonscip-python python python-stdlib 3.11 json/__init__:.dumpsscip-python python python-stdlib 3.11 json/dumps().(checkpoint, defaultscip-python python python-stdlib 3.11 json/dumps().(default)=json_default)
361 location = url_path_joinscip-python python jupyter_server 2.20.0 `jupyter_server.utils`/url_path_join().(
362 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#post().(self).base_urlscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/AuthenticatedHandler#base_url().,
363 "api/contents",
364 url_escapescip-python python jupyter_server 2.20.0 `jupyter_server.utils`/url_escape().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#post().(path)),
365 "checkpoints",
366 url_escapescip-python python jupyter_server 2.20.0 `jupyter_server.utils`/url_escape().(checkpoint["id"]),
367 )
368 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#post().(self).set_header("Location", location)
369 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#post().(self).set_status(201)
370 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#post().(self).finishscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/APIHandler#finish().(data)
371
372
373 class ModifyCheckpointsHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#(ContentsAPIHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsAPIHandler#):
374 """A checkpoints modification handler."""
375
376 @web.authenticated
377 @authorizedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().
378 async def postscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#post().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#post().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#post().(path), checkpoint_idscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#post().(checkpoint_id)):
379 """post restores a file from a checkpoint"""
380 cm = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#post().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager().
381 await ensure_async(cm.restore_checkpointscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#restore_checkpoint().(checkpoint_idscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#post().(checkpoint_id), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#post().(path)))
382 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#post().(self).set_status(204)
383 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#post().(self).finishscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/APIHandler#finish().()
384
385 @web.authenticated
386 @authorizedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().
387 async def deletescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#delete().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#delete().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#delete().(path), checkpoint_idscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#delete().(checkpoint_id)):
388 """delete clears a checkpoint for a given file"""
389 cm = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#delete().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager().
390 await ensure_async(cm.delete_checkpointscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#delete_checkpoint().(checkpoint_idscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#delete().(checkpoint_id), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#delete().(path)))
391 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#delete().(self).set_status(204)
392 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#delete().(self).finishscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/APIHandler#finish().()
393
394
395 class NotebooksRedirectHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#(JupyterHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#):
396 """Redirect /api/notebooks to /api/contents"""
397
398 SUPPORTED_METHODSscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#SUPPORTED_METHODS. = (
399 "GET",
400 "PUT",
401 "PATCH",
402 "POST",
403 "DELETE",
404 )
405
406 @allow_unauthenticatedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/allow_unauthenticated().
407 def getscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#get().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#get().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#get().(path)):
408 """Handle a notebooks redirect."""
409 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#get().(self).logscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#log()..warningscip-python python python-stdlib 3.11 logging/Logger#warning().("/api/notebooks is deprecated, use /api/contents")
410 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#get().(self).redirect(url_path_joinscip-python python jupyter_server 2.20.0 `jupyter_server.utils`/url_path_join().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#get().(self).base_urlscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/AuthenticatedHandler#base_url()., "api/contents", url_escapescip-python python jupyter_server 2.20.0 `jupyter_server.utils`/url_escape().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#get().(path))))
411
412 putscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#put. = patchscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#patch. = postscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#post. = deletescip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#delete. = getscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#get().
413
414
415 class TrustNotebooksHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/TrustNotebooksHandler#(JupyterHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#):
416 """Handles trust/signing of notebooks"""
417
418 @web.authenticated
419 @authorizedscip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().(resourcescip-python python jupyter_server 2.20.0 `jupyter_server.auth.decorator`/authorized().(resource)=AUTH_RESOURCEscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/AUTH_RESOURCE.)
420 async def postscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/TrustNotebooksHandler#post().(selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/TrustNotebooksHandler#post().(self), pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/TrustNotebooksHandler#post().(path)=""):
421 """Trust a notebook by path."""
422 cm = selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/TrustNotebooksHandler#post().(self).contents_managerscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/JupyterHandler#contents_manager().
423 await ensure_async(cm.trust_notebookscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.manager`/ContentsManager#trust_notebook().(pathscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/TrustNotebooksHandler#post().(path)))
424 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/TrustNotebooksHandler#post().(self).set_status(201)
425 selfscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/TrustNotebooksHandler#post().(self).finish()
426
427
428 # -----------------------------------------------------------------------------
429 # URL to handler mappings
430 # -----------------------------------------------------------------------------
431
432
433 _checkpoint_id_regexscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_checkpoint_id_regex. = r"(?P<checkpoint_id>[\w-]+)"
434
435
436 default_handlersscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/default_handlers. = [
437 (r"/api/contents%s/checkpoints" % path_regexscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/path_regex., CheckpointsHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/CheckpointsHandler#),
438 (
439 rf"/api/contents{path_regexscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/path_regex.}/checkpoints/{_checkpoint_id_regexscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/_checkpoint_id_regex.}",
440 ModifyCheckpointsHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ModifyCheckpointsHandler#,
441 ),
442 (r"/api/contents%s/trust" % path_regexscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/path_regex., TrustNotebooksHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/TrustNotebooksHandler#),
443 (r"/api/contents%s" % path_regexscip-python python jupyter_server 2.20.0 `jupyter_server.base.handlers`/path_regex., ContentsHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/ContentsHandler#),
444 (r"/api/notebooks/?(.*)", NotebooksRedirectHandlerscip-python python jupyter_server 2.20.0 `jupyter_server.services.contents.handlers`/NotebooksRedirectHandler#),
445 ]