URI Submodule

class rfc3986.uri.URIReference

Immutable object representing a parsed URI Reference.

Note

This class is not intended to be directly instantiated by the user.

This object exposes attributes for the following components of a URI:

  • scheme
  • authority
  • path
  • query
  • fragment
scheme

The scheme that was parsed for the URI Reference. For example, http, https, smtp, imap, etc.

authority

Component of the URI that contains the user information, host, and port sub-components. For example, google.com, 127.0.0.1:5000, username@[::1], username:password@example.com:443, etc.

path

The path that was parsed for the given URI Reference. For example, /, /index.php, etc.

query

The query component for a given URI Reference. For example, a=b, a=b%20c, a=b+c, a=b,c=d,e=%20f, etc.

fragment

The fragment component of a URI. For example, section-3.1.

This class also provides extra attributes for easier access to information like the subcomponents of the authority component.

userinfo

The user information parsed from the authority.

host

The hostname, IPv4, or IPv6 adddres parsed from the authority.

port

The port parsed from the authority.

classmethod URIReference.from_string(uri_string, encoding='utf-8')

Parse a URI reference from the given unicode URI string.

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

URIReference or subclass thereof

URIReference.unsplit()

Create a URI string from the components.

Returns:The URI Reference reconstituted as a string.
Return type:str
URIReference.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 is not an absolute URI.
URIReference.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

URIReference.normalize()

Normalize this reference as described in Section 6.2.2.

This is not an in-place normalization. Instead this creates a new URIReference.

Returns:A new reference object with normalized components.
Return type:URIReference
URIReference.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
URIReference.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.