1 1
import sys
2 1
from traitlets import Unicode, Enum
3

4 1
from ipypublish.postprocessors.base import IPyPostProcessor
5

6

7 1
class WriteStream(IPyPostProcessor):
8
    """ write the stream to the terminal
9
    """
10

11 1
    @property
12 1
    def allowed_mimetypes(self):
13 1
        return (
14
            "text/latex",
15
            "text/restructuredtext",
16
            "text/html",
17
            "text/x-python",
18
            "application/json",
19
            "text/markdown",
20
        )
21

22 1
    @property
23 1
    def requires_path(self):
24 1
        return True
25

26 1
    @property
27 1
    def logger_name(self):
28 1
        return "write-text-file"
29

30 1
    encoding = Unicode(
31
        default_value="utf8", help="the encoding of the output file"
32
    ).tag(config=True)
33

34 1
    pipe = Enum(
35
        ["stdout", "stderr", "stdin"],
36
        default_value="stdout",
37
        help="where to write the output to",
38
    ).tag(config=True)
39

40 1
    def run_postprocess(self, stream, mimetype, filepath, resources):
41

42 1
        self.logger.info("writing stream to {}".format(self.pipe))
43 1
        io_type = {"stdout": sys.stdout, "stdin": sys.stdin, "stderr": sys.stderr}.get(
44
            self.pipe
45
        )
46 1
        io_type.write(stream)
47

48 1
        return stream, filepath, resources

Read our documentation on viewing source code .

Loading