@@ -115,7 +115,7 @@ def _get_obj(constructor, destructor, *args):
115
115
116
116
117
117
def _get_str (x ):
118
- ret = ffi .string (x .data , x .length ).decode ('utf-8' ) if x .length else ''
118
+ ret = ffi .string (x .data , x .length ).decode () if x .length else ''
119
119
return ret
120
120
121
121
@@ -185,14 +185,14 @@ class URL:
185
185
scheme_type : Final [SchemeType ]
186
186
187
187
def __init__ (self , url : str , base : Optional [str ] = None ):
188
- url_bytes = url .encode ('utf-8' )
188
+ url_bytes = url .encode ()
189
189
190
190
if base is None :
191
191
self .urlobj = _get_obj (
192
192
lib .ada_parse , lib .ada_free , url_bytes , len (url_bytes )
193
193
)
194
194
else :
195
- base_bytes = base .encode ('utf-8' )
195
+ base_bytes = base .encode ()
196
196
self .urlobj = _get_obj (
197
197
lib .ada_parse_with_base ,
198
198
lib .ada_free ,
@@ -254,7 +254,7 @@ def __getattr__(self, attr: str) -> Union[str, HostType, SchemeType]:
254
254
def __setattr__ (self , attr : str , value : str ) -> None :
255
255
if attr in SET_ATTRIBUTES :
256
256
try :
257
- value_bytes = value .encode ('utf-8' )
257
+ value_bytes = value .encode ()
258
258
except Exception :
259
259
raise ValueError (f'Invalid value for { attr } ' ) from None
260
260
@@ -276,15 +276,15 @@ def __repr__(self):
276
276
@staticmethod
277
277
def can_parse (url : str , base : Optional [str ] = None ) -> bool :
278
278
try :
279
- url_bytes = url .encode ('utf-8' )
279
+ url_bytes = url .encode ()
280
280
except Exception :
281
281
return False
282
282
283
283
if base is None :
284
284
return lib .ada_can_parse (url_bytes , len (url_bytes ))
285
285
286
286
try :
287
- base_bytes = base .encode ('utf-8' )
287
+ base_bytes = base .encode ()
288
288
except Exception :
289
289
return False
290
290
@@ -347,7 +347,7 @@ class URLSearchParams:
347
347
"""
348
348
349
349
def __init__ (self , params : str ):
350
- params_bytes = params .encode ('utf-8' )
350
+ params_bytes = params .encode ()
351
351
self .paramsobj = _get_obj (
352
352
lib .ada_parse_search_params ,
353
353
lib .ada_free_search_params ,
@@ -363,8 +363,8 @@ def __len__(self) -> int:
363
363
return self .size
364
364
365
365
def append (self , key : str , value : str ):
366
- key_bytes = key .encode ('utf-8' )
367
- value_bytes = value .encode ('utf-8' )
366
+ key_bytes = key .encode ()
367
+ value_bytes = value .encode ()
368
368
lib .ada_search_params_append (
369
369
self .paramsobj ,
370
370
key_bytes ,
@@ -374,11 +374,11 @@ def append(self, key: str, value: str):
374
374
)
375
375
376
376
def delete (self , key : str , value : Optional [str ] = None ):
377
- key_bytes = key .encode ('utf-8' )
377
+ key_bytes = key .encode ()
378
378
if value is None :
379
379
lib .ada_search_params_remove (self .paramsobj , key_bytes , len (key_bytes ))
380
380
else :
381
- value_bytes = value .encode ('utf-8' )
381
+ value_bytes = value .encode ()
382
382
lib .ada_search_params_remove_value (
383
383
self .paramsobj ,
384
384
key_bytes ,
@@ -388,12 +388,12 @@ def delete(self, key: str, value: Optional[str] = None):
388
388
)
389
389
390
390
def get (self , key : str ) -> str :
391
- key_bytes = key .encode ('utf-8' )
391
+ key_bytes = key .encode ()
392
392
item = lib .ada_search_params_get (self .paramsobj , key_bytes , len (key_bytes ))
393
393
return _get_str (item )
394
394
395
395
def get_all (self , key : str ) -> List [str ]:
396
- key_bytes = key .encode ('utf-8' )
396
+ key_bytes = key .encode ()
397
397
items = lib .ada_search_params_get_all (self .paramsobj , key_bytes , len (key_bytes ))
398
398
count = lib .ada_strings_size (items )
399
399
@@ -405,11 +405,11 @@ def get_all(self, key: str) -> List[str]:
405
405
return ret
406
406
407
407
def has (self , key : str , value : Optional [str ] = None ) -> bool :
408
- key_bytes = key .encode ('utf-8' )
408
+ key_bytes = key .encode ()
409
409
if value is None :
410
410
return lib .ada_search_params_has (self .paramsobj , key_bytes , len (key_bytes ))
411
411
else :
412
- value_bytes = value .encode ('utf-8' )
412
+ value_bytes = value .encode ()
413
413
return lib .ada_search_params_has_value (
414
414
self .paramsobj ,
415
415
key_bytes ,
@@ -419,8 +419,8 @@ def has(self, key: str, value: Optional[str] = None) -> bool:
419
419
)
420
420
421
421
def set (self , key : str , value : str ):
422
- key_bytes = key .encode ('utf-8' )
423
- value_bytes = value .encode ('utf-8' )
422
+ key_bytes = key .encode ()
423
+ value_bytes = value .encode ()
424
424
lib .ada_search_params_set (
425
425
self .paramsobj ,
426
426
key_bytes ,
@@ -486,7 +486,7 @@ def check_url(s: str) -> bool:
486
486
487
487
"""
488
488
try :
489
- s_bytes = s .encode ('utf-8' )
489
+ s_bytes = s .encode ()
490
490
except Exception :
491
491
return False
492
492
@@ -508,8 +508,8 @@ def join_url(base_url: str, s: str) -> str:
508
508
509
509
"""
510
510
try :
511
- base_bytes = base_url .encode ('utf-8' )
512
- s_bytes = s .encode ('utf-8' )
511
+ base_bytes = base_url .encode ()
512
+ s_bytes = s .encode ()
513
513
except Exception :
514
514
raise ValueError ('Invalid URL' ) from None
515
515
@@ -584,7 +584,7 @@ def parse_url(s: str, attributes: Iterable[str] = PARSE_ATTRIBUTES) -> ParseAttr
584
584
585
585
"""
586
586
try :
587
- s_bytes = s .encode ('utf-8' )
587
+ s_bytes = s .encode ()
588
588
except Exception :
589
589
raise ValueError ('Invalid URL' ) from None
590
590
@@ -629,7 +629,7 @@ def replace_url(s: str, **kwargs: str) -> str:
629
629
``ValueError`` is raised if the input URL or one of the components is not valid.
630
630
"""
631
631
try :
632
- s_bytes = s .encode ('utf-8' )
632
+ s_bytes = s .encode ()
633
633
except Exception :
634
634
raise ValueError ('Invalid URL' ) from None
635
635
@@ -645,7 +645,7 @@ def replace_url(s: str, **kwargs: str) -> str:
645
645
continue
646
646
647
647
try :
648
- value_bytes = value .encode ('utf-8' )
648
+ value_bytes = value .encode ()
649
649
except Exception :
650
650
raise ValueError (f'Invalid value for { attr } ' ) from None
651
651
@@ -745,7 +745,7 @@ def decode(s: Union[str, bytes]) -> str:
745
745
@staticmethod
746
746
def encode (s : Union [str , bytes ]) -> str :
747
747
if isinstance (s , str ):
748
- s = s .encode ('utf-8' )
748
+ s = s .encode ()
749
749
750
750
val = _get_obj (lib .ada_idna_to_ascii , lib .ada_free_owned_string , s , len (s ))
751
751
return ffi .string (val .data , val .length ) if val .length else b''
0 commit comments