chrisjsewell / ipypublish
1 3
import sys
2 3
from traitlets import Unicode, Enum
3

4 3
from ipypublish.postprocessors.base import IPyPostProcessor
5

6

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

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

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

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

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

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

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

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

48 3
        return stream, filepath, resources

Read our documentation on viewing source code .

Loading