/usr/lib/python3/dist-packages/sagenb_export/text_writer.py is in python3-sagenb-export 3.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | from sagenb_export.logger import log
from sagenb_export.sagenb_reader import TextCell, ComputeCell
HEADER = u"""
Name: {nb.name}
"""
TEXT_CELL = u"""
Text: {cell.input}
"""
COMPUTE_CELL = u"""
In[{cell.index}]: {cell.input}
Out[{cell.index}]: {cell.output}
"""
class TextWriter(object):
def __init__(self, sagenb):
self.nb = sagenb
@property
def header(self):
return HEADER.format(nb=self.nb)
@property
def cells(self):
for cell in self.nb.cells:
if isinstance(cell, TextCell):
yield TEXT_CELL.format(cell=cell)
elif isinstance(cell, ComputeCell):
yield COMPUTE_CELL.format(cell=cell)
else:
log.critical('unknown cell: {0}'.format(cell))
def write(self, stream):
stream.write(self.header)
for cell in self.cells:
stream.write(cell)
|