本文整理汇总了Python中tempfile.TMP_MAX属性的典型用法代码示例。如果您正苦于以下问题:Python tempfile.TMP_MAX属性的具体用法?Python tempfile.TMP_MAX怎么用?Python tempfile.TMP_MAX使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类tempfile
的用法示例。
在下文中一共展示了tempfile.TMP_MAX属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mkstemp
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import TMP_MAX [as 别名]
def mkstemp(self, suffix='', prefix='', dir=None, mode='wb'):
"""A wrap around tempfile.mkstemp creating a file with a unique
name. Unlike mkstemp it returns an object with a file-like
interface.
"""
class FileWrapper:
def __init__(self, fd, name):
self.file = fd
self.name = name
def __getattr__(self, attr):
return getattr(self.file, attr)
text = 'b' not in mode
# max number of tries to find out a unique file name
tempfile.TMP_MAX = 50
fd, name = tempfile.mkstemp(suffix, prefix, dir, text=text)
file = os.fdopen(fd, mode)
return FileWrapper(file, name)
# --- Wrapper methods around os.* calls
示例2: mkstemp
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import TMP_MAX [as 别名]
def mkstemp(self, suffix='', prefix='', dir=None, mode='wb'):
"""A wrap around tempfile.mkstemp creating a file with a unique
name. Unlike mkstemp it returns an object with a file-like
interface.
"""
class FileWrapper:
def __init__(self, fd, name):
self.file = fd
self.name = name
def __getattr__(self, attr):
return getattr(self.file, attr)
text = 'b' not in mode
# max number of tries to find out a unique file name
tempfile.TMP_MAX = 50
fd, name = tempfile.mkstemp(suffix, prefix, dir, text=text)
file = os.fdopen(fd, mode)
return FileWrapper(file, name)
# --- Wrapper methods around os.* calls
示例3: mkstemp
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import TMP_MAX [as 别名]
def mkstemp(self, suffix='', prefix='', dir=None, mode='wb'):
"""A wrap around tempfile.mkstemp creating a file with a unique
name. Unlike mkstemp it returns an object with a file-like
interface.
"""
class FileWrapper:
def __init__(self, fd, name):
self.file = fd
self.name = name
def __getattr__(self, attr):
return getattr(self.file, attr)
text = not 'b' in mode
# max number of tries to find out a unique file name
tempfile.TMP_MAX = 50
fd, name = tempfile.mkstemp(suffix, prefix, dir, text=text)
file = os.fdopen(fd, mode)
return FileWrapper(file, name)
# --- Wrapper methods around os.* calls
示例4: mkdtemp
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import TMP_MAX [as 别名]
def mkdtemp(dirpath, prefix='', suffix='', mode=0700):
"""Creates a directory in directory *dir* using *prefix* and *suffix* to
name it:
(dir)/<prefix><random_string><postfix>
Returns absolute path of directory.
"""
dirpath = os.path.abspath(dirpath)
names = _get_candidate_names()
mode = int(mode)
if not fcheck.mode_check(mode):
raise ValueError("wrong mode: %r" % oct(mode))
for _ in xrange(TMP_MAX):
name = names.next()
fpath = os.path.abspath(os.path.join(dirpath, '%s%s%s'
% (prefix, name, suffix)))
try:
os.mkdir(fpath, mode)
return fpath
except OSError, ex:
if ex.errno == errno.EEXIST:
# try again
continue
raise
示例5: _make_inc_temp
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import TMP_MAX [as 别名]
def _make_inc_temp(self, suffix="", prefix="", directory_name=None):
"""Return a incremental temporary file name. The file is not created.
Args:
suffix (str): The suffix of the temp file.
prefix (str): The prefix of the temp file.
directory_name (str) : The base directory of the temp file.
Returns:
A string of file name. If there existing a file having
the same name, the returned name will look like
"{directory_name}/{prefix}.{unique_index}{suffix}"
"""
if directory_name is None:
directory_name = ray.utils.get_ray_temp_dir()
directory_name = os.path.expanduser(directory_name)
index = self._incremental_dict[suffix, prefix, directory_name]
# `tempfile.TMP_MAX` could be extremely large,
# so using `range` in Python2.x should be avoided.
while index < tempfile.TMP_MAX:
if index == 0:
filename = os.path.join(directory_name, prefix + suffix)
else:
filename = os.path.join(directory_name,
prefix + "." + str(index) + suffix)
index += 1
if not os.path.exists(filename):
# Save the index.
self._incremental_dict[suffix, prefix, directory_name] = index
return filename
raise FileExistsError(errno.EEXIST,
"No usable temporary filename found")
示例6: mkstemp
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import TMP_MAX [as 别名]
def mkstemp(dirpath, prefix='', suffix='', unlink=1, mode=0600):
"""Creates a file in directory *dir* using *prefix* and *suffix* to
name it:
(dir)/<prefix><random_string><postfix>
Returns a couple of files (pysec.io.fd.File):
(Read_File, Write_File)
If *unlink* is true registers a unlink function at exit.
"""
dirpath = os.path.abspath(dirpath)
mode = int(mode)
if not fcheck.mode_check(mode):
raise ValueError("wrong mode: %r" % oct(mode))
names = _get_candidate_names()
for _ in xrange(TMP_MAX):
name = names.next()
fpath = os.path.join(dirpath, '%s%s%s' % (prefix, name, suffix))
if unlink:
atexit.register(os.unlink, fpath)
fdr = fdw = -1
try:
fdr = os.open(fpath, os.O_RDONLY | os.O_CREAT | os.O_EXCL, mode)
fdw = os.open(fpath, os.O_WRONLY, mode)
_set_cloexec(fdr)
_set_cloexec(fdw)
return fd.File(fdr), fd.File(fdw)
except OSError, ex:
if fdr != -1:
os.close(fdr)
if fdw != -1:
os.close(fdw)
if ex.errno == errno.EEXIST:
continue
else:
try:
os.unlink(fpath)
except IOError:
pass
raise
except: