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


Python tempfile.template方法代碼示例

本文整理匯總了Python中tempfile.template方法的典型用法代碼示例。如果您正苦於以下問題:Python tempfile.template方法的具體用法?Python tempfile.template怎麽用?Python tempfile.template使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tempfile的用法示例。


在下文中一共展示了tempfile.template方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: mkdtemp

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def mkdtemp(self, prefix=tempfile.template):
    """Makes a new temporary directory, returns Path to it.

    Args:
      * prefix (str) - a tempfile template for the directory name (defaults
        to "tmp").

    Returns a Path to the new directory.
    """
    if not self._test_data.enabled:  # pragma: no cover
      # New path as str.
      new_path = tempfile.mkdtemp(prefix=prefix, dir=str(self['cleanup']))
      # Ensure it's under self._cleanup_dir, convert to Path.
      new_path = self._split_path(new_path)
      assert new_path[:len(self._cleanup_dir)] == self._cleanup_dir, (
          'new_path: %r -- cleanup_dir: %r' % (new_path, self._cleanup_dir))
      temp_dir = self['cleanup'].join(*new_path[len(self._cleanup_dir):])
    else:
      self._test_counter += 1
      assert isinstance(prefix, basestring)
      temp_dir = self['cleanup'].join('%s_tmp_%d' %
                                      (prefix, self._test_counter))
    self.mock_add_paths(temp_dir)
    return temp_dir 
開發者ID:luci,項目名稱:recipes-py,代碼行數:26,代碼來源:api.py

示例2: test_exports

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def test_exports(self):
        # There are no surprising symbols in the tempfile module
        dict = tempfile.__dict__

        expected = {
            "NamedTemporaryFile" : 1,
            "TemporaryFile" : 1,
            "mkstemp" : 1,
            "mkdtemp" : 1,
            "mktemp" : 1,
            "TMP_MAX" : 1,
            "gettempprefix" : 1,
            "gettempdir" : 1,
            "tempdir" : 1,
            "template" : 1,
            "SpooledTemporaryFile" : 1
        }

        unexp = []
        for key in dict:
            if key[0] != '_' and key not in expected:
                unexp.append(key)
        self.assertTrue(len(unexp) == 0,
                        "unexpected keys: %s" % unexp) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_tempfile.py

示例3: retry_before_failing

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def retry_before_failing(ntimes=None):
    """Decorator which runs a test function and retries N times before
    actually failing.
    """
    def decorator(fun):
        @functools.wraps(fun)
        def wrapper(*args, **kwargs):
            for x in range(ntimes or NO_RETRIES):
                try:
                    return fun(*args, **kwargs)
                except AssertionError as _:
                    err = _
            raise err
        return wrapper
    return decorator


# commented out as per bug http://bugs.python.org/issue10354
# tempfile.template = 'tmp-pyftpdlib' 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:21,代碼來源:__init__.py

示例4: make_temp_file

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def make_temp_file(**kw):
    try:
        result = tempfile.mktemp(**kw)
        try:
            result = os.path.realpath(result)
        except AttributeError:
            # Python 2.1 has no os.path.realpath() method.
            pass
    except TypeError:
        try:
            save_template = tempfile.template
            prefix = kw['prefix']
            del kw['prefix']
            tempfile.template = prefix
            result = tempfile.mktemp(**kw)
        finally:
            tempfile.template = save_template
    return result 
開發者ID:coin3d,項目名稱:pivy,代碼行數:20,代碼來源:scons-time.py

示例5: test_exports

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def test_exports(self):
        # There are no surprising symbols in the tempfile module
        dict = tempfile.__dict__

        expected = {
            "NamedTemporaryFile" : 1,
            "TemporaryFile" : 1,
            "mkstemp" : 1,
            "mkdtemp" : 1,
            "mktemp" : 1,
            "TMP_MAX" : 1,
            "gettempprefix" : 1,
            "gettempdir" : 1,
            "tempdir" : 1,
            "template" : 1,
            "SpooledTemporaryFile" : 1,
            "TemporaryDirectory" : 1,
        }

        unexp = []
        for key in dict:
            if key[0] != '_' and key not in expected:
                unexp.append(key)
        self.assertTrue(len(unexp) == 0,
                        "unexpected keys: %s" % unexp) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:27,代碼來源:test_tempfile.py

示例6: __init__

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def __init__(self, suffix="", prefix=template, dir=None):
        self.name = mkdtemp(suffix, prefix, dir)
        self._closed = False 
開發者ID:matthew-brett,項目名稱:delocate,代碼行數:5,代碼來源:tmpdirs.py

示例7: __init__

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def __init__(self, suffix="", prefix=template, dir=None, chdir=False):
        self.name = mkdtemp(suffix, prefix, dir)
        self._closed = False 
開發者ID:ME-ICA,項目名稱:me-ica,代碼行數:5,代碼來源:tmpdirs.py

示例8: mkstemp

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def mkstemp(self, prefix=tempfile.template):
    """Makes a new temporary file, returns Path to it.

    Args:
      * prefix (str) - a tempfile template for the file name (defaults to
        "tmp").

    Returns a Path to the new file. Unlike tempfile.mkstemp, the file's file
    descriptor is closed.
    """
    if not self._test_data.enabled:  # pragma: no cover
      # New path as str.
      fd, new_path = tempfile.mkstemp(prefix=prefix, dir=str(self['cleanup']))
      # Ensure it's under self._cleanup_dir, convert to Path.
      new_path = self._split_path(new_path)
      assert new_path[:len(self._cleanup_dir)] == self._cleanup_dir, (
          'new_path: %r -- cleanup_dir: %r' % (new_path, self._cleanup_dir))
      temp_file = self['cleanup'].join(*new_path[len(self._cleanup_dir):])
      os.close(fd)
    else:
      self._test_counter += 1
      assert isinstance(prefix, basestring)
      temp_file = self['cleanup'].join('%s_tmp_%d' %
                                       (prefix, self._test_counter))
    self.mock_add_paths(temp_file)
    return temp_file 
開發者ID:luci,項目名稱:recipes-py,代碼行數:28,代碼來源:api.py

示例9: get_temp_file

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def get_temp_file(self, prefix=template, suffix=""):
        """
        On windows we cannot open temporary files after creating them unless we close them first.
        For this reason we must also create them with delete=False (or they would be deleted immediately when closed)
        and we want to make sure that the test object owns a reference to the file objects by adding them
        to self._tempfiles, so that they can be deleted when the test finishes.
        """
        ret = NamedTemporaryFile(delete=False, prefix=prefix, suffix=suffix)
        self._tempfiles.append(ret)
        if is_win():
            ret.close()
        return ret 
開發者ID:apache,項目名稱:cassandra-dtest,代碼行數:14,代碼來源:test_cqlsh_copy.py

示例10: get_fileobject

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def get_fileobject(self, suffix="", prefix=tempfile.template, dir=None,
                       **kwargs):
        '''Return the temporary file to use.'''
        if dir is None:
            dir = os.path.normpath(os.path.dirname(self._path))
        descriptor, name = tempfile.mkstemp(suffix=suffix, prefix=prefix,
                                            dir=dir)
        # io.open() will take either the descriptor or the name, but we need
        # the name later for commit()/replace_atomic() and couldn't find a way
        # to get the filename from the descriptor.
        os.close(descriptor)
        kwargs['mode'] = self._mode
        kwargs['file'] = name
        return io.open(**kwargs) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:16,代碼來源:__init__.py

示例11: make_temp_file

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def make_temp_file(**kw):
    try:
        result = tempfile.mktemp(**kw)
        result = os.path.realpath(result)
    except TypeError:
        try:
            save_template = tempfile.template
            prefix = kw['prefix']
            del kw['prefix']
            tempfile.template = prefix
            result = tempfile.mktemp(**kw)
        finally:
            tempfile.template = save_template
    return result 
開發者ID:Autodesk,項目名稱:arnold-usd,代碼行數:16,代碼來源:scons-time.py

示例12: make_temp

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def make_temp(self):
        return tempfile._mkstemp_inner(tempfile.gettempdir(),
                                       tempfile.template,
                                       '',
                                       tempfile._bin_openflags) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_tempfile.py

示例13: __init__

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def __init__(self, suffix="", prefix=template, dir=None):
            self.name = mkdtemp(suffix, prefix, dir)
            self._closed = False 
開發者ID:jupyter,項目名稱:testpath,代碼行數:5,代碼來源:tempdir.py

示例14: remove_test_files

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def remove_test_files():
    """Remove files and directores created during tests."""
    for name in os.listdir(u('.')):
        if name.startswith(tempfile.template):
            if os.path.isdir(name):
                shutil.rmtree(name)
            else:
                os.remove(name) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:10,代碼來源:__init__.py

示例15: tempdir

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import template [as 別名]
def tempdir(self, path=None):
        """Creates a temporary directory.
        A unique directory name is generated if no path name is specified.
        The directory is created, and will be removed when the TestCmd
        object is destroyed.
        """
        if path is None:
            try:
                path = tempfile.mktemp(prefix=tempfile.template)
            except TypeError:
                path = tempfile.mktemp()
        os.mkdir(path)

        # Symlinks in the path will report things
        # differently from os.getcwd(), so chdir there
        # and back to fetch the canonical path.
        cwd = os.getcwd()
        try:
            os.chdir(path)
            path = os.getcwd()
        finally:
            os.chdir(cwd)

        # Uppercase the drive letter since the case of drive
        # letters is pretty much random on win32:
        drive, rest = os.path.splitdrive(path)
        if drive:
            path = drive.upper() + rest

        #
        self._dirlist.append(path)

        global _Cleanup
        if self not in _Cleanup:
            _Cleanup.append(self)

        return path 
開發者ID:refack,項目名稱:GYP3,代碼行數:39,代碼來源:TestCmd.py


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