本文整理汇总了Python中pex.pex.PEX.minimum_sys_modules方法的典型用法代码示例。如果您正苦于以下问题:Python PEX.minimum_sys_modules方法的具体用法?Python PEX.minimum_sys_modules怎么用?Python PEX.minimum_sys_modules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pex.pex.PEX
的用法示例。
在下文中一共展示了PEX.minimum_sys_modules方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_minimum_sys_modules
# 需要导入模块: from pex.pex import PEX [as 别名]
# 或者: from pex.pex.PEX import minimum_sys_modules [as 别名]
def test_minimum_sys_modules():
# builtins stay
builtin_module = ModuleType('my_builtin')
modules = {'my_builtin': builtin_module}
new_modules = PEX.minimum_sys_modules([], modules)
assert new_modules == modules
new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
assert new_modules == modules
# tainted evict
tainted_module = ModuleType('tainted_module')
tainted_module.__path__ = ['bad_path']
modules = {'tainted_module': tainted_module}
new_modules = PEX.minimum_sys_modules([], modules)
assert new_modules == modules
new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
assert new_modules == {}
assert tainted_module.__path__ == []
# tainted cleaned
tainted_module = ModuleType('tainted_module')
tainted_module.__path__ = ['bad_path', 'good_path']
modules = {'tainted_module': tainted_module}
new_modules = PEX.minimum_sys_modules([], modules)
assert new_modules == modules
new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
assert new_modules == modules
assert tainted_module.__path__ == ['good_path']
示例2: test_minimum_sys_modules
# 需要导入模块: from pex.pex import PEX [as 别名]
# 或者: from pex.pex.PEX import minimum_sys_modules [as 别名]
def test_minimum_sys_modules():
# builtins stay
builtin_module = ModuleType('my_builtin')
modules = {'my_builtin': builtin_module}
new_modules = PEX.minimum_sys_modules([], modules)
assert new_modules == modules
new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
assert new_modules == modules
# tainted evict
tainted_module = ModuleType('tainted_module')
tainted_module.__path__ = ['bad_path']
modules = {'tainted_module': tainted_module}
new_modules = PEX.minimum_sys_modules([], modules)
assert new_modules == modules
new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
assert new_modules == {}
assert tainted_module.__path__ == []
# tainted cleaned
tainted_module = ModuleType('tainted_module')
tainted_module.__path__ = ['bad_path', 'good_path']
modules = {'tainted_module': tainted_module}
new_modules = PEX.minimum_sys_modules([], modules)
assert new_modules == modules
new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
assert new_modules == modules
assert tainted_module.__path__ == ['good_path']
# If __path__ is not a list the module is removed; typically this implies
# it's a namespace package (https://www.python.org/dev/peps/pep-0420/) where
# __path__ is a _NamespacePath.
try:
from importlib._bootstrap_external import _NamespacePath
bad_path = _NamespacePath("hello", "world", None)
except ImportError:
bad_path = {"hello": "world"}
class FakeModule(object):
pass
tainted_module = FakeModule()
tainted_module.__path__ = bad_path # Not a list as expected
modules = {'tainted_module': tainted_module}
new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
assert new_modules == {}