Esempio n. 1
0
def execwrap(content, from_file=None):
    from_file = from_file or '<stdin>'
    if isinstance(content, six.string_types):
        content = compile_text(content, from_file=from_file)

    def _inner():
        global_env = exec_globals()
        local_env = global_env
        six.exec_(content, global_env, local_env)
        return global_env

    globals_ = {}
    output_handler = None
    try:
        with reopen_stdout_stderr() as output_handler:
            globals_ = _inner()
    except Exception:
        if output_handler is not None:
            output = "%s%s" % (output_handler.read(),
                               _exception(from_file))
        else:
            output = _exception(from_file)
    else:
        output = output_handler.read()

    output = strutil.ensure_text(output)

    return output, globals_
Esempio n. 2
0
def execwrap(content, from_file=None):
    from_file = from_file or '<stdin>'
    if isinstance(content, six.string_types):
        content = compile_text(content, from_file=from_file)

    def _inner():
        global_env = exec_globals()
        local_env = global_env
        six.exec_(content, global_env, local_env)
        return global_env

    globals_ = {}
    output_handler = None
    try:
        with reopen_stdout_stderr() as output_handler:
            globals_ = _inner()
    except Exception:
        if output_handler is not None:
            output = "%s%s" % (output_handler.read(), _exception(from_file))
        else:
            output = _exception(from_file)
    else:
        output = output_handler.read()

    output = strutil.ensure_text(output)

    return output, globals_
Esempio n. 3
0
 def test_ensure_text_already(self):
     result = strutil.ensure_text(self.text)
     assert isinstance(result, six.text_type)
     assert result is self.text
Esempio n. 4
0
 def test_ensure_text_non_str(self):
     result = strutil.ensure_text(self.number)
     assert result is self.number
Esempio n. 5
0
 def test_ensure_text(self):
     result = strutil.ensure_text(self.string)
     assert isinstance(result, six.text_type)
Esempio n. 6
0
def next_handler(app):
    buffer_names = app.engine.contents()
    next_buf = buffers.next_buffer(buffer_names,
                                   app.buffers.current_name(None))
    app.buffers.push_focus(None, strutil.ensure_text(next_buf))
Esempio n. 7
0
 def test_ensure_text_already(self):
     result = strutil.ensure_text(self.text)
     assert isinstance(result, six.text_type)
     assert result is self.text
Esempio n. 8
0
 def test_ensure_text_non_str(self):
     result = strutil.ensure_text(self.number)
     assert result is self.number
Esempio n. 9
0
 def test_ensure_text(self):
     result = strutil.ensure_text(self.string)
     assert isinstance(result, six.text_type)