• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tempfile._candidate_tempdir_list函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tempfile._candidate_tempdir_list函数的典型用法代码示例。如果您正苦于以下问题:Python _candidate_tempdir_list函数的具体用法?Python _candidate_tempdir_list怎么用?Python _candidate_tempdir_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_wanted_dirs

    def test_wanted_dirs(self):
        # _candidate_tempdir_list contains the expected directories

        # Make sure the interesting environment variables are all set.
        added = []
        try:
            for envname in 'TMPDIR', 'TEMP', 'TMP':
                dirname = os.getenv(envname)
                if not dirname:
                    os.environ[envname] = os.path.abspath(envname)
                    added.append(envname)

            cand = tempfile._candidate_tempdir_list()

            for envname in 'TMPDIR', 'TEMP', 'TMP':
                dirname = os.getenv(envname)
                if not dirname: raise ValueError
                self.assert_(dirname in cand)

            try:
                dirname = os.getcwd()
            except (AttributeError, os.error):
                dirname = os.curdir

            self.assert_(dirname in cand)

            # Not practical to try to verify the presence of OS-specific
            # paths in this list.
        finally:
            for p in added:
                del os.environ[p]
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:31,代码来源:test_tempfile.py


示例2: test_nonempty_list

    def test_nonempty_list(self) -> None:
        # _candidate_tempdir_list returns a nonempty list of strings

        cand = tempfile._candidate_tempdir_list()

        self.assertFalse(len(cand) == 0)
        for c in cand:
            self.assertIsInstance(c, str)
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:8,代码来源:test_tempfile.py


示例3: test_nonempty_list

    def test_nonempty_list(self):
        # _candidate_tempdir_list returns a nonempty list of strings

        cand = tempfile._candidate_tempdir_list()

        self.failIf(len(cand) == 0)
        for c in cand:
            self.assert_(isinstance(c, basestring), "%s is not a string" % c)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_tempfile.py


示例4: test_nonempty_list

    def test_nonempty_list(self):
        # _candidate_tempdir_list returns a nonempty list of strings

        cand = tempfile._candidate_tempdir_list()

        self.assertFalse(len(cand) == 0)
        for c in cand:
            self.assertTrue(isinstance(c, str),
                         "%s is not a string" % c)
开发者ID:henrywoo,项目名称:Python3.1.3-Linux,代码行数:9,代码来源:test_tempfile.py


示例5: find_good_temp_dir

def find_good_temp_dir():
    """
    Given a list of candidate temp directories extracted from ``ansible.cfg``
    and stored in _candidate_temp_dirs, combine it with the Python-builtin list
    of candidate directories used by :mod:`tempfile`, then iteratively try each
    in turn until one is found that is both writeable and executable.
    """
    paths = [os.path.expandvars(os.path.expanduser(p))
             for p in _candidate_temp_dirs]
    paths.extend(tempfile._candidate_tempdir_list())

    for path in paths:
        try:
            tmp = tempfile.NamedTemporaryFile(
                prefix='ansible_mitogen_find_good_temp_dir',
                dir=path,
            )
        except (OSError, IOError) as e:
            LOG.debug('temp dir %r unusable: %s', path, e)
            continue

        try:
            try:
                os.chmod(tmp.name, int('0700', 8))
            except OSError as e:
                LOG.debug('temp dir %r unusable: %s: chmod failed: %s',
                          path, e)
                continue

            try:
                # access(.., X_OK) is sufficient to detect noexec.
                if not os.access(tmp.name, os.X_OK):
                    raise OSError('filesystem appears to be mounted noexec')
            except OSError as e:
                LOG.debug('temp dir %r unusable: %s: %s', path, e)
                continue

            LOG.debug('Selected temp directory: %r (from %r)', path, paths)
            return path
        finally:
            tmp.close()

    raise IOError(MAKE_TEMP_FAILED_MSG % {
        'paths': '\n    '.join(paths),
    })
开发者ID:toshywoshy,项目名称:ansible,代码行数:45,代码来源:target.py


示例6: test_wanted_dirs

    def test_wanted_dirs(self) -> None:
        # _candidate_tempdir_list contains the expected directories

        # Make sure the interesting environment variables are all set.
        with support.EnvironmentVarGuard() as env:
            for envname in 'TMPDIR', 'TEMP', 'TMP':
                dirname = os.getenv(envname)
                if not dirname:
                    env[envname] = os.path.abspath(envname)

            cand = tempfile._candidate_tempdir_list()

            for envname in 'TMPDIR', 'TEMP', 'TMP':
                dirname = os.getenv(envname)
                if not dirname: raise ValueError
                self.assertIn(dirname, cand)

            try:
                dirname = os.getcwd()
            except (AttributeError, os.error):
                dirname = os.curdir

            self.assertIn(dirname, cand)
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:23,代码来源:test_tempfile.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tempfile._get_candidate_names函数代码示例发布时间:2022-05-27
下一篇:
Python tempfile._RandomNameSequence函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap