当前位置: 首页>>代码示例>>Python>>正文


Python setuptools.sandbox方法代码示例

本文整理汇总了Python中setuptools.sandbox方法的典型用法代码示例。如果您正苦于以下问题:Python setuptools.sandbox方法的具体用法?Python setuptools.sandbox怎么用?Python setuptools.sandbox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在setuptools的用法示例。


在下文中一共展示了setuptools.sandbox方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _no_sandbox

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def _no_sandbox(function):
    def __no_sandbox(*args, **kw):
        try:
            from setuptools.sandbox import DirectorySandbox
            if not hasattr(DirectorySandbox, '_old'):
                def violation(*args):
                    pass
                DirectorySandbox._old = DirectorySandbox._violation
                DirectorySandbox._violation = violation
                patched = True
            else:
                patched = False
        except ImportError:
            patched = False

        try:
            return function(*args, **kw)
        finally:
            if patched:
                DirectorySandbox._violation = DirectorySandbox._old
                del DirectorySandbox._old

    return __no_sandbox 
开发者ID:bunbun,项目名称:nested-dict,代码行数:25,代码来源:ez_setup.py

示例2: test_unpickleable_exception_when_hiding_setuptools

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_unpickleable_exception_when_hiding_setuptools(self):
        """
        As revealed in #440, an infinite recursion can occur if an unpickleable
        exception while setuptools is hidden. Ensure this doesn't happen.
        """

        class ExceptionUnderTest(Exception):
            """
            An unpickleable exception (not in globals).
            """

        with pytest.raises(setuptools.sandbox.UnpickleableException) as caught:
            with setuptools.sandbox.save_modules():
                setuptools.sandbox.hide_setuptools()
                raise ExceptionUnderTest()

        msg, = caught.value.args
        assert msg == 'ExceptionUnderTest()' 
开发者ID:pypa,项目名称:setuptools,代码行数:20,代码来源:test_sandbox.py

示例3: _rename_path

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def _rename_path(path):
    new_name = path + '.OLD.%s' % time.time()
    log.warn('Renaming %s into %s', path, new_name)
    try:
        from setuptools.sandbox import DirectorySandbox
        def _violation(*args):
            pass
        DirectorySandbox._violation = _violation
    except ImportError:
        pass

    os.rename(path, new_name)
    return new_name 
开发者ID:arcpy,项目名称:sample-gp-tools,代码行数:15,代码来源:distribute_setup.py

示例4: test_devnull

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_devnull(self, tmpdir):
        with setuptools.sandbox.DirectorySandbox(str(tmpdir)):
            self._file_writer(os.devnull) 
开发者ID:pypa,项目名称:setuptools,代码行数:5,代码来源:test_sandbox.py

示例5: test_setup_py_with_BOM

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_setup_py_with_BOM(self):
        """
        It should be possible to execute a setup.py with a Byte Order Mark
        """
        target = pkg_resources.resource_filename(
            __name__,
            'script-with-bom.py')
        namespace = types.ModuleType('namespace')
        setuptools.sandbox._execfile(target, vars(namespace))
        assert namespace.result == 'passed' 
开发者ID:pypa,项目名称:setuptools,代码行数:12,代码来源:test_sandbox.py

示例6: test_setup_py_with_CRLF

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_setup_py_with_CRLF(self, tmpdir):
        setup_py = tmpdir / 'setup.py'
        with setup_py.open('wb') as stream:
            stream.write(b'"degenerate script"\r\n')
        setuptools.sandbox._execfile(str(setup_py), globals()) 
开发者ID:pypa,项目名称:setuptools,代码行数:7,代码来源:test_sandbox.py

示例7: test_exception_trapped

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_exception_trapped(self):
        with setuptools.sandbox.ExceptionSaver():
            raise ValueError("details") 
开发者ID:pypa,项目名称:setuptools,代码行数:5,代码来源:test_sandbox.py

示例8: test_exception_resumed

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_exception_resumed(self):
        with setuptools.sandbox.ExceptionSaver() as saved_exc:
            raise ValueError("details")

        with pytest.raises(ValueError) as caught:
            saved_exc.resume()

        assert isinstance(caught.value, ValueError)
        assert str(caught.value) == 'details' 
开发者ID:pypa,项目名称:setuptools,代码行数:11,代码来源:test_sandbox.py

示例9: test_no_exception_passes_quietly

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_no_exception_passes_quietly(self):
        with setuptools.sandbox.ExceptionSaver() as saved_exc:
            pass

        saved_exc.resume() 
开发者ID:pypa,项目名称:setuptools,代码行数:7,代码来源:test_sandbox.py

示例10: test_unpickleable_exception

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_unpickleable_exception(self):
        class CantPickleThis(Exception):
            "This Exception is unpickleable because it's not in globals"
            def __repr__(self):
                return 'CantPickleThis%r' % (self.args,)

        with setuptools.sandbox.ExceptionSaver() as saved_exc:
            raise CantPickleThis('detail')

        with pytest.raises(setuptools.sandbox.UnpickleableException) as caught:
            saved_exc.resume()

        assert str(caught.value) == "CantPickleThis('detail',)" 
开发者ID:pypa,项目名称:setuptools,代码行数:15,代码来源:test_sandbox.py

示例11: test_sandbox_violation_raised_hiding_setuptools

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_sandbox_violation_raised_hiding_setuptools(self, tmpdir):
        """
        When in a sandbox with setuptools hidden, a SandboxViolation
        should reflect a proper exception and not be wrapped in
        an UnpickleableException.
        """

        def write_file():
            "Trigger a SandboxViolation by writing outside the sandbox"
            with open('/etc/foo', 'w'):
                pass

        with pytest.raises(setuptools.sandbox.SandboxViolation) as caught:
            with setuptools.sandbox.save_modules():
                setuptools.sandbox.hide_setuptools()
                with setuptools.sandbox.DirectorySandbox(str(tmpdir)):
                    write_file()

        cmd, args, kwargs = caught.value.args
        assert cmd == 'open'
        assert args == ('/etc/foo', 'w')
        assert kwargs == {}

        msg = str(caught.value)
        assert 'open' in msg
        assert "('/etc/foo', 'w')" in msg 
开发者ID:pypa,项目名称:setuptools,代码行数:28,代码来源:test_sandbox.py

示例12: user_install_setup_context

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def user_install_setup_context(self, *args, **kwargs):
        """
        Wrap sandbox.setup_context to patch easy_install in that context to
        appear as user-installed.
        """
        with self.orig_context(*args, **kwargs):
            import setuptools.command.easy_install as ei
            ei.__file__ = site.USER_SITE
            yield 
开发者ID:pypa,项目名称:setuptools,代码行数:11,代码来源:test_easy_install.py

示例13: test_setup_requires_honors_fetch_params

# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_setup_requires_honors_fetch_params(self, mock_index, monkeypatch):
        """
        When easy_install installs a source distribution which specifies
        setup_requires, it should honor the fetch parameters (such as
        index-url, and find-links).
        """
        monkeypatch.setenv(str('PIP_RETRIES'), str('0'))
        monkeypatch.setenv(str('PIP_TIMEOUT'), str('0'))
        with contexts.quiet():
            # create an sdist that has a build-time dependency.
            with TestSetupRequires.create_sdist() as dist_file:
                with contexts.tempdir() as temp_install_dir:
                    with contexts.environment(PYTHONPATH=temp_install_dir):
                        ei_params = [
                            '--index-url', mock_index.url,
                            '--exclude-scripts',
                            '--install-dir', temp_install_dir,
                            dist_file,
                        ]
                        with sandbox.save_argv(['easy_install']):
                            # attempt to install the dist. It should
                            # fail because it doesn't exist.
                            with pytest.raises(SystemExit):
                                easy_install_pkg.main(ei_params)
        # there should have been one requests to the server
        assert [r.path for r in mock_index.requests] == ['/does-not-exist/'] 
开发者ID:pypa,项目名称:setuptools,代码行数:28,代码来源:test_easy_install.py


注:本文中的setuptools.sandbox方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。