@@ -115,7 +115,7 @@ def _get_obj(constructor, destructor, *args):
115115
116116
117117def _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 ''
119119 return ret
120120
121121
@@ -185,14 +185,14 @@ class URL:
185185 scheme_type : Final [SchemeType ]
186186
187187 def __init__ (self , url : str , base : Optional [str ] = None ):
188- url_bytes = url .encode ('utf-8' )
188+ url_bytes = url .encode ()
189189
190190 if base is None :
191191 self .urlobj = _get_obj (
192192 lib .ada_parse , lib .ada_free , url_bytes , len (url_bytes )
193193 )
194194 else :
195- base_bytes = base .encode ('utf-8' )
195+ base_bytes = base .encode ()
196196 self .urlobj = _get_obj (
197197 lib .ada_parse_with_base ,
198198 lib .ada_free ,
@@ -254,7 +254,7 @@ def __getattr__(self, attr: str) -> Union[str, HostType, SchemeType]:
254254 def __setattr__ (self , attr : str , value : str ) -> None :
255255 if attr in SET_ATTRIBUTES :
256256 try :
257- value_bytes = value .encode ('utf-8' )
257+ value_bytes = value .encode ()
258258 except Exception :
259259 raise ValueError (f'Invalid value for { attr } ' ) from None
260260
@@ -276,15 +276,15 @@ def __repr__(self):
276276 @staticmethod
277277 def can_parse (url : str , base : Optional [str ] = None ) -> bool :
278278 try :
279- url_bytes = url .encode ('utf-8' )
279+ url_bytes = url .encode ()
280280 except Exception :
281281 return False
282282
283283 if base is None :
284284 return lib .ada_can_parse (url_bytes , len (url_bytes ))
285285
286286 try :
287- base_bytes = base .encode ('utf-8' )
287+ base_bytes = base .encode ()
288288 except Exception :
289289 return False
290290
@@ -347,7 +347,7 @@ class URLSearchParams:
347347 """
348348
349349 def __init__ (self , params : str ):
350- params_bytes = params .encode ('utf-8' )
350+ params_bytes = params .encode ()
351351 self .paramsobj = _get_obj (
352352 lib .ada_parse_search_params ,
353353 lib .ada_free_search_params ,
@@ -363,8 +363,8 @@ def __len__(self) -> int:
363363 return self .size
364364
365365 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 ()
368368 lib .ada_search_params_append (
369369 self .paramsobj ,
370370 key_bytes ,
@@ -374,11 +374,11 @@ def append(self, key: str, value: str):
374374 )
375375
376376 def delete (self , key : str , value : Optional [str ] = None ):
377- key_bytes = key .encode ('utf-8' )
377+ key_bytes = key .encode ()
378378 if value is None :
379379 lib .ada_search_params_remove (self .paramsobj , key_bytes , len (key_bytes ))
380380 else :
381- value_bytes = value .encode ('utf-8' )
381+ value_bytes = value .encode ()
382382 lib .ada_search_params_remove_value (
383383 self .paramsobj ,
384384 key_bytes ,
@@ -388,12 +388,12 @@ def delete(self, key: str, value: Optional[str] = None):
388388 )
389389
390390 def get (self , key : str ) -> str :
391- key_bytes = key .encode ('utf-8' )
391+ key_bytes = key .encode ()
392392 item = lib .ada_search_params_get (self .paramsobj , key_bytes , len (key_bytes ))
393393 return _get_str (item )
394394
395395 def get_all (self , key : str ) -> List [str ]:
396- key_bytes = key .encode ('utf-8' )
396+ key_bytes = key .encode ()
397397 items = lib .ada_search_params_get_all (self .paramsobj , key_bytes , len (key_bytes ))
398398 count = lib .ada_strings_size (items )
399399
@@ -405,11 +405,11 @@ def get_all(self, key: str) -> List[str]:
405405 return ret
406406
407407 def has (self , key : str , value : Optional [str ] = None ) -> bool :
408- key_bytes = key .encode ('utf-8' )
408+ key_bytes = key .encode ()
409409 if value is None :
410410 return lib .ada_search_params_has (self .paramsobj , key_bytes , len (key_bytes ))
411411 else :
412- value_bytes = value .encode ('utf-8' )
412+ value_bytes = value .encode ()
413413 return lib .ada_search_params_has_value (
414414 self .paramsobj ,
415415 key_bytes ,
@@ -419,8 +419,8 @@ def has(self, key: str, value: Optional[str] = None) -> bool:
419419 )
420420
421421 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 ()
424424 lib .ada_search_params_set (
425425 self .paramsobj ,
426426 key_bytes ,
@@ -486,7 +486,7 @@ def check_url(s: str) -> bool:
486486
487487 """
488488 try :
489- s_bytes = s .encode ('utf-8' )
489+ s_bytes = s .encode ()
490490 except Exception :
491491 return False
492492
@@ -508,8 +508,8 @@ def join_url(base_url: str, s: str) -> str:
508508
509509 """
510510 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 ()
513513 except Exception :
514514 raise ValueError ('Invalid URL' ) from None
515515
@@ -584,7 +584,7 @@ def parse_url(s: str, attributes: Iterable[str] = PARSE_ATTRIBUTES) -> ParseAttr
584584
585585 """
586586 try :
587- s_bytes = s .encode ('utf-8' )
587+ s_bytes = s .encode ()
588588 except Exception :
589589 raise ValueError ('Invalid URL' ) from None
590590
@@ -629,7 +629,7 @@ def replace_url(s: str, **kwargs: str) -> str:
629629 ``ValueError`` is raised if the input URL or one of the components is not valid.
630630 """
631631 try :
632- s_bytes = s .encode ('utf-8' )
632+ s_bytes = s .encode ()
633633 except Exception :
634634 raise ValueError ('Invalid URL' ) from None
635635
@@ -645,7 +645,7 @@ def replace_url(s: str, **kwargs: str) -> str:
645645 continue
646646
647647 try :
648- value_bytes = value .encode ('utf-8' )
648+ value_bytes = value .encode ()
649649 except Exception :
650650 raise ValueError (f'Invalid value for { attr } ' ) from None
651651
@@ -745,7 +745,7 @@ def decode(s: Union[str, bytes]) -> str:
745745 @staticmethod
746746 def encode (s : Union [str , bytes ]) -> str :
747747 if isinstance (s , str ):
748- s = s .encode ('utf-8' )
748+ s = s .encode ()
749749
750750 val = _get_obj (lib .ada_idna_to_ascii , lib .ada_free_owned_string , s , len (s ))
751751 return ffi .string (val .data , val .length ) if val .length else b''
0 commit comments