__init__.py 文件源码

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

项目:atropos 作者: jdidion 项目源码 文件源码
def check_path(path, ptype=None, access=None):
    """Checks that a path exists, is of the specified type, and allows the
    specified access.

    Args:
        ptype: 'f' for file or 'd' for directory.
        access (int): One of the access values from :module:`os`

    Raises:
        IOError if the path does not exist, is not of the specified type, or
        doesn't allow the specified access.
    """
    if (
            ptype == 'f' and not path.startswith("/dev/") and
            not os.path.isfile(path)):
        raise IOError(errno.EISDIR, "{} is not a file".format(path), path)
    elif ptype == 'd' and not os.path.isdir(path):
        raise IOError(errno.ENOTDIR, "{} is not a directory".format(path), path)
    elif not os.path.exists(path):
        raise IOError(errno.ENOENT, "{} does not exist".format(path), path)
    if access is not None and not os.access(path, access):
        raise IOError(errno.EACCES, "{} is not accessable".format(path), path)
    return path
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号