8
8
9
9
import six
10
10
from six .moves import range
11
- import urllib
12
-
13
11
from six .moves .urllib import parse
12
+ from six .moves import urllib
14
13
from six import StringIO
15
14
16
15
import re
@@ -47,10 +46,10 @@ def file_uri(path, split_frag=False): # type: (str, bool) -> str
47
46
return path
48
47
if split_frag :
49
48
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 ]))
52
51
else :
53
- urlpath = urllib .pathname2url (path )
52
+ urlpath = urllib .request . pathname2url (path )
54
53
frag = ""
55
54
if urlpath .startswith ("//" ):
56
55
return "file:%s%s" % (urlpath , frag )
@@ -60,8 +59,8 @@ def file_uri(path, split_frag=False): # type: (str, bool) -> str
60
59
def uri_file_path (url ): # type: (str) -> str
61
60
split = parse .urlsplit (url )
62
61
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 ))
65
64
if bool (split .fragment ) else "" )
66
65
else :
67
66
raise ValueError ("Not a file URI" )
@@ -142,7 +141,7 @@ def fetch_text(self, url):
142
141
return resp .text
143
142
elif scheme == 'file' :
144
143
try :
145
- with open (urllib .url2pathname (str (path ))) as fp :
144
+ with open (urllib .request . url2pathname (str (path ))) as fp :
146
145
read = fp .read ()
147
146
if hasattr (read , "decode" ):
148
147
return read .decode ("utf-8" )
@@ -171,7 +170,7 @@ def check_exists(self, url): # type: (Text) -> bool
171
170
return False
172
171
return True
173
172
elif scheme == 'file' :
174
- return os .path .exists (urllib .url2pathname (str (path )))
173
+ return os .path .exists (urllib .request . url2pathname (str (path )))
175
174
else :
176
175
raise ValueError ('Unsupported scheme in url: %s' % url )
177
176
0 commit comments