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
评论列表
文章目录