From eb101169aa39f420107d1d602a65a2aea39eaa82 Mon Sep 17 00:00:00 2001 From: Chris Kirby Date: Sat, 15 Feb 2020 10:55:52 -0500 Subject: [PATCH 1/5] Added LICENSE to package data. Resolves #71. --- hide_code/{LICENSE.txt => LICENSE} | 0 setup.py | 4 +++- 2 files changed, 3 insertions(+), 1 deletion(-) rename hide_code/{LICENSE.txt => LICENSE} (100%) diff --git a/hide_code/LICENSE.txt b/hide_code/LICENSE similarity index 100% rename from hide_code/LICENSE.txt rename to hide_code/LICENSE diff --git a/setup.py b/setup.py index af377cc..381a780 100644 --- a/setup.py +++ b/setup.py @@ -54,6 +54,8 @@ 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', ], # What does your project relate to? @@ -74,7 +76,7 @@ # installed, specify them here. If using Python 2.6 or less, then these # have to be included in MANIFEST.in as well. package_data={ - 'hide_code': ['*.js','*.txt', os.path.join('Templates', '*'), 'hide_code_config.json'], + 'hide_code': ['*.js','*.txt', os.path.join('Templates', '*'), 'hide_code_config.json', 'LICENSE'], }, # Although 'package_data' is the preferred approach, in some case you may From 3ec5c275c1165036b0453594e5e3152227d4af85 Mon Sep 17 00:00:00 2001 From: Chris Kirby Date: Sat, 15 Feb 2020 11:04:27 -0500 Subject: [PATCH 2/5] Ignoring all notebook files. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 75e5579..c393b10 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ hide_code.sublime-workspace /hide_code/test/.ipynb_checkpoints/* *.iml *.idea +*ipynb From b779c806f3f57c562190e34c7eb3ceadb7479067 Mon Sep 17 00:00:00 2001 From: Chris Kirby Date: Sat, 15 Feb 2020 11:07:44 -0500 Subject: [PATCH 3/5] Updated file open encoding. Resolves #74 #80 --- hide_code/hide_code.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hide_code/hide_code.py b/hide_code/hide_code.py index 6a15107..fb7d151 100644 --- a/hide_code/hide_code.py +++ b/hide_code/hide_code.py @@ -22,7 +22,7 @@ class HideCodeHTMLExportHandler(IPythonHandler): def get(self, *args): self.log.info("hide_code: Starting HTML export for {}".format(args[-1])) - with open(ipynb_file_name(args)) as f: + with open(ipynb_file_name(args), encoding="utf-8") as f: nb = nbformat.reads(f.read(), as_version=4) exporter = HideCodeHTMLExporter() output_html, resources = exporter.from_notebook_node(nb) @@ -37,7 +37,7 @@ def get(self, *args): class HideCodePDFExportHandler(IPythonHandler): def get(self, *args): self.log.info("hide_code: Starting PDF export for {}".format(args[-1])) - with open(ipynb_file_name(args)) as f: + with open(ipynb_file_name(args), encoding="utf-8") as f: nb = nbformat.reads(f.read(), as_version=4) exporter = HideCodeHTMLExporter() output_html, resources = exporter.from_notebook_node(nb) @@ -53,7 +53,7 @@ def get(self, *args): class HideCodeLatexPDFExportHandler(IPythonHandler): def get(self, *args): self.log.info("hide_code: Starting Latex PDF export for {}".format(args[-1])) - with open(ipynb_file_name(args)) as f: + with open(ipynb_file_name(args), encoding="utf-8") as f: nb = nbformat.reads(f.read(), as_version=4) exporter = HideCodePDFExporter() output, resources = exporter.from_notebook_node(nb, resources={"metadata": {"name": notebook_name(args)}}) @@ -67,7 +67,7 @@ def get(self, *args): class HideCodeLatexExportHandler(IPythonHandler): def get(self, *args): self.log.info("hide_code: Starting Latex export for {}".format(args[-1])) - with open(ipynb_file_name(args)) as f: + with open(ipynb_file_name(args), encoding="utf-8") as f: nb = nbformat.reads(f.read(), as_version=4) exporter = HideCodeLatexExporter() output, resources = exporter.from_notebook_node(nb, resources={"metadata": {"name": notebook_name(args)}}) @@ -81,7 +81,7 @@ def get(self, *args): class HideCodeSlidesExportHandler(IPythonHandler): def get(self, *args): self.log.info("hide_code: Starting Slides export for {}".format(args[-1])) - with open(ipynb_file_name(args)) as f: + with open(ipynb_file_name(args), encoding="utf-8") as f: nb = nbformat.reads(f.read(), as_version=4) exporter = HideCodeSlidesExporter() output, resources = exporter.from_notebook_node(nb, resources={"metadata": {"name": notebook_name(args)}}) From 373bd28034432a60b9ccb3b7d0682e0238bfd9af Mon Sep 17 00:00:00 2001 From: Chris Kirby Date: Sat, 15 Feb 2020 11:14:25 -0500 Subject: [PATCH 4/5] Version bump. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 381a780..c94a118 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='0.5.2', + version='0.5.3', description='A Jupyter notebook extension to hide code, prompts and outputs.', long_description=long_description, From 6e622d6324a0d400140e779ffa7dc91174e2bacf Mon Sep 17 00:00:00 2001 From: Chris Kirby Date: Sat, 15 Feb 2020 11:44:03 -0500 Subject: [PATCH 5/5] Fixed Content-Disposition header to correctly pass filenames with spaces. Resolves #77 #62. --- hide_code/hide_code.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hide_code/hide_code.py b/hide_code/hide_code.py index fb7d151..1b46c4d 100644 --- a/hide_code/hide_code.py +++ b/hide_code/hide_code.py @@ -15,6 +15,7 @@ from .hide_code_config import HideCodeConfig as hc_config from .utils import Utils + notebook_dir = [] base_url = "" @@ -27,7 +28,7 @@ def get(self, *args): exporter = HideCodeHTMLExporter() output_html, resources = exporter.from_notebook_node(nb) self.set_header('Content-Type', 'text/html') - self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args) + '.html') + self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args, 'html')) self.flush() self.write(output_html) self.log.info("hide_code: Finished HTML export for {}".format(args[-1])) @@ -43,7 +44,7 @@ def get(self, *args): output_html, resources = exporter.from_notebook_node(nb) output = pdfkit.from_string(output_html, False) self.set_header('Content-Type', 'application/pdf') - self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args) + '.pdf') + self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args, 'pdf')) self.flush() self.write(output) self.log.info("hide_code: Finished PDF export for {}".format(args[-1])) @@ -57,7 +58,7 @@ def get(self, *args): nb = nbformat.reads(f.read(), as_version=4) exporter = HideCodePDFExporter() output, resources = exporter.from_notebook_node(nb, resources={"metadata": {"name": notebook_name(args)}}) - self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args) + '.pdf') + self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args, 'pdf')) self.flush() self.write(output) self.log.info("hide_code: Finished Latex PDF export for {}".format(args[-1])) @@ -71,7 +72,7 @@ def get(self, *args): nb = nbformat.reads(f.read(), as_version=4) exporter = HideCodeLatexExporter() output, resources = exporter.from_notebook_node(nb, resources={"metadata": {"name": notebook_name(args)}}) - self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args) + '.tex') + self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args, 'tex')) self.flush() self.write(output) self.log.info("hide_code: Finished Latex export for {}".format(args[-1])) @@ -85,7 +86,7 @@ def get(self, *args): nb = nbformat.reads(f.read(), as_version=4) exporter = HideCodeSlidesExporter() output, resources = exporter.from_notebook_node(nb, resources={"metadata": {"name": notebook_name(args)}}) - self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args) + '.html') + self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args, 'html')) self.flush() self.write(output) self.log.info("hide_code: Finished Slides export for {}".format(args[-1])) @@ -303,12 +304,13 @@ def route_pattern_for(exporter): return url_path_join(base_url, 'notebooks/([^/]+)' + pattern, 'export', exporter) -def notebook_name(params): +def notebook_name(params, filetype): """ - Returns notebook name without .ipynb extension. + Returns URL encoded notebook name without .ipynb extension. """ args = [param.replace('/', '') for param in params if param is not None] - return args[-1][:-6] + print(args) + return '"{}.{}"'.format(args[-1][:-6], filetype) def ipynb_file_name(params):