55import hashlib
66import logging
77import collections
8+
9+ import six
10+ from six .moves import range
811import urllib
9- import urlparse
12+ # import urlparse
13+ from six .moves .urllib import parse
14+
1015import re
1116import copy
12- import urllib
1317from StringIO import StringIO
1418
1519from . import validate
2933import xml .sax
3034from typing import (cast , Any , AnyStr , Callable , Dict , List , Iterable ,
3135 Optional , Set , Text , Tuple , TypeVar , Union )
32- import six
33- from six .moves import range
36+
3437
3538_logger = logging .getLogger ("salad" )
3639ContextType = Dict [six .text_type , Union [Dict , six .text_type , Iterable [six .text_type ]]]
@@ -54,7 +57,7 @@ def file_uri(path, split_frag=False): # type: (str, bool) -> str
5457 return "file://%s%s" % (urlpath , frag )
5558
5659def uri_file_path (url ): # type: (str) -> str
57- split = urlparse .urlsplit (url )
60+ split = parse .urlsplit (url )
5861 if split .scheme == "file" :
5962 return urllib .url2pathname (
6063 str (split .path )) + ("#" + urllib .unquote (str (split .fragment ))
@@ -126,7 +129,7 @@ def fetch_text(self, url):
126129 if url in self .cache :
127130 return self .cache [url ]
128131
129- split = urlparse .urlsplit (url )
132+ split = parse .urlsplit (url )
130133 scheme , path = split .scheme , split .path
131134
132135 if scheme in [u'http' , u'https' ] and self .session is not None :
@@ -156,7 +159,7 @@ def check_exists(self, url): # type: (Text) -> bool
156159 if url in self .cache :
157160 return True
158161
159- split = urlparse .urlsplit (url )
162+ split = parse .urlsplit (url )
160163 scheme , path = split .scheme , split .path
161164
162165 if scheme in [u'http' , u'https' ] and self .session is not None :
@@ -172,7 +175,7 @@ def check_exists(self, url): # type: (Text) -> bool
172175 raise ValueError ('Unsupported scheme in url: %s' % url )
173176
174177 def urljoin (self , base_url , url ): # type: (Text, Text) -> Text
175- return urlparse .urljoin (base_url , url )
178+ return parse .urljoin (base_url , url )
176179
177180class Loader (object ):
178181 def __init__ (self ,
@@ -187,7 +190,7 @@ def __init__(self,
187190 ):
188191 # type: (...) -> None
189192
190- normalize = lambda url : urlparse .urlsplit (url ).geturl ()
193+ normalize = lambda url : parse .urlsplit (url ).geturl ()
191194 if idx is not None :
192195 self .idx = idx
193196 else :
@@ -273,20 +276,20 @@ def expand_url(self,
273276 if prefix in self .vocab :
274277 url = self .vocab [prefix ] + url [len (prefix ) + 1 :]
275278
276- split = urlparse .urlsplit (url )
279+ split = parse .urlsplit (url )
277280
278281 if (bool (split .scheme ) or url .startswith (u"$(" )
279282 or url .startswith (u"${" )):
280283 pass
281284 elif scoped_id and not bool (split .fragment ):
282- splitbase = urlparse .urlsplit (base_url )
285+ splitbase = parse .urlsplit (base_url )
283286 frg = u""
284287 if bool (splitbase .fragment ):
285288 frg = splitbase .fragment + u"/" + split .path
286289 else :
287290 frg = split .path
288291 pt = splitbase .path if splitbase .path != '' else "/"
289- url = urlparse .urlunsplit (
292+ url = parse .urlunsplit (
290293 (splitbase .scheme , splitbase .netloc , pt , splitbase .query , frg ))
291294 elif scoped_ref is not None and not split .fragment :
292295 pass
@@ -493,7 +496,7 @@ def resolve_ref(self,
493496 doc_url = url
494497 else :
495498 # Load structured document
496- doc_url , frg = urlparse .urldefrag (url )
499+ doc_url , frg = parse .urldefrag (url )
497500 if doc_url in self .idx and (not mixin ):
498501 # If the base document is in the index, it was already loaded,
499502 # so if we didn't find the reference earlier then it must not
@@ -869,7 +872,7 @@ def fetch(self, url, inject_ids=True): # type: (Text, bool) -> Any
869872
870873 def validate_scoped (self , field , link , docid ):
871874 # type: (Text, Text, Text) -> Text
872- split = urlparse .urlsplit (docid )
875+ split = parse .urlsplit (docid )
873876 sp = split .fragment .split (u"/" )
874877 n = self .scoped_ref_fields [field ]
875878 while n > 0 and len (sp ) > 0 :
@@ -878,7 +881,7 @@ def validate_scoped(self, field, link, docid):
878881 tried = []
879882 while True :
880883 sp .append (link )
881- url = urlparse .urlunsplit ((
884+ url = parse .urlunsplit ((
882885 split .scheme , split .netloc , split .path , split .query ,
883886 u"/" .join (sp )))
884887 tried .append (url )
0 commit comments