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


Python tempfile.gettempprefix方法代碼示例

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


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

示例1: mkstemp

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [as 別名]
def mkstemp(suffix=None, prefix=None, dir=None, text=False):
    """
    Args:
        suffix (`pathlike` or `None`): suffix or `None` to use the default
        prefix (`pathlike` or `None`): prefix or `None` to use the default
        dir (`pathlike` or `None`): temp dir or `None` to use the default
        text (bool): if the file should be opened in text mode
    Returns:
        Tuple[`int`, `fsnative`]:
            A tuple containing the file descriptor and the file path
    Raises:
        EnvironmentError

    Like :func:`python3:tempfile.mkstemp` but always returns a `fsnative`
    path.
    """

    suffix = fsnative() if suffix is None else path2fsn(suffix)
    prefix = gettempprefix() if prefix is None else path2fsn(prefix)
    dir = gettempdir() if dir is None else path2fsn(dir)

    return tempfile.mkstemp(suffix, prefix, dir, text) 
開發者ID:bugatsinho,項目名稱:bugatsinho.github.io,代碼行數:24,代碼來源:_temp.py

示例2: mkdtemp

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [as 別名]
def mkdtemp(suffix=None, prefix=None, dir=None):
    """
    Args:
        suffix (`pathlike` or `None`): suffix or `None` to use the default
        prefix (`pathlike` or `None`): prefix or `None` to use the default
        dir (`pathlike` or `None`): temp dir or `None` to use the default
    Returns:
        `fsnative`: A path to a directory
    Raises:
        EnvironmentError

    Like :func:`python3:tempfile.mkstemp` but always returns a `fsnative` path.
    """

    suffix = fsnative() if suffix is None else path2fsn(suffix)
    prefix = gettempprefix() if prefix is None else path2fsn(prefix)
    dir = gettempdir() if dir is None else path2fsn(dir)

    return tempfile.mkdtemp(suffix, prefix, dir) 
開發者ID:bugatsinho,項目名稱:bugatsinho.github.io,代碼行數:21,代碼來源:_temp.py

示例3: test_exports

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [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

示例4: test_usable_template

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [as 別名]
def test_usable_template(self):
        # gettempprefix returns a usable prefix string

        # Create a temp directory, avoiding use of the prefix.
        # Then attempt to create a file whose name is
        # prefix + 'xxxxxx.xxx' in that directory.
        p = tempfile.gettempprefix() + "xxxxxx.xxx"
        d = tempfile.mkdtemp(prefix="")
        try:
            p = os.path.join(d, p)
            try:
                fd = os.open(p, os.O_RDWR | os.O_CREAT)
            except:
                self.failOnException("os.open")
            os.close(fd)
            os.unlink(p)
        finally:
            os.rmdir(d) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_tempfile.py

示例5: repo_path

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [as 別名]
def repo_path():
    '''
    Sice elasticsearch may be launched under the other user,
    tempfile.TemporaryDirectory can't be used, because python
    can't cleanup it after elasticsearch user.
    So we are just leaving it there.
    '''
    characters = "abcdefghijklmnopqrstuvwxyz0123456789_"
    temp_dir = tempfile.gettempdir()
    temp_prefix = '/' + tempfile.gettempprefix()
    temp_name = temp_prefix + ''.join(
        [random.choice(characters) for _ in range(8)]
    )

    dir_path = os.path.join(temp_dir + temp_name)
    os.makedirs(dir_path)
    yield dir_path

    try:
        shutil.rmtree(dir_path)
    except PermissionError:
        # if subdirs were created by other user
        pass 
開發者ID:aio-libs-abandoned,項目名稱:aioes,代碼行數:25,代碼來源:test_snapshot.py

示例6: test_exports

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [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

示例7: test_exports

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [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
        }

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

示例8: __init__

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [as 別名]
def __init__(self, filename=None):
        """Initializes a new DarkFrame object."""
        super(DarkFrame, self).__init__(filename=filename)
        self.options = Options({
            'auto_brightness': False,
            'brightness': 1.0,
            'auto_stretch': True,
            'bps': 16,
            'gamma': (1, 1),
            'rotation': 0,
        })
        self._tmp = os.path.join(
            tempfile.gettempdir(),
            '{prefix}{rand}'.format(
                prefix=tempfile.gettempprefix(),
                rand=''.join(random.SystemRandom().choice(
                    string.ascii_uppercase + string.digits) for _ in range(8)
                )
            )
        )
        self._filetype = None 
開發者ID:photoshell,項目名稱:rawkit,代碼行數:23,代碼來源:raw.py

示例9: serve

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [as 別名]
def serve(content):
    """Write content to a temp file and serve it in browser"""
    temp_folder = tempfile.gettempdir()
    temp_file_name = tempfile.gettempprefix() + str(uuid.uuid4()) + ".html"
    # Generate a file path with a random name in temporary dir
    temp_file_path = os.path.join(temp_folder, temp_file_name)

    # save content to temp file
    save(temp_file_path, content)

    # Open templfile in a browser
    webbrowser.open("file://{}".format(temp_file_path))

    # Block the thread while content is served
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        # cleanup the temp file
        os.remove(temp_file_path) 
開發者ID:vividvilla,項目名稱:csvtotable,代碼行數:22,代碼來源:convert.py

示例10: _check_tmp_free_space

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [as 別名]
def _check_tmp_free_space() -> CheckLevels:
    """
    Warn if there is not enough free space in the default temporary directory.
    """
    free_space = shutil.disk_usage(gettempdir()).free
    free_space_gb = free_space / 1024 / 1024 / 1024

    low_space_message = (
        'The default temporary directory ("{tmp_prefix}") has '
        '{free_space:.1f} GB of free space available. '
        'Creating a cluster typically takes approximately 2 GB of temporary '
        'storage. '
        'If you encounter problems with disk space usage, set the ``TMPDIR`` '
        'environment variable to a suitable temporary directory or use the '
        '``--workspace-dir`` option on the ``minidcos docker create`` command.'
    ).format(
        tmp_prefix=Path('/') / gettempprefix(),
        free_space=free_space_gb,
    )

    if free_space_gb < 5:
        warn(message=low_space_message)
        return CheckLevels.WARNING

    return CheckLevels.NONE 
開發者ID:dcos,項目名稱:dcos-e2e,代碼行數:27,代碼來源:doctor.py

示例11: get_fileobject

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [as 別名]
def get_fileobject(self, suffix="", prefix=tempfile.gettempprefix(),
                       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:untitaker,項目名稱:python-atomicwrites,代碼行數:16,代碼來源:__init__.py

示例12: gettempprefix

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [as 別名]
def gettempprefix():
    """
    Returns:
        `fsnative`

    Like :func:`python3:tempfile.gettempprefix`, but always returns a
    `fsnative` path
    """

    return path2fsn(tempfile.gettempprefix()) 
開發者ID:bugatsinho,項目名稱:bugatsinho.github.io,代碼行數:12,代碼來源:_temp.py

示例13: test_sane_template

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [as 別名]
def test_sane_template(self):
        # gettempprefix returns a nonempty prefix string
        p = tempfile.gettempprefix()

        self.assertIsInstance(p, basestring)
        self.assertTrue(len(p) > 0) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_tempfile.py

示例14: test_exports

# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import gettempprefix [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,
            "gettempprefixb" : 1,
            "gettempdir" : 1,
            "gettempdirb" : 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:Microvellum,項目名稱:Fluid-Designer,代碼行數:29,代碼來源:test_tempfile.py

示例15: make_temp

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


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