filesystem.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:halogen 作者: fish2000 项目源码 文件源码
def NamedTemporaryFile(mode='w+b', bufsize=-1,
                       suffix="tmp", prefix=gettempprefix(), dir=None, delete=True):

    """ Variation on tempfile.NamedTemporaryFile(…), such that suffixes are passed
        WITHOUT specifying the period in front (versus the standard library version
        which makes you pass suffixes WITH the fucking period, ugh).
    """

    from tempfile import _bin_openflags, _text_openflags,   \
                         _mkstemp_inner, _os,               \
                         _TemporaryFileWrapper,             \
                         gettempdir

    if dir is None:
        dir = gettempdir()

    if 'b' in mode:
        flags = _bin_openflags
    else:
        flags = _text_openflags

    if _os.name == 'nt' and delete:
        flags |= _os.O_TEMPORARY

    (fd, name) = _mkstemp_inner(dir, prefix, ".%s" % suffix, flags)
    try:
        file = _os.fdopen(fd, mode, bufsize)
        return _TemporaryFileWrapper(file, name, delete)
    except BaseException as baseexc:
        _os.unlink(name)
        _os.close(fd)
        raise FilesystemError(str(baseexc))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号