當前位置: 首頁>>代碼示例>>Python>>正文


Python tempfile.TMP_MAX屬性代碼示例

本文整理匯總了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 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:23,代碼來源:filesystems.py

示例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 
開發者ID:exasol,項目名稱:script-languages,代碼行數:24,代碼來源:filesystems.py

示例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 
開發者ID:exasol,項目名稱:script-languages,代碼行數:22,代碼來源:ftpserver.py

示例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 
開發者ID:ebranca,項目名稱:owasp-pysec,代碼行數:25,代碼來源:temp.py

示例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") 
開發者ID:ray-project,項目名稱:ray,代碼行數:35,代碼來源:node.py

示例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: 
開發者ID:ebranca,項目名稱:owasp-pysec,代碼行數:41,代碼來源:temp.py


注:本文中的tempfile.TMP_MAX屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。