Skip to content

Commit f2d86c1

Browse files
authored
Merge branch 'master' into quiet-external-schema
2 parents 9b6a6be + f6744ad commit f2d86c1

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

schema_salad/ref_resolver.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def add_schemas(self, ns, base_url):
189189
self.cache[fetchurl].parse(data=content, format=fmt)
190190
self.graph += self.cache[fetchurl]
191191
break
192-
except xml.sax.SAXParseException: # type: ignore
192+
except xml.sax.SAXParseException:
193193
pass
194194
except TypeError:
195195
pass
@@ -661,12 +661,21 @@ def fetch(self, url, inject_ids=True): # type: (unicode, bool) -> Any
661661
self.idx[url] = result
662662
return result
663663

664-
def check_file(self, fn): # type: (unicode) -> bool
665-
if fn.startswith("file://"):
666-
u = urlparse.urlsplit(fn)
667-
return os.path.exists(u.path)
664+
def check_file(self, url): # type: (unicode) -> bool
665+
split = urlparse.urlsplit(url)
666+
scheme, path = split.scheme, split.path
667+
668+
if scheme in [u'http', u'https'] and self.session:
669+
try:
670+
resp = self.session.head(url)
671+
resp.raise_for_status()
672+
except Exception as e:
673+
return False
674+
return True
675+
elif scheme == 'file':
676+
return os.path.exists(path)
668677
else:
669-
return False
678+
raise ValueError('Unsupported scheme in url: %s' % url)
670679

671680
FieldType = TypeVar('FieldType', unicode, List[unicode], Dict[unicode, Any])
672681

typeshed/2.7/requests/sessions.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Session(SessionRedirectMixin):
7878
json=...) -> Response: ...
7979
def get(self, url: AnyStr, **kwargs) -> Response: ...
8080
def options(self, url: str, **kwargs) -> Response: ...
81-
def head(self, url: str, **kwargs) -> Response: ...
81+
def head(self, url: AnyStr, **kwargs) -> Response: ...
8282
def post(self, url: str, data=..., json=..., **kwargs) -> Response: ...
8383
def put(self, url: str, data=..., **kwargs) -> Response: ...
8484
def patch(self, url: str, data=..., **kwargs) -> Response: ...

0 commit comments

Comments
 (0)