comparison python/open.py @ 398:2025368488ee

adding python/open.py
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 30 Jul 2013 00:05:46 -0700
parents
children
comparison
equal deleted inserted replaced
397:11ac996b9c49 398:2025368488ee
1 def load(resource):
2 """
3 open a file or URL for reading. If the passed resource string is not a URL,
4 or begins with 'file://', return a ``file``. Otherwise, return the
5 result of urllib2.urlopen()
6 """
7
8 # handle file URLs separately due to python stdlib limitations
9 if resource.startswith('file://'):
10 resource = resource[len('file://'):]
11
12 if not is_url(resource):
13 # if no scheme is given, it is a file path
14 return file(resource)
15
16 return urllib2.urlopen(resource)