本文整理汇总了Python中lib2to3.main.main方法的典型用法代码示例。如果您正苦于以下问题:Python main.main方法的具体用法?Python main.main怎么用?Python main.main使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib2to3.main
的用法示例。
在下文中一共展示了main.main方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tearDown
# 需要导入模块: from lib2to3 import main [as 别名]
# 或者: from lib2to3.main import main [as 别名]
def tearDown(self):
# Clean up logging configuration down by main.
del logging.root.handlers[:]
if self.temp_dir:
shutil.rmtree(self.temp_dir)
示例2: run_2to3_capture
# 需要导入模块: from lib2to3 import main [as 别名]
# 或者: from lib2to3.main import main [as 别名]
def run_2to3_capture(self, args, in_capture, out_capture, err_capture):
save_stdin = sys.stdin
save_stdout = sys.stdout
save_stderr = sys.stderr
sys.stdin = in_capture
sys.stdout = out_capture
sys.stderr = err_capture
try:
return main.main("lib2to3.fixes", args)
finally:
sys.stdin = save_stdin
sys.stdout = save_stdout
sys.stderr = save_stderr
示例3: tearDown
# 需要导入模块: from lib2to3 import main [as 别名]
# 或者: from lib2to3.main import main [as 别名]
def tearDown(self):
# Clean up logging configuration down by main.
del logging.root.handlers[:]
示例4: script_to_py3
# 需要导入模块: from lib2to3 import main [as 别名]
# 或者: from lib2to3.main import main [as 别名]
def script_to_py3(script):
"""Convert a script to Python3 syntax if required."""
if sys.version_info[0] < 3:
return script
import tempfile
f = tempfile.NamedTemporaryFile(suffix=".py", delete=False)
f.write(script.encode())
f.flush()
filename = f.name
f.close()
# 2to3 is way too chatty
import logging
logging.basicConfig(filename=os.devnull)
from lib2to3.main import main
if main("lib2to3.fixes", ['--no-diffs', '-w', '-n', filename]):
raise Exception('py3 conversion failed')
f2 = open(filename)
try:
return f2.read()
finally:
f2.close()
os.remove(filename)