Skip to content

Commit 0a75534

Browse files
authored
maybe formating?
1 parent eb0fa0a commit 0a75534

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

nbformat/reader.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@
66
import json
77
from .validator import ValidationError
88

9+
910
class NotJSONError(ValueError):
1011
pass
1112

13+
1214
def parse_json(s, **kwargs):
1315
"""Parse a JSON string into a dict."""
1416
try:
1517
nb_dict = json.loads(s, **kwargs)
1618
except ValueError as e:
1719
# Limit the error message to 80 characters. Display whatever JSON will fit.
18-
raise NotJSONError(("Notebook does not appear to be JSON: %r" % s)[:77] + "...") from e
20+
raise NotJSONError(("Notebook does not appear to be JSON: %r" % s)[
21+
:77] + "...") from e
1922
return nb_dict
2023

2124
# High level API
2225

26+
2327
def get_version(nb):
2428
"""Get the version of a notebook.
2529
@@ -53,24 +57,25 @@ def reads(s, **kwargs):
5357
-------
5458
nb : NotebookNode
5559
The notebook that was read.
56-
60+
5761
Raises
5862
------
5963
ValidationError
6064
Notebook JSON for a given version is missing an expected key and cannot be read.
61-
65+
6266
NBFormatError
6367
Specified major version is invalid or unsupported.
6468
"""
6569
from . import versions, NBFormatError
66-
70+
6771
nb_dict = parse_json(s, **kwargs)
6872
(major, minor) = get_version(nb_dict)
6973
if major in versions:
7074
try:
7175
return versions[major].to_notebook_json(nb_dict, minor=minor)
7276
except AttributeError as e:
73-
raise ValidationError(f"The notebook is invalid and is missing an expected key: {e}")
77+
raise ValidationError(
78+
f"The notebook is invalid and is missing an expected key: {e}")
7479
else:
7580
raise NBFormatError('Unsupported nbformat version %s' % major)
7681

@@ -92,4 +97,3 @@ def read(fp, **kwargs):
9297
The notebook that was read.
9398
"""
9499
return reads(fp.read(), **kwargs)
95-

nbformat/v3/rwbase.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ def restore_bytes(nb):
2323
if "png" in output:
2424
output.png = output.png.encode("ascii", "replace")
2525
if "jpeg" in output:
26-
output.jpeg = output.jpeg.encode("ascii", "replace")
26+
output.jpeg = output.jpeg.encode(
27+
"ascii", "replace")
2728
except KeyError as e:
28-
raise validator.ValidationError(f"The notebook was invalid missing the key: {e.message}")
29+
raise validator.ValidationError(
30+
f"The notebook was invalid missing the key: {e.message}")
2931
return nb
3032

33+
3134
# output keys that are likely to have multiline values
3235
_multiline_outputs = ['text', 'html', 'svg', 'latex', 'javascript', 'json']
3336

@@ -67,7 +70,7 @@ def rejoin_lines(nb):
6770
item = output.get(key, None)
6871
if isinstance(item, list):
6972
output[key] = _join_lines(item)
70-
else: # text, heading cell
73+
else: # text, heading cell
7174
for key in ['source', 'rendered']:
7275
item = cell.get(key, None)
7376
if isinstance(item, list):
@@ -93,7 +96,7 @@ def split_lines(nb):
9396
item = output.get(key, None)
9497
if isinstance(item, str):
9598
output[key] = item.splitlines(True)
96-
else: # text, heading cell
99+
else: # text, heading cell
97100
for key in ['source', 'rendered']:
98101
item = cell.get(key, None)
99102
if isinstance(item, str):
@@ -103,6 +106,7 @@ def split_lines(nb):
103106
# b64 encode/decode are never actually used, because all bytes objects in
104107
# the notebook are already b64-encoded, and we don't need/want to double-encode
105108

109+
106110
def base64_decode(nb):
107111
"""Restore all bytes objects in the notebook from base64-encoded strings.
108112
@@ -179,8 +183,5 @@ def writes(self, nb, **kwargs):
179183

180184
def write(self, nb, fp, **kwargs):
181185
"""Write a notebook to a file like object"""
182-
nbs = self.writes(nb,**kwargs)
186+
nbs = self.writes(nb, **kwargs)
183187
return fp.write(nbs)
184-
185-
186-

0 commit comments

Comments
 (0)