Skip to content

Commit 159541c

Browse files
committed
Paths and URIs conversions are more generalized
made the compatible with win32 now
1 parent 9a9d639 commit 159541c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

schema_salad/ref_resolver.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import hashlib
55
import logging
66
import collections
7+
import urllib
78
import urlparse
89
import re
910
import copy
1011
import pprint
1112
from StringIO import StringIO
13+
import pathlib2 as pathlib
1214

1315
from . import validate
1416
from .aslist import aslist
@@ -108,7 +110,7 @@ def fetch_text(self, url):
108110
return resp.text
109111
elif scheme == 'file':
110112
try:
111-
with open(path) as fp:
113+
with open(urllib.url2pathname(urlparse.urlparse(url).path)) as fp:
112114
read = fp.read()
113115
if hasattr(read, "decode"):
114116
return read.decode("utf-8")
@@ -137,7 +139,7 @@ def check_exists(self, url): # type: (unicode) -> bool
137139
return False
138140
return True
139141
elif scheme == 'file':
140-
return os.path.exists(path)
142+
return os.path.exists(urllib.url2pathname(urlparse.urlparse(url).path))
141143
else:
142144
raise ValueError('Unsupported scheme in url: %s' % url)
143145

@@ -247,6 +249,8 @@ def expand_url(self,
247249
(splitbase.scheme, splitbase.netloc, pt, splitbase.query, frg))
248250
elif scoped_ref is not None and not split.fragment:
249251
pass
252+
elif base_url is None:
253+
url = pathlib.Path(os.path.join(os.getcwd(), url)).as_uri()
250254
else:
251255
url = self.fetcher.urljoin(base_url, url)
252256

@@ -371,7 +375,6 @@ def resolve_ref(self,
371375
checklinks=True # type: bool
372376
):
373377
# type: (...) -> Tuple[Union[CommentedMap, CommentedSeq, unicode], Dict[unicode, Any]]
374-
base_url = base_url or u'file://%s/' % os.path.abspath('.')
375378

376379
obj = None # type: CommentedMap
377380
resolved_obj = None # type: Union[CommentedMap, CommentedSeq, unicode]
@@ -418,7 +421,7 @@ def resolve_ref(self,
418421
raise ValueError(u"Expected CommentedMap or string, got %s: `%s`" % (type(ref), unicode(ref)))
419422

420423
url = self.expand_url(ref, base_url, scoped_id=(obj is not None))
421-
424+
base_url = base_url or pathlib.Path(os.getcwd()).as_uri() + '/'
422425
# Has this reference been loaded already?
423426
if url in self.idx and (not mixin):
424427
return self.idx[url], {}

0 commit comments

Comments
 (0)