# 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. The output URL, parsed into components. tuple
prance.util.url.fetch_url(url, cache={})[source]

Fetch the URL and parse the contents.

Same as fetch_url_text(), but also parses the content and only returns the parse results.

Parameters: url (tuple) – The url, parsed as returned by absurl above. cache (Mapping) – An optional cache. If the URL can be found in the cache, return the cache contents. The parsed file. dict
prance.util.url.split_url_reference(base_url, reference)[source]

Return a normalized, parsed URL and object path.

The reference string is a JSON reference, i.e. a URL with a fragment that contains an object path into the referenced resource.

The base URL is used as a reference point for relative references.

Parameters: base_url (mixed) – A parsed URL. reference (str) – A JSON reference string. The parsed absolute URL of the reference and the object path.
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 The resource part of the URL str