URI Submodule¶
-
class
rfc3986.uri.
URIReference
(scheme, authority, path, query, fragment, encoding='utf-8')¶ 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.
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
- 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.
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.
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
Return a dictionary with the
userinfo
,host
, andport
.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.
Deprecated Methods¶
-
URIReference.
is_valid
(**kwargs)¶ Determine if the URI is valid.
Deprecated since version 1.1.0: Use the
Validator
object instead.- Parameters
require_scheme (bool) – Set to
True
if you wish to require the presence of the scheme component.require_authority (bool) – Set to
True
if you wish to require the presence of the authority component.require_path (bool) – Set to
True
if you wish to require the presence of the path component.require_query (bool) – Set to
True
if you wish to require the presence of the query component.require_fragment (bool) – Set to
True
if you wish to require the presence of the fragment component.
- Returns
True
if the URI is valid.False
otherwise.- Return type
bool
Determine if the authority component is valid.
Deprecated since version 1.1.0: Use the
Validator
object instead.- Parameters
require (bool) – Set to
True
to require the presence of this component.- Returns
True
if the authority is valid.False
otherwise.- Return type
bool
-
URIReference.
scheme_is_valid
(require=False)¶ Determine if the scheme component is valid.
Deprecated since version 1.1.0: Use the
Validator
object instead.- Parameters
require (str) – Set to
True
to require the presence of this component.- Returns
True
if the scheme is valid.False
otherwise.- Return type
bool
-
URIReference.
path_is_valid
(require=False)¶ Determine if the path component is valid.
Deprecated since version 1.1.0: Use the
Validator
object instead.- Parameters
require (str) – Set to
True
to require the presence of this component.- Returns
True
if the path is valid.False
otherwise.- Return type
bool
-
URIReference.
query_is_valid
(require=False)¶ Determine if the query component is valid.
Deprecated since version 1.1.0: Use the
Validator
object instead.- Parameters
require (str) – Set to
True
to require the presence of this component.- Returns
True
if the query is valid.False
otherwise.- Return type
bool
-
URIReference.
fragment_is_valid
(require=False)¶ Determine if the fragment component is valid.
Deprecated since version 1.1.0: Use the Validator object instead.
- Parameters
require (str) – Set to
True
to require the presence of this component.- Returns
True
if the fragment is valid.False
otherwise.- Return type
bool