@@ -1353,8 +1353,8 @@ def from_base64(base64_string):
1353
1353
Components = namedtuple ("Components" , ["scheme" , "netloc" , "path" , "query" , "fragment" ])
1354
1354
1355
1355
1356
- def sanitize_url (url , remove_authority = True , remove_query_values = True ):
1357
- # type: (str, bool, bool) -> str
1356
+ def sanitize_url (url , remove_authority = True , remove_query_values = True , split = False ):
1357
+ # type: (str, bool, bool, bool ) -> Union[ str, Components]
1358
1358
"""
1359
1359
Removes the authority and query parameter values from a given URL.
1360
1360
"""
@@ -1383,17 +1383,18 @@ def sanitize_url(url, remove_authority=True, remove_query_values=True):
1383
1383
else :
1384
1384
query_string = parsed_url .query
1385
1385
1386
- safe_url = urlunsplit (
1387
- Components (
1388
- scheme = parsed_url .scheme ,
1389
- netloc = netloc ,
1390
- query = query_string ,
1391
- path = parsed_url .path ,
1392
- fragment = parsed_url .fragment ,
1393
- )
1386
+ components = Components (
1387
+ scheme = parsed_url .scheme ,
1388
+ netloc = netloc ,
1389
+ query = query_string ,
1390
+ path = parsed_url .path ,
1391
+ fragment = parsed_url .fragment ,
1394
1392
)
1395
1393
1396
- return safe_url
1394
+ if split :
1395
+ return components
1396
+ else :
1397
+ return urlunsplit (components )
1397
1398
1398
1399
1399
1400
ParsedUrl = namedtuple ("ParsedUrl" , ["url" , "query" , "fragment" ])
@@ -1406,20 +1407,25 @@ def parse_url(url, sanitize=True):
1406
1407
parameters will be sanitized to remove sensitive data. The autority (username and password)
1407
1408
in the URL will always be removed.
1408
1409
"""
1409
- url = sanitize_url (url , remove_authority = True , remove_query_values = sanitize )
1410
+ parsed_url = sanitize_url (
1411
+ url , remove_authority = True , remove_query_values = sanitize , split = True
1412
+ )
1410
1413
1411
- parsed_url = urlsplit (url )
1412
1414
base_url = urlunsplit (
1413
1415
Components (
1414
- scheme = parsed_url .scheme ,
1415
- netloc = parsed_url .netloc ,
1416
+ scheme = parsed_url .scheme , # type: ignore
1417
+ netloc = parsed_url .netloc , # type: ignore
1416
1418
query = "" ,
1417
- path = parsed_url .path ,
1419
+ path = parsed_url .path , # type: ignore
1418
1420
fragment = "" ,
1419
1421
)
1420
1422
)
1421
1423
1422
- return ParsedUrl (url = base_url , query = parsed_url .query , fragment = parsed_url .fragment )
1424
+ return ParsedUrl (
1425
+ url = base_url ,
1426
+ query = parsed_url .query , # type: ignore
1427
+ fragment = parsed_url .fragment , # type: ignore
1428
+ )
1423
1429
1424
1430
1425
1431
def is_valid_sample_rate (rate , source ):
0 commit comments