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

13 statements  

1"""Base classes and function for readers and writers. 

2 

3Authors: 

4 

5* Brian Granger 

6""" 

7 

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# ----------------------------------------------------------------------------- 

14 

15# ----------------------------------------------------------------------------- 

16# Imports 

17# ----------------------------------------------------------------------------- 

18 

19# ----------------------------------------------------------------------------- 

20# Code 

21# ----------------------------------------------------------------------------- 

22from __future__ import annotations 

23 

24 

25class NotebookReader: 

26 """The base notebook reader.""" 

27 

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) 

32 

33 def read(self, fp, **kwargs): 

34 """Read a notebook from a file like object""" 

35 return self.reads(fp.read(), **kwargs) 

36 

37 

38class NotebookWriter: 

39 """The base notebook writer.""" 

40 

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) 

45 

46 def write(self, nb, fp, **kwargs): 

47 """Write a notebook to a file like object""" 

48 return fp.write(self.writes(nb, **kwargs))