|
4 | 4 | import hashlib
|
5 | 5 | import logging
|
6 | 6 | import collections
|
| 7 | +import urllib |
7 | 8 | import urlparse
|
8 | 9 | import re
|
9 | 10 | import copy
|
10 | 11 | import pprint
|
11 | 12 | from StringIO import StringIO
|
| 13 | +import pathlib2 as pathlib |
12 | 14 |
|
13 | 15 | from . import validate
|
14 | 16 | from .aslist import aslist
|
@@ -108,7 +110,7 @@ def fetch_text(self, url):
|
108 | 110 | return resp.text
|
109 | 111 | elif scheme == 'file':
|
110 | 112 | try:
|
111 |
| - with open(path) as fp: |
| 113 | + with open(urllib.url2pathname(urlparse.urlparse(url).path)) as fp: |
112 | 114 | read = fp.read()
|
113 | 115 | if hasattr(read, "decode"):
|
114 | 116 | return read.decode("utf-8")
|
@@ -137,7 +139,7 @@ def check_exists(self, url): # type: (unicode) -> bool
|
137 | 139 | return False
|
138 | 140 | return True
|
139 | 141 | elif scheme == 'file':
|
140 |
| - return os.path.exists(path) |
| 142 | + return os.path.exists(urllib.url2pathname(urlparse.urlparse(url).path)) |
141 | 143 | else:
|
142 | 144 | raise ValueError('Unsupported scheme in url: %s' % url)
|
143 | 145 |
|
@@ -247,6 +249,8 @@ def expand_url(self,
|
247 | 249 | (splitbase.scheme, splitbase.netloc, pt, splitbase.query, frg))
|
248 | 250 | elif scoped_ref is not None and not split.fragment:
|
249 | 251 | pass
|
| 252 | + elif base_url is None: |
| 253 | + url = pathlib.Path(os.path.join(os.getcwd(), url)).as_uri() |
250 | 254 | else:
|
251 | 255 | url = self.fetcher.urljoin(base_url, url)
|
252 | 256 |
|
@@ -371,7 +375,6 @@ def resolve_ref(self,
|
371 | 375 | checklinks=True # type: bool
|
372 | 376 | ):
|
373 | 377 | # type: (...) -> Tuple[Union[CommentedMap, CommentedSeq, unicode], Dict[unicode, Any]]
|
374 |
| - base_url = base_url or u'file://%s/' % os.path.abspath('.') |
375 | 378 |
|
376 | 379 | obj = None # type: CommentedMap
|
377 | 380 | resolved_obj = None # type: Union[CommentedMap, CommentedSeq, unicode]
|
@@ -418,7 +421,7 @@ def resolve_ref(self,
|
418 | 421 | raise ValueError(u"Expected CommentedMap or string, got %s: `%s`" % (type(ref), unicode(ref)))
|
419 | 422 |
|
420 | 423 | 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() + '/' |
422 | 425 | # Has this reference been loaded already?
|
423 | 426 | if url in self.idx and (not mixin):
|
424 | 427 | return self.idx[url], {}
|
|
0 commit comments