How to use the prance.util.url.ResolutionError function in prance

To help you get started, we’ve selected a few prance examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def test_issue_69_urlparse_error():
  # XXX depending on python version, the error may not actually come from
  #     parsing the URL, but from trying to load a local file that does
  #     not exist. See test_issue_72_* for a test case that specifically
  #     tries for a nonexistent file url.
  specs = {'$ref': "file://a\u2100b/bad/netloc"}
  res = resolver.RefResolver(specs,
      fs.abspath('tests/specs/with_externals.yaml'))

  with pytest.raises(ResolutionError) as exinfo:
    res.resolve_references()

  assert 'bad/netloc' in str(exinfo.value)
github jfinkhaeuser / prance / tests / test_util_url.py View on Github external
def test_absurl_fragment():
  base = 'file:///etc/passwd'
  test = '#frag'
  with pytest.raises(url.ResolutionError):
    url.absurl(test)

  res = url.absurl(test, base)
  assert res.geturl() == 'file:///etc/passwd#frag'
github kiwicom / the-zoo / zoo / repos / views.py View on Github external
def _parse_file(path, base=None):
    try:
        parser = ResolvingParser(str(path))
        return parser.specification
    except (
        AssertionError,
        AttributeError,
        ComposerError,
        FileNotFoundError,
        ResolutionError,
        ScannerError,
        UnicodeDecodeError,
        ValidationError,
    ) as err:
        log.info(
            "repos.views.openapi.invalid", path=str(path.relative_to(base)), error=err
        )
github jfinkhaeuser / prance / prance / util / url.py View on Github external
if not reference or not reference.path:
      raise ResolutionError('Cannot build an absolute file URL from a fragment'
          ' without a reference with path!')
    result_list = list(reference)
    result_list[5] = parsed.fragment
  elif os.path.isabs(from_posix(parsed.path)):
    # We have an absolute path, so we can ignore the reference entirely!
    result_list = list(parsed)
    result_list[0] = 'file'  # in case it was empty
  else:
    # If we have a relative path, we require a reference.
    if not reference:
      raise ResolutionError('Cannot build an absolute file URL from a relative'
          ' path without a reference!')
    if reference.scheme not in (None, '', 'file'):
      raise ResolutionError('Cannot build an absolute file URL with a non-file'
          ' reference!')

    result_list = list(parsed)
    result_list[0] = 'file'  # in case it was empty
    result_list[2] = abspath(from_posix(parsed.path),
            from_posix(reference.path))

  # Reassemble the result and return it
  result = parse.ParseResult(*result_list)
  return result
github jfinkhaeuser / prance / prance / util / resolver.py View on Github external
def default_reclimit_handler(limit, parsed_url):
  """Raise prance.util.url.ResolutionError."""
  raise _url.ResolutionError('Recursion reached limit of %d trying to '
        'resolve "%s"!' % (limit, parsed_url.geturl()))
github jfinkhaeuser / prance / prance / util / resolver.py View on Github external
:return: A copy of the dereferenced value, with all internal references
        resolved.
    """
    # In order to start dereferencing anything in the referenced URL, we have
    # to read and parse it, of course.
    contents = _url.fetch_url(ref_url, self.__reference_cache)

    # In this inner parser's specification, we can now look for the referenced
    # object.
    value = contents
    if len(obj_path) != 0:
      from prance.util.path import path_get
      try:
        value = path_get(value, obj_path)
      except KeyError:
        raise _url.ResolutionError('Cannot resolve reference "%s"!'
            % (ref_url.geturl(), ))

    # Deep copy value; we don't want to create recursive structures
    import copy
    value = copy.deepcopy(value)

    # Now resolve partial specs
    value = self._resolve_partial(ref_url, value, recursions)

    # That's it!
    return value