本文整理匯總了Python中pygments.cmdline.main方法的典型用法代碼示例。如果您正苦於以下問題:Python cmdline.main方法的具體用法?Python cmdline.main怎麽用?Python cmdline.main使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pygments.cmdline
的用法示例。
在下文中一共展示了cmdline.main方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_cmdline
# 需要導入模塊: from pygments import cmdline [as 別名]
# 或者: from pygments.cmdline import main [as 別名]
def run_cmdline(*args, **kwds):
saved_stdin = sys.stdin
saved_stdout = sys.stdout
saved_stderr = sys.stderr
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')
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(), \
stderr_buffer.getvalue()
return (ret, _decode_output(out), _decode_output(err))