Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/rfc3986/api.py: 100%
15 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:04 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:04 +0000
1# Copyright (c) 2014 Rackspace
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11# implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""
15Module containing the simple and functional API for rfc3986.
17This module defines functions and provides access to the public attributes
18and classes of rfc3986.
19"""
20from .iri import IRIReference
21from .parseresult import ParseResult
22from .uri import URIReference
25def uri_reference(uri, encoding="utf-8"):
26 """Parse a URI string into a URIReference.
28 This is a convenience function. You could achieve the same end by using
29 ``URIReference.from_string(uri)``.
31 :param str uri: The URI which needs to be parsed into a reference.
32 :param str encoding: The encoding of the string provided
33 :returns: A parsed URI
34 :rtype: :class:`URIReference`
35 """
36 return URIReference.from_string(uri, encoding)
39def iri_reference(iri, encoding="utf-8"):
40 """Parse a IRI string into an IRIReference.
42 This is a convenience function. You could achieve the same end by using
43 ``IRIReference.from_string(iri)``.
45 :param str iri: The IRI which needs to be parsed into a reference.
46 :param str encoding: The encoding of the string provided
47 :returns: A parsed IRI
48 :rtype: :class:`IRIReference`
49 """
50 return IRIReference.from_string(iri, encoding)
53def is_valid_uri(uri, encoding="utf-8", **kwargs):
54 """Determine if the URI given is valid.
56 This is a convenience function. You could use either
57 ``uri_reference(uri).is_valid()`` or
58 ``URIReference.from_string(uri).is_valid()`` to achieve the same result.
60 :param str uri: The URI to be validated.
61 :param str encoding: The encoding of the string provided
62 :param bool require_scheme: Set to ``True`` if you wish to require the
63 presence of the scheme component.
64 :param bool require_authority: Set to ``True`` if you wish to require the
65 presence of the authority component.
66 :param bool require_path: Set to ``True`` if you wish to require the
67 presence of the path component.
68 :param bool require_query: Set to ``True`` if you wish to require the
69 presence of the query component.
70 :param bool require_fragment: Set to ``True`` if you wish to require the
71 presence of the fragment component.
72 :returns: ``True`` if the URI is valid, ``False`` otherwise.
73 :rtype: bool
74 """
75 return URIReference.from_string(uri, encoding).is_valid(**kwargs)
78def normalize_uri(uri, encoding="utf-8"):
79 """Normalize the given URI.
81 This is a convenience function. You could use either
82 ``uri_reference(uri).normalize().unsplit()`` or
83 ``URIReference.from_string(uri).normalize().unsplit()`` instead.
85 :param str uri: The URI to be normalized.
86 :param str encoding: The encoding of the string provided
87 :returns: The normalized URI.
88 :rtype: str
89 """
90 normalized_reference = URIReference.from_string(uri, encoding).normalize()
91 return normalized_reference.unsplit()
94def urlparse(uri, encoding="utf-8"):
95 """Parse a given URI and return a ParseResult.
97 This is a partial replacement of the standard library's urlparse function.
99 :param str uri: The URI to be parsed.
100 :param str encoding: The encoding of the string provided.
101 :returns: A parsed URI
102 :rtype: :class:`~rfc3986.parseresult.ParseResult`
103 """
104 return ParseResult.from_string(uri, encoding, strict=False)