本文整理汇总了Python中lib2to3.refactor.get_fixers_from_package方法的典型用法代码示例。如果您正苦于以下问题:Python refactor.get_fixers_from_package方法的具体用法?Python refactor.get_fixers_from_package怎么用?Python refactor.get_fixers_from_package使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib2to3.refactor
的用法示例。
在下文中一共展示了refactor.get_fixers_from_package方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fixer_loading_helpers
# 需要导入模块: from lib2to3 import refactor [as 别名]
# 或者: from lib2to3.refactor import get_fixers_from_package [as 别名]
def test_fixer_loading_helpers(self):
contents = ["explicit", "first", "last", "parrot", "preorder"]
non_prefixed = refactor.get_all_fix_names("myfixes")
prefixed = refactor.get_all_fix_names("myfixes", False)
full_names = refactor.get_fixers_from_package("myfixes")
self.assertEqual(prefixed, ["fix_" + name for name in contents])
self.assertEqual(non_prefixed, contents)
self.assertEqual(full_names,
["myfixes.fix_" + name for name in contents])
示例2: test_crlf_newlines
# 需要导入模块: from lib2to3 import refactor [as 别名]
# 或者: from lib2to3.refactor import get_fixers_from_package [as 别名]
def test_crlf_newlines(self):
old_sep = os.linesep
os.linesep = "\r\n"
try:
fn = os.path.join(TEST_DATA_DIR, "crlf.py")
fixes = refactor.get_fixers_from_package("lib2to3.fixes")
self.check_file_refactoring(fn, fixes)
finally:
os.linesep = old_sep
示例3: get_refactorer
# 需要导入模块: from lib2to3 import refactor [as 别名]
# 或者: from lib2to3.refactor import get_fixers_from_package [as 别名]
def get_refactorer(fixer_pkg="lib2to3", fixers=None, options=None):
"""
A convenience function for creating a RefactoringTool for tests.
fixers is a list of fixers for the RefactoringTool to use. By default
"lib2to3.fixes.*" is used. options is an optional dictionary of options to
be passed to the RefactoringTool.
"""
if fixers is not None:
fixers = [fixer_pkg + ".fixes.fix_" + fix for fix in fixers]
else:
fixers = refactor.get_fixers_from_package(fixer_pkg + ".fixes")
options = options or {}
return refactor.RefactoringTool(fixers, options, explicit=True)
示例4: __build_fixer_names
# 需要导入模块: from lib2to3 import refactor [as 别名]
# 或者: from lib2to3.refactor import get_fixers_from_package [as 别名]
def __build_fixer_names(self):
if self.fixer_names: return
self.fixer_names = []
for p in setuptools.lib2to3_fixer_packages:
self.fixer_names.extend(get_fixers_from_package(p))
if self.distribution.use_2to3_fixers is not None:
for p in self.distribution.use_2to3_fixers:
self.fixer_names.extend(get_fixers_from_package(p))
示例5: __build_fixer_names
# 需要导入模块: from lib2to3 import refactor [as 别名]
# 或者: from lib2to3.refactor import get_fixers_from_package [as 别名]
def __build_fixer_names(self):
if self.fixer_names:
return
self.fixer_names = []
for p in setuptools.lib2to3_fixer_packages:
self.fixer_names.extend(get_fixers_from_package(p))
if self.distribution.use_2to3_fixers is not None:
for p in self.distribution.use_2to3_fixers:
self.fixer_names.extend(get_fixers_from_package(p))
示例6: convert_with_2to3
# 需要导入模块: from lib2to3 import refactor [as 别名]
# 或者: from lib2to3.refactor import get_fixers_from_package [as 别名]
def convert_with_2to3(filepath: str) -> str:
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
from lib2to3.pgen2.parse import ParseError
fixers = get_fixers_from_package('lib2to3.fixes')
refactoring_tool = RefactoringTool(fixers)
source = refactoring_tool._read_python_source(filepath)[0]
try:
tree = refactoring_tool.refactor_string(source, 'conf.py')
except ParseError as err:
# do not propagate lib2to3 exceptions
lineno, offset = err.context[1]
# try to match ParseError details with SyntaxError details
raise SyntaxError(err.msg, (filepath, lineno, offset, err.value))
return str(tree)