def run_cmdline(*args, **kwds): saved_stdin = sys.stdin saved_stdout = sys.stdout saved_stderr = sys.stderr if sys.version_info > (3,): stdin_buffer = BytesIO() stdout_buffer = BytesIO() stderr_buffer = BytesIO() new_stdin = sys.stdin = io.TextIOWrapper(stdin_buffer, 'utf-8') new_stdout = sys.stdout = io.TextIOWrapper(stdout_buffer, 'utf-8') new_stderr = sys.stderr = io.TextIOWrapper(stderr_buffer, 'utf-8') else: stdin_buffer = new_stdin = sys.stdin = StringIO() stdout_buffer = new_stdout = sys.stdout = StringIO() stderr_buffer = new_stderr = sys.stderr = StringIO() new_stdin.write(kwds.get('stdin', '')) new_stdin.seek(0, 0) try: ret = cmdline.main(['pygmentize'] + list(args)) finally: sys.stdin = saved_stdin sys.stdout = saved_stdout sys.stderr = saved_stderr new_stdout.flush() new_stderr.flush() out, err = stdout_buffer.getvalue().decode('utf-8'), \ stderr_buffer.getvalue().decode('utf-8') return (ret, out, err)
def run_cmdline(*args, **kwds): saved_stdin = sys.stdin saved_stdout = sys.stdout saved_stderr = sys.stderr if sys.version_info > (3, ): stdin_buffer = BytesIO() stdout_buffer = BytesIO() stderr_buffer = BytesIO() new_stdin = sys.stdin = io.TextIOWrapper(stdin_buffer, 'utf-8') new_stdout = sys.stdout = io.TextIOWrapper(stdout_buffer, 'utf-8') new_stderr = sys.stderr = io.TextIOWrapper(stderr_buffer, 'utf-8') else: stdin_buffer = new_stdin = sys.stdin = StringIO() stdout_buffer = new_stdout = sys.stdout = StringIO() stderr_buffer = new_stderr = sys.stderr = StringIO() new_stdin.write(kwds.get('stdin', '')) new_stdin.seek(0, 0) try: ret = cmdline.main(['pygmentize'] + list(args)) finally: sys.stdin = saved_stdin sys.stdout = saved_stdout sys.stderr = saved_stderr new_stdout.flush() new_stderr.flush() out, err = stdout_buffer.getvalue().decode('utf-8'), \ stderr_buffer.getvalue().decode('utf-8') return (ret, out, err)
def run_cmdline(*args): saved_stdout = sys.stdout saved_stderr = sys.stderr if sys.version_info > (3,): stdout_buffer = BytesIO() stderr_buffer = BytesIO() new_stdout = sys.stdout = io.TextIOWrapper(stdout_buffer, 'utf-8') new_stderr = sys.stderr = io.TextIOWrapper(stderr_buffer, 'utf-8') else: stdout_buffer = new_stdout = sys.stdout = StringIO() stderr_buffer = new_stderr = sys.stderr = StringIO() try: ret = cmdline.main(["pygmentize"] + list(args)) finally: sys.stdout = saved_stdout sys.stderr = saved_stderr new_stdout.flush() new_stderr.flush() out, err = stdout_buffer.getvalue().decode('utf-8'), \ stderr_buffer.getvalue().decode('utf-8') return (ret, out, err)