def local_open(url):
scheme, server, path, param, query, frag = urlparse(url)<EOL>filename = url2pathname(path)<EOL>if os.path.isfile(filename):<EOL><INDENT>return urllib2.urlopen(url)<EOL><DEDENT>elif path.endswith('<STR_LIT:/>') and os.path.isdir(filename):<EOL><INDENT>files = []<EOL>for f in os.listdir(filename):<EOL><INDENT>if f=='<STR_LIT>':<EOL><INDENT>with open(os.path.join(filename,f),'<STR_LIT:r>') as fp:<EOL><INDENT>body = fp.read()<EOL><DEDENT>break<EOL><DEDENT>elif os.path.isdir(os.path.join(filename,f)):<EOL><INDENT>f+='<STR_LIT:/>'<EOL><DEDENT>files.append("<STR_LIT>" % (f,f))<EOL><DEDENT>else:<EOL><INDENT>body = ("<STR_LIT>" % url) +"<STR_LIT>" % '<STR_LIT:\n>'.join(files)<EOL><DEDENT>status, message = <NUM_LIT:200>, "<STR_LIT:OK>"<EOL><DEDENT>else:<EOL><INDENT>status, message, body = <NUM_LIT>, "<STR_LIT>", "<STR_LIT>"<EOL><DEDENT>headers = {'<STR_LIT>': '<STR_LIT>'}<EOL>return HTTPError(url, status, message, headers, StringIO(body))<EOL>
Read a local path, with special support for directories