# HG changeset patch # User Jeff Hammel # Date 1375167946 25200 # Node ID 2025368488eec154877e2c4ace449614829f5ac4 # Parent 11ac996b9c499d82923bba5e6e7b077f0a7cd0d4 adding python/open.py diff -r 11ac996b9c49 -r 2025368488ee python/open.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/open.py Tue Jul 30 00:05:46 2013 -0700 @@ -0,0 +1,16 @@ +def load(resource): + """ + open a file or URL for reading. If the passed resource string is not a URL, + or begins with 'file://', return a ``file``. Otherwise, return the + result of urllib2.urlopen() + """ + + # handle file URLs separately due to python stdlib limitations + if resource.startswith('file://'): + resource = resource[len('file://'):] + + if not is_url(resource): + # if no scheme is given, it is a file path + return file(resource) + + return urllib2.urlopen(resource) \ No newline at end of file