Skip to content

Optional skip_schemas #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions schema_salad/ref_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def merge_properties(a, b): # type: (List[Any], List[Any]) -> Dict[Any, Any]
def SubLoader(loader): # type: (Loader) -> Loader
return Loader(loader.ctx, schemagraph=loader.graph,
foreign_properties=loader.foreign_properties, idx=loader.idx,
cache=loader.cache, fetcher_constructor=loader.fetcher_constructor)
cache=loader.cache, fetcher_constructor=loader.fetcher_constructor,
skip_schemas=loader.skip_schemas)

class Fetcher(object):
def fetch_text(self, url): # type: (unicode) -> unicode
Expand Down Expand Up @@ -179,7 +180,8 @@ def __init__(self,
idx=None, # type: Dict[unicode, Union[CommentedMap, CommentedSeq, unicode, None]]
cache=None, # type: Dict[unicode, Any]
session=None, # type: requests.sessions.Session
fetcher_constructor=None # type: Callable[[Dict[unicode, unicode], requests.sessions.Session], Fetcher]
fetcher_constructor=None, # type: Callable[[Dict[unicode, unicode], requests.sessions.Session], Fetcher]
skip_schemas=None # type: bool
):
# type: (...) -> None

Expand All @@ -205,6 +207,11 @@ def __init__(self,
else:
self.cache = {}

if skip_schemas is not None:
self.skip_schemas = skip_schemas
else:
self.skip_schemas = False

if session is None:
if "HOME" in os.environ:
self.session = CacheControl(
Expand Down Expand Up @@ -305,6 +312,8 @@ def add_namespaces(self, ns): # type: (Dict[unicode, unicode]) -> None

def add_schemas(self, ns, base_url):
# type: (Union[List[unicode], unicode], unicode) -> None
if self.skip_schemas:
return
for sch in aslist(ns):
fetchurl = self.fetcher.urljoin(base_url, sch)
if fetchurl not in self.cache:
Expand Down