diff --git a/sandbox/grist/engine.py b/sandbox/grist/engine.py index 7f4926bc..c5ddf87d 100644 --- a/sandbox/grist/engine.py +++ b/sandbox/grist/engine.py @@ -24,6 +24,7 @@ from codebuilder import DOLLAR_REGEX import depend import docactions import docmodel +from fake_std_streams import FakeStdStreams import gencode import logger import match_counter @@ -944,9 +945,11 @@ class Engine(object): raise depend.CircularRefError("Circular Reference") if not col.is_formula(): value = col.get_cell_value(int(record), restore=True) - result = col.method(record, table.user_table, value, self._user) + with FakeStdStreams(): + result = col.method(record, table.user_table, value, self._user) else: - result = col.method(record, table.user_table) + with FakeStdStreams(): + result = col.method(record, table.user_table) if self._cell_required_error: raise self._cell_required_error # pylint: disable=raising-bad-type self.formula_tracer(col, record) diff --git a/sandbox/grist/fake_std_streams.py b/sandbox/grist/fake_std_streams.py new file mode 100644 index 00000000..e15a0a99 --- /dev/null +++ b/sandbox/grist/fake_std_streams.py @@ -0,0 +1,18 @@ +import sys + +import six + + +class FakeStdStreams(object): + """ + Redirects stdout and stderr to StringIO. + """ + def __enter__(self): + self._orig_stdout = sys.stdout + self._orig_stderr = sys.stderr + sys.stdout = six.StringIO() + sys.stderr = six.StringIO() + + def __exit__(self, exc_type, exc_val, exc_tb): + sys.stdout = self._orig_stdout + sys.stderr = self._orig_stderr