IRI Submodule¶
-
class
rfc3986.iri.IRIReference(scheme, authority, path, query, fragment, encoding='utf-8')¶ 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
idnamodule is installed or therfc3986[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
- 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
IRIReferenceor 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_uriis not an absolute URI.
-
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
-
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
Trueif it is an absolute URI,Falseotherwise.- Return type
bool
Return a dictionary with the
userinfo,host, andport.If the authority is not valid, it will raise a
InvalidAuthorityException.- Returns
{'userinfo': 'username:password', 'host': 'www.example.com', 'port': '80'}- Return type
dict
- Raises
rfc3986.exceptions.InvalidAuthority – If the authority is not
Noneand can not be parsed.