__init__.py 文件源码

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

项目:drift 作者: dgnorth 项目源码 文件源码
def fetch(path):
    """Read the contents of the file or url pointed to by 'path'."""
    try:
        with open(path) as f:
            return f.read()
    except Exception as e1:
        pass

    try:
        r = requests.get(path)
        r.raise_for_status()
        return r.text
    except Exception as e2:
        pass

    try:
        region, bucket_name, key_name = path.split("/", 2)
        conn = connect_to_region(region, calling_format=OrdinaryCallingFormat())
        bucket = conn.lookup(bucket_name)
        data = bucket.get_key(key_name).get_contents_as_string()
        return data
    except Exception as e3:
        pass

    print "Can't fetch '{}'".format(path)
    print "   Not a file:", e1
    print "   Not an URL:", e2
    print "   Not a bucket:", e3
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号