##// END OF EJS Templates
move `ipython notebook trust` to `ipython trust`...
MinRK -
Show More
@@ -83,13 +83,12 b' from IPython.kernel.zmq.kernelapp import ('
83 kernel_flags,
83 kernel_flags,
84 kernel_aliases,
84 kernel_aliases,
85 )
85 )
86 from IPython.nbformat import current, sign
87 from IPython.utils.importstring import import_item
86 from IPython.utils.importstring import import_item
88 from IPython.utils.localinterfaces import localhost
87 from IPython.utils.localinterfaces import localhost
89 from IPython.utils import submodule
88 from IPython.utils import submodule
90 from IPython.utils.traitlets import (
89 from IPython.utils.traitlets import (
91 Dict, Unicode, Integer, List, Bool, Bytes,
90 Dict, Unicode, Integer, List, Bool, Bytes,
92 DottedObjectName, Instance,
91 DottedObjectName
93 )
92 )
94 from IPython.utils import py3compat
93 from IPython.utils import py3compat
95 from IPython.utils.path import filefind, get_ipython_dir
94 from IPython.utils.path import filefind, get_ipython_dir
@@ -218,10 +217,6 b' class NotebookWebApplication(web.Application):'
218 return new_handlers
217 return new_handlers
219
218
220
219
221 #-----------------------------------------------------------------------------
222 # Subcommands
223 #-----------------------------------------------------------------------------
224
225 class NbserverListApp(BaseIPythonApplication):
220 class NbserverListApp(BaseIPythonApplication):
226
221
227 description="List currently running notebook servers in this profile."
222 description="List currently running notebook servers in this profile."
@@ -244,37 +239,6 b' class NbserverListApp(BaseIPythonApplication):'
244 else:
239 else:
245 print(serverinfo['url'], "::", serverinfo['notebook_dir'])
240 print(serverinfo['url'], "::", serverinfo['notebook_dir'])
246
241
247
248 class NotebookTrustApp(BaseIPythonApplication):
249
250 description="""Sign one or more IPython notebooks with your key,
251 to trust their dynamic (HTML, Javascript) output."""
252
253 examples="""ipython notebook trust mynotebook.ipynb"""
254
255 notary = Instance(sign.NotebookNotary)
256 def _notary_default(self):
257 return sign.NotebookNotary(parent=self, profile_dir=self.profile_dir)
258
259 def sign_notebook(self, notebook_path):
260 if not os.path.exists(notebook_path):
261 self.log.error("Notebook missing: %s" % notebook_path)
262 self.exit(1)
263 with io.open(notebook_path, encoding='utf8') as f:
264 nb = current.read(f, 'json')
265 self.notary.sign(nb)
266 with io.open(notebook_path, 'w', encoding='utf8') as f:
267 current.write(nb, f, 'json')
268
269 def start(self):
270 if not self.extra_args:
271 self.log.critical("Specify at least one notebook to sign.")
272 self.exit(1)
273
274 for notebook_path in self.extra_args:
275 print("Signing notebook: %s" % notebook_path)
276 self.sign_notebook(notebook_path)
277
278 #-----------------------------------------------------------------------------
242 #-----------------------------------------------------------------------------
279 # Aliases and Flags
243 # Aliases and Flags
280 #-----------------------------------------------------------------------------
244 #-----------------------------------------------------------------------------
@@ -349,7 +313,6 b' class NotebookApp(BaseIPythonApplication):'
349
313
350 subcommands = dict(
314 subcommands = dict(
351 list=(NbserverListApp, NbserverListApp.description.splitlines()[0]),
315 list=(NbserverListApp, NbserverListApp.description.splitlines()[0]),
352 trust=(NotebookTrustApp, NotebookTrustApp.description),
353 )
316 )
354
317
355 kernel_argv = List(Unicode)
318 kernel_argv = List(Unicode)
@@ -18,8 +18,11 b' import io'
18 import os
18 import os
19
19
20 from IPython.utils.py3compat import string_types, unicode_type, cast_bytes
20 from IPython.utils.py3compat import string_types, unicode_type, cast_bytes
21 from IPython.config import LoggingConfigurable
22 from IPython.utils.traitlets import Instance, Bytes, Enum, Any, Unicode
21 from IPython.utils.traitlets import Instance, Bytes, Enum, Any, Unicode
22 from IPython.config import LoggingConfigurable
23 from IPython.core.application import BaseIPythonApplication
24
25 from .current import read, write
23
26
24 #-----------------------------------------------------------------------------
27 #-----------------------------------------------------------------------------
25 # Code
28 # Code
@@ -198,6 +201,41 b' class NotebookNotary(LoggingConfigurable):'
198 if not cell.get('trusted', False):
201 if not cell.get('trusted', False):
199 return False
202 return False
200 return True
203 return True
204
205
206 class TrustNotebookApp(BaseIPythonApplication):
207
208 description="""Sign one or more IPython notebooks with your key,
209 to trust their dynamic (HTML, Javascript) output.
201
210
211 Otherwise, you will have to re-execute the notebook to see output.
212 """
213
214 examples="""ipython trust mynotebook.ipynb and_this_one.ipynb"""
215
216 notary = Instance(NotebookNotary)
217 def _notary_default(self):
218 return NotebookNotary(parent=self, profile_dir=self.profile_dir)
219
220 def sign_notebook(self, notebook_path):
221 if not os.path.exists(notebook_path):
222 self.log.error("Notebook missing: %s" % notebook_path)
223 self.exit(1)
224 with io.open(notebook_path, encoding='utf8') as f:
225 nb = read(f, 'json')
226 if self.notary.check_signature(nb):
227 print("Notebook already signed: %s" % notebook_path)
228 else:
229 print("Signing notebook: %s" % notebook_path)
230 self.notary.sign(nb)
231 with io.open(notebook_path, 'w', encoding='utf8') as f:
232 write(nb, f, 'json')
233
234 def start(self):
235 if not self.extra_args:
236 self.log.critical("Specify at least one notebook to sign.")
237 self.exit(1)
238
239 for notebook_path in self.extra_args:
240 self.sign_notebook(notebook_path)
202
241
203 No newline at end of file
@@ -249,6 +249,9 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
249 nbconvert=('IPython.nbconvert.nbconvertapp.NbConvertApp',
249 nbconvert=('IPython.nbconvert.nbconvertapp.NbConvertApp',
250 "Convert notebooks to/from other formats."
250 "Convert notebooks to/from other formats."
251 ),
251 ),
252 trust=('IPython.nbformat.sign.TrustNotebookApp',
253 "Sign notebooks to trust their potentially unsafe contents at load."
254 ),
252 ))
255 ))
253
256
254 # *do* autocreate requested profile, but don't create the config file.
257 # *do* autocreate requested profile, but don't create the config file.
General Comments 0
You need to be logged in to leave comments. Login now