88
99import six
1010from six .moves import range
11- import urllib
12-
1311from six .moves .urllib import parse
12+ from six .moves import urllib
1413from six import StringIO
1514
1615import re
@@ -47,10 +46,10 @@ def file_uri(path, split_frag=False): # type: (str, bool) -> str
4746 return path
4847 if split_frag :
4948 pathsp = path .split ("#" , 2 )
50- frag = "#" + urllib .quote (str (pathsp [1 ])) if len (pathsp ) == 2 else ""
51- urlpath = urllib .pathname2url (str (pathsp [0 ]))
49+ frag = "#" + urllib .parse . quote (str (pathsp [1 ])) if len (pathsp ) == 2 else ""
50+ urlpath = urllib .request . pathname2url (str (pathsp [0 ]))
5251 else :
53- urlpath = urllib .pathname2url (path )
52+ urlpath = urllib .request . pathname2url (path )
5453 frag = ""
5554 if urlpath .startswith ("//" ):
5655 return "file:%s%s" % (urlpath , frag )
@@ -60,8 +59,8 @@ def file_uri(path, split_frag=False): # type: (str, bool) -> str
6059def uri_file_path (url ): # type: (str) -> str
6160 split = parse .urlsplit (url )
6261 if split .scheme == "file" :
63- return urllib .url2pathname (
64- str (split .path )) + ("#" + urllib .unquote (str (split .fragment ))
62+ return urllib .request . url2pathname (
63+ str (split .path )) + ("#" + urllib .parse . unquote (str (split .fragment ))
6564 if bool (split .fragment ) else "" )
6665 else :
6766 raise ValueError ("Not a file URI" )
@@ -142,7 +141,7 @@ def fetch_text(self, url):
142141 return resp .text
143142 elif scheme == 'file' :
144143 try :
145- with open (urllib .url2pathname (str (path ))) as fp :
144+ with open (urllib .request . url2pathname (str (path ))) as fp :
146145 read = fp .read ()
147146 if hasattr (read , "decode" ):
148147 return read .decode ("utf-8" )
@@ -171,7 +170,7 @@ def check_exists(self, url): # type: (Text) -> bool
171170 return False
172171 return True
173172 elif scheme == 'file' :
174- return os .path .exists (urllib .url2pathname (str (path )))
173+ return os .path .exists (urllib .request . url2pathname (str (path )))
175174 else :
176175 raise ValueError ('Unsupported scheme in url: %s' % url )
177176
0 commit comments