prance.util.url

This submodule contains code for fetching/parsing URLs.

Exceptions

exception prance.util.url.ResolutionError[source]

Bases: exceptions.LookupError

Functions

prance.util.url.absurl(url, relative_to=None)[source]

Turn relative file URLs into absolute file URLs.

This is necessary, because while JSON pointers do not allow relative file URLs, Swagger/OpenAPI explicitly does. We need to make relative paths absolute before passing them off to jsonschema for verification.

Non-file URLs are left untouched. URLs without scheme are assumed to be file URLs.

Parameters:
  • url (str/tuple) – The input URL.
  • relative_to (str/tuple) – [optional] The URL to which the input URL is relative.
Returns:

The output URL, parsed into components.

Return type:

tuple

prance.util.url.fetch_url(url)[source]

Fetch the URL and parse the contents.

If the URL is a file URL, the format used for parsing depends on the file extension. Otherwise, YAML is assumed.

Parameters:url (tuple) – The url, parsed as returned by absurl above.
Returns:The parsed file.
Return type:dict
prance.util.url.urlresource(url)[source]

Return the resource part of a parsed URL.

The resource part is defined as the part without query, parameters or fragment. Just the scheme, netloc and path remains.

Parameters:url (tuple) – A parsed URL
Returns:The resource part of the URL
Return type:str