1
+ """BuildURL's core."""
2
+
1
3
from copy import deepcopy
2
4
from typing import Any , Dict , List , Optional , Tuple , Union
3
5
from urllib .parse import parse_qs , urlencode , urlsplit , urlunsplit
@@ -31,6 +33,7 @@ class BuildURL:
31
33
"""
32
34
33
35
def __init__ (self , base : str = "" , force_trailing_slash : bool = False ):
36
+ """Initialize a new instance of BuildURL."""
34
37
purl = urlsplit (base )
35
38
36
39
# scheme://netloc/path;params?query#fragment
@@ -68,7 +71,7 @@ def copy(self) -> "BuildURL":
68
71
return deepcopy (self )
69
72
70
73
def set_force_trailing_slash (self , enabled : bool = True ) -> "BuildURL" :
71
- """Sets the `force_trailing_slash` attribute
74
+ """Set the `force_trailing_slash` attribute.
72
75
73
76
Args:
74
77
enabled:
@@ -115,7 +118,6 @@ def add_path(self, *args: Path) -> "BuildURL":
115
118
>>> print(url.get)
116
119
https://example.com/never/stopping/to/play/with/paths
117
120
"""
118
-
119
121
path_list = list ()
120
122
for path in args :
121
123
if isinstance (path , str ):
@@ -166,7 +168,6 @@ def add_query(self, *args: Query, **kwargs) -> "BuildURL":
166
168
>>> print(url.get)
167
169
https://example.com?key=value&another=query&more=stuff&a=b&c=d&e=f
168
170
"""
169
-
170
171
query_dict = dict ()
171
172
for query in args :
172
173
if isinstance (query , str ):
@@ -250,7 +251,6 @@ def __itruediv__(self, path: Path) -> "BuildURL":
250
251
>>> print(url.get)
251
252
https://example.com/test/more/paths/again/and/again/
252
253
"""
253
-
254
254
self .add_path (path )
255
255
return self
256
256
@@ -274,7 +274,6 @@ def __truediv__(self, path: Path) -> "BuildURL":
274
274
>>> print(new_url.get)
275
275
https://example.com/testing
276
276
"""
277
-
278
277
out = self .copy ()
279
278
out /= path
280
279
return out
@@ -300,7 +299,6 @@ def __iadd__(self, query: Query) -> "BuildURL":
300
299
>>> print(url.get)
301
300
https://example.com?key=value&another=query&more=stuff
302
301
"""
303
-
304
302
self .add_query (query )
305
303
return self
306
304
@@ -324,7 +322,6 @@ def __add__(self, query: Query) -> "BuildURL":
324
322
>>> print(new_url.get)
325
323
https://example.com?test=it
326
324
"""
327
-
328
325
out = self .copy ()
329
326
out += query
330
327
return out
@@ -340,7 +337,6 @@ def __repr__(self) -> str:
340
337
>>> print(repr(url))
341
338
BuildURL(base='https://example.com/test?now=true', force_trailing_slash=False)
342
339
"""
343
-
344
340
return f"{ self .__class__ .__name__ } (base='{ self .get } ', force_trailing_slash={ self .force_trailing_slash } )"
345
341
346
342
def __str__ (self ) -> str :
@@ -359,7 +355,6 @@ def __str__(self) -> str:
359
355
>>> print(url)
360
356
https://example.com/test
361
357
"""
362
-
363
358
return self .get
364
359
365
360
def __len__ (self ) -> int :
0 commit comments