示例#1
0
    def resolving(self, ref):
        """
        Context manager which resolves a JSON ``ref`` and enters the
        resolution scope of this ref.

        :argument str ref: reference to resolve

        """

        full_uri = urljoin(self.resolution_scope, ref)
        uri, fragment = urldefrag(full_uri)
        if not uri:
            uri = self.base_uri

        if uri in self.store:
            document = self.store[uri]
        else:
            try:
                document = self.resolve_remote(uri)
            except Exception as exc:
                raise RefResolutionError(exc)

        old_base_uri, self.base_uri = self.base_uri, uri
        try:
            with self.in_scope(uri):
                yield self.resolve_fragment(document, fragment)
        finally:
            self.base_uri = old_base_uri
示例#2
0
    def resolving(self, ref):
        """
        Context manager which resolves a JSON ``ref`` and enters the
        resolution scope of this ref.

        :argument str ref: reference to resolve

        """

        full_uri = urljoin(self.resolution_scope, ref)
        uri, fragment = urldefrag(full_uri)
        if not uri:
            uri = self.base_uri

        if uri in self.store:
            document = self.store[uri]
        else:
            try:
                document = self.resolve_remote(uri)
            except Exception as exc:
                raise RefResolutionError(exc)

        old_base_uri, self.base_uri = self.base_uri, uri
        try:
            with self.in_scope(uri):
                yield self.resolve_fragment(document, fragment)
        finally:
            self.base_uri = old_base_uri
示例#3
0
 def in_scope(self, scope):
     old_scope = self.resolution_scope
     self.resolution_scope = urljoin(old_scope, scope)
     try:
         yield
     finally:
         self.resolution_scope = old_scope
示例#4
0
 def in_scope(self, scope):
     old_scope = self.resolution_scope
     self.resolution_scope = urljoin(old_scope, scope)
     try:
         yield
     finally:
         self.resolution_scope = old_scope
示例#5
0
def urljoin_with_custom_scheme(*args, **kwargs):
    """Patch urljoin call when using local store with custom schemes.

    Allows using custom schemes by extending urllib.parse
    configuration (work-around suggested in
    https://bugs.python.org/issue18828). This patch won't
    be needed once https://github.com/Julian/jsonschema/issues/649
    gets fixed.
    """
    for arg in args:
        if isinstance(arg, str) and "://" in arg:
            scheme = arg.split("://")[0]
            if scheme not in urllib.parse.uses_relative:
                urllib.parse.uses_relative.append(scheme)
            if scheme not in urllib.parse.uses_netloc:
                urllib.parse.uses_netloc.append(scheme)

    return urljoin(*args, **kwargs)