12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
"""Module containing the logic for the URIBuilder object."""
15
+ import typing as t
15
16
from urllib .parse import parse_qsl
16
17
from urllib .parse import urlencode
17
18
@@ -33,13 +34,13 @@ class URIBuilder:
33
34
34
35
def __init__ (
35
36
self ,
36
- scheme = None ,
37
- userinfo = None ,
38
- host = None ,
39
- port = None ,
40
- path = None ,
41
- query = None ,
42
- fragment = None ,
37
+ scheme : t . Optional [ str ] = None ,
38
+ userinfo : t . Optional [ str ] = None ,
39
+ host : t . Optional [ str ] = None ,
40
+ port : t . Optional [ str ] = None ,
41
+ path : t . Optional [ str ] = None ,
42
+ query : t . Optional [ str ] = None ,
43
+ fragment : t . Optional [ str ] = None ,
43
44
):
44
45
"""Initialize our URI builder.
45
46
@@ -76,7 +77,7 @@ def __repr__(self):
76
77
return formatstr .format (b = self )
77
78
78
79
@classmethod
79
- def from_uri (cls , reference ):
80
+ def from_uri (cls , reference : t . Union [ "uri.URIReference" , str ] ):
80
81
"""Initialize the URI builder from another URI.
81
82
82
83
Takes the given URI reference and creates a new URI builder instance
@@ -95,7 +96,7 @@ def from_uri(cls, reference):
95
96
fragment = reference .fragment ,
96
97
)
97
98
98
- def add_scheme (self , scheme ):
99
+ def add_scheme (self , scheme : str ):
99
100
"""Add a scheme to our builder object.
100
101
101
102
After normalizing, this will generate a new URIBuilder instance with
@@ -119,7 +120,7 @@ def add_scheme(self, scheme):
119
120
fragment = self .fragment ,
120
121
)
121
122
122
- def add_credentials (self , username , password ):
123
+ def add_credentials (self , username : str , password : t . Optional [ str ] ):
123
124
"""Add credentials as the userinfo portion of the URI.
124
125
125
126
.. code-block:: python
@@ -152,7 +153,7 @@ def add_credentials(self, username, password):
152
153
fragment = self .fragment ,
153
154
)
154
155
155
- def add_host (self , host ):
156
+ def add_host (self , host : str ):
156
157
"""Add hostname to the URI.
157
158
158
159
.. code-block:: python
@@ -172,7 +173,7 @@ def add_host(self, host):
172
173
fragment = self .fragment ,
173
174
)
174
175
175
- def add_port (self , port ):
176
+ def add_port (self , port : t . Union [ str , int ] ):
176
177
"""Add port to the URI.
177
178
178
179
.. code-block:: python
@@ -211,7 +212,7 @@ def add_port(self, port):
211
212
fragment = self .fragment ,
212
213
)
213
214
214
- def add_path (self , path ):
215
+ def add_path (self , path : str ):
215
216
"""Add a path to the URI.
216
217
217
218
.. code-block:: python
@@ -238,7 +239,7 @@ def add_path(self, path):
238
239
fragment = self .fragment ,
239
240
)
240
241
241
- def extend_path (self , path ):
242
+ def extend_path (self , path : str ):
242
243
"""Extend the existing path value with the provided value.
243
244
244
245
.. versionadded:: 1.5.0
@@ -314,7 +315,7 @@ def extend_query_with(self, query_items):
314
315
315
316
return self .add_query_from (original_query_items + query_items )
316
317
317
- def add_query (self , query ):
318
+ def add_query (self , query : str ):
318
319
"""Add a pre-formated query string to the URI.
319
320
320
321
.. code-block:: python
@@ -334,7 +335,7 @@ def add_query(self, query):
334
335
fragment = self .fragment ,
335
336
)
336
337
337
- def add_fragment (self , fragment ):
338
+ def add_fragment (self , fragment : str ):
338
339
"""Add a fragment to the URI.
339
340
340
341
.. code-block:: python
@@ -354,7 +355,7 @@ def add_fragment(self, fragment):
354
355
fragment = normalizers .normalize_fragment (fragment ),
355
356
)
356
357
357
- def finalize (self ):
358
+ def finalize (self ) -> "uri.URIReference" :
358
359
"""Create a URIReference from our builder.
359
360
360
361
.. code-block:: python
0 commit comments