IRI Submodule

class rfc3986.iri.IRIReference

Immutable object representing a parsed IRI Reference.

Can be encoded into an URIReference object via the procedure specified in RFC 3987 Section 3.1

Note

The IRI submodule is a new interface and may possibly change in the future. Check for changes to the interface when upgrading.

IRIReference.encode(idna_encoder=None)

Encode an IRIReference into a URIReference instance.

If the idna module is installed or the rfc3986[idna] extra is used then unicode characters in the IRI host component will be encoded with IDNA2008.

Parameters:idna_encoder – Function that encodes each part of the host component If not given will raise an exception if the IRI contains a host component.
Return type:uri.URIReference
Returns:A URI reference
classmethod IRIReference.from_string(iri_string, encoding='utf-8')

Parse a IRI reference from the given unicode IRI string.

Parameters:
  • iri_string (str) – Unicode IRI to be parsed into a reference.
  • encoding (str) – The encoding of the string provided
Returns:

IRIReference or subclass thereof

IRIReference.unsplit()

Create a URI string from the components.

Returns:The URI Reference reconstituted as a string.
Return type:str
IRIReference.resolve_with(base_uri, strict=False)

Use an absolute URI Reference to resolve this relative reference.

Assuming this is a relative reference that you would like to resolve, use the provided base URI to resolve it.

See http://tools.ietf.org/html/rfc3986#section-5 for more information.

Parameters:base_uri – Either a string or URIReference. It must be an absolute URI or it will raise an exception.
Returns:A new URIReference which is the result of resolving this reference using base_uri.
Return type:URIReference
Raises:rfc3986.exceptions.ResolutionError – If the base_uri does not at least have a scheme.
IRIReference.copy_with(scheme=<object object>, authority=<object object>, path=<object object>, query=<object object>, fragment=<object object>)

Create a copy of this reference with the new components.

Parameters:
  • scheme (str) – (optional) The scheme to use for the new reference.
  • authority (str) – (optional) The authority to use for the new reference.
  • path (str) – (optional) The path to use for the new reference.
  • query (str) – (optional) The query to use for the new reference.
  • fragment (str) – (optional) The fragment to use for the new reference.
Returns:

New URIReference with provided components.

Return type:

URIReference

IRIReference.is_absolute()

Determine if this URI Reference is an absolute URI.

See http://tools.ietf.org/html/rfc3986#section-4.3 for explanation.

Returns:True if it is an absolute URI, False otherwise.
Return type:bool
IRIReference.authority_info()

Return a dictionary with the userinfo, host, and port.

If the authority is not valid, it will raise a InvalidAuthority Exception.

Returns:{'userinfo': 'username:password', 'host': 'www.example.com', 'port': '80'}
Return type:dict
Raises:rfc3986.exceptions.InvalidAuthority – If the authority is not None and can not be parsed.