Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/nbformat/v1/rwbase.py: 54%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Base classes and function for readers and writers.
3Authors:
5* Brian Granger
6"""
8# -----------------------------------------------------------------------------
9# Copyright (C) 2008-2011 The IPython Development Team
10#
11# Distributed under the terms of the BSD License. The full license is in
12# the file LICENSE, distributed as part of this software.
13# -----------------------------------------------------------------------------
15# -----------------------------------------------------------------------------
16# Imports
17# -----------------------------------------------------------------------------
19# -----------------------------------------------------------------------------
20# Code
21# -----------------------------------------------------------------------------
22from __future__ import annotations
25class NotebookReader:
26 """The base notebook reader."""
28 def reads(self, s, **kwargs):
29 """Read a notebook from a string."""
30 msg = "loads must be implemented in a subclass"
31 raise NotImplementedError(msg)
33 def read(self, fp, **kwargs):
34 """Read a notebook from a file like object"""
35 return self.reads(fp.read(), **kwargs)
38class NotebookWriter:
39 """The base notebook writer."""
41 def writes(self, nb, **kwargs):
42 """Write a notebook to a string."""
43 msg = "loads must be implemented in a subclass"
44 raise NotImplementedError(msg)
46 def write(self, nb, fp, **kwargs):
47 """Write a notebook to a file like object"""
48 return fp.write(self.writes(nb, **kwargs))