pythontemplist_Python tempfile._candidate_tempdir_list方法代码示例

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

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

示例1: find_good_temp_dir

​点赞 6

# 需要导入模块: import tempfile [as 别名]

# 或者: from tempfile import _candidate_tempdir_list [as 别名]

def find_good_temp_dir(candidate_temp_dirs):

"""

Given a list of candidate temp directories extracted from ``ansible.cfg``,

combine it with the Python-builtin list of candidate directories used by

:mod:`tempfile`, then iteratively try each until one is found that is both

writeable and executable.

:param list candidate_temp_dirs:

List of candidate $variable-expanded and tilde-expanded directory paths

that may be usable as a temporary directory.

"""

paths = [os.path.expandvars(os.path.expanduser(p))

for p in candidate_temp_dirs]

paths.extend(tempfile._candidate_tempdir_list())

for path in paths:

if is_good_temp_dir(path):

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

return path

raise IOError(MAKE_TEMP_FAILED_MSG % {

'paths': '\n '.join(paths),

})

开发者ID:dw,项目名称:mitogen,代码行数:25,

示例2: test_nonempty_list

​点赞 5

# 需要导入模块: import tempfile [as 别名]

# 或者: from tempfile import _candidate_tempdir_list [as 别名]

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.assertIsInstance(c, basestring)

开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,

示例3: test_wanted_dirs

​点赞 5

# 需要导入模块: import tempfile [as 别名]

# 或者: from tempfile import _candidate_tempdir_list [as 别名]

def test_wanted_dirs(self):

# _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)

# Not practical to try to verify the presence of OS-specific

# paths in this list.

开发者ID:IronLanguages,项目名称:ironpython2,代码行数:28,

示例4: test_no_files_left_behind

​点赞 5

# 需要导入模块: import tempfile [as 别名]

# 或者: from tempfile import _candidate_tempdir_list [as 别名]

def test_no_files_left_behind(self):

# use a private empty directory

our_temp_directory = tempfile.mkdtemp()

try:

# force _get_default_tempdir() to consider our empty directory

def our_candidate_list():

return [our_temp_directory]

with support.swap_attr(tempfile, "_candidate_tempdir_list",

our_candidate_list):

# verify our directory is empty after _get_default_tempdir()

tempfile._get_default_tempdir()

self.assertEqual(os.listdir(our_temp_directory), [])

def raise_OSError(*args, **kwargs):

raise OSError(-1)

with support.swap_attr(io, "open", raise_OSError):

# test again with failing io.open()

with self.assertRaises(IOError) as cm:

tempfile._get_default_tempdir()

self.assertEqual(cm.exception.errno, errno.ENOENT)

self.assertEqual(os.listdir(our_temp_directory), [])

def bad_writer(*args, **kwargs):

fp = orig_open(*args, **kwargs)

fp.write = raise_OSError

return fp

with support.swap_attr(io, "open", bad_writer) as orig_open:

# test again with failing write()

with self.assertRaises(IOError) as cm:

tempfile._get_default_tempdir()

self.assertEqual(cm.exception.errno, errno.ENOENT)

self.assertEqual(os.listdir(our_temp_directory), [])

finally:

shutil.rmtree(our_temp_directory)

开发者ID:IronLanguages,项目名称:ironpython2,代码行数:39,

示例5: test_no_files_left_behind

​点赞 5

# 需要导入模块: import tempfile [as 别名]

# 或者: from tempfile import _candidate_tempdir_list [as 别名]

def test_no_files_left_behind(self):

# use a private empty directory

our_temp_directory = tempfile.mkdtemp()

try:

# force _get_default_tempdir() to consider our empty directory

def our_candidate_list():

return [our_temp_directory]

with support.swap_attr(tempfile, "_candidate_tempdir_list",

our_candidate_list):

# verify our directory is empty after _get_default_tempdir()

tempfile._get_default_tempdir()

self.assertEqual(os.listdir(our_temp_directory), [])

def raise_OSError(*args, **kwargs):

raise OSError(-1)

with support.swap_attr(io, "open", raise_OSError):

# test again with failing io.open()

with self.assertRaises(IOError) as cm:

tempfile._get_default_tempdir()

self.assertEqual(cm.exception.errno, errno.ENOENT)

self.assertEqual(os.listdir(our_temp_directory), [])

open = io.open

def bad_writer(*args, **kwargs):

fp = open(*args, **kwargs)

fp.write = raise_OSError

return fp

with support.swap_attr(io, "open", bad_writer):

# test again with failing write()

with self.assertRaises(IOError) as cm:

tempfile._get_default_tempdir()

self.assertEqual(cm.exception.errno, errno.ENOENT)

self.assertEqual(os.listdir(our_temp_directory), [])

finally:

shutil.rmtree(our_temp_directory)

开发者ID:dxwu,项目名称:BinderFilter,代码行数:40,

示例6: test_nonempty_list

​点赞 5

# 需要导入模块: import tempfile [as 别名]

# 或者: from tempfile import _candidate_tempdir_list [as 别名]

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.assertIsInstance(c, str)

开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,

示例7: test_wanted_dirs

​点赞 5

# 需要导入模块: import tempfile [as 别名]

# 或者: from tempfile import _candidate_tempdir_list [as 别名]

def test_wanted_dirs(self):

# _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, OSError):

dirname = os.curdir

self.assertIn(dirname, cand)

# Not practical to try to verify the presence of OS-specific

# paths in this list.

# We test _get_default_tempdir some more by testing gettempdir.

开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:31,

示例8: test_no_files_left_behind

​点赞 5

# 需要导入模块: import tempfile [as 别名]

# 或者: from tempfile import _candidate_tempdir_list [as 别名]

def test_no_files_left_behind(self):

# use a private empty directory

with tempfile.TemporaryDirectory() as our_temp_directory:

# force _get_default_tempdir() to consider our empty directory

def our_candidate_list():

return [our_temp_directory]

with support.swap_attr(tempfile, "_candidate_tempdir_list",

our_candidate_list):

# verify our directory is empty after _get_default_tempdir()

tempfile._get_default_tempdir()

self.assertEqual(os.listdir(our_temp_directory), [])

def raise_OSError(*args, **kwargs):

raise OSError()

with support.swap_attr(io, "open", raise_OSError):

# test again with failing io.open()

with self.assertRaises(FileNotFoundError):

tempfile._get_default_tempdir()

self.assertEqual(os.listdir(our_temp_directory), [])

open = io.open

def bad_writer(*args, **kwargs):

fp = open(*args, **kwargs)

fp.write = raise_OSError

return fp

with support.swap_attr(io, "open", bad_writer):

# test again with failing write()

with self.assertRaises(FileNotFoundError):

tempfile._get_default_tempdir()

self.assertEqual(os.listdir(our_temp_directory), [])

开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:35,

示例9: test_no_files_left_behind

​点赞 5

# 需要导入模块: import tempfile [as 别名]

# 或者: from tempfile import _candidate_tempdir_list [as 别名]

def test_no_files_left_behind(self):

# use a private empty directory

with tempfile.TemporaryDirectory() as our_temp_directory:

# force _get_default_tempdir() to consider our empty directory

def our_candidate_list():

return [our_temp_directory]

with support.swap_attr(tempfile, "_candidate_tempdir_list",

our_candidate_list):

# verify our directory is empty after _get_default_tempdir()

tempfile._get_default_tempdir()

self.assertEqual(os.listdir(our_temp_directory), [])

def raise_OSError(*args, **kwargs):

raise OSError()

with support.swap_attr(io, "open", raise_OSError):

# test again with failing io.open()

with self.assertRaises(FileNotFoundError):

tempfile._get_default_tempdir()

self.assertEqual(os.listdir(our_temp_directory), [])

def bad_writer(*args, **kwargs):

fp = orig_open(*args, **kwargs)

fp.write = raise_OSError

return fp

with support.swap_attr(io, "open", bad_writer) as orig_open:

# test again with failing write()

with self.assertRaises(FileNotFoundError):

tempfile._get_default_tempdir()

self.assertEqual(os.listdir(our_temp_directory), [])

开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:34,

示例10: test_nonempty_list

​点赞 5

# 需要导入模块: import tempfile [as 别名]

# 或者: from tempfile import _candidate_tempdir_list [as 别名]

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:ofermend,项目名称:medicare-demo,代码行数:11,

示例11: test_wanted_dirs

​点赞 5

# 需要导入模块: import tempfile [as 别名]

# 或者: from tempfile import _candidate_tempdir_list [as 别名]

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:ofermend,项目名称:medicare-demo,代码行数:33,

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值