22from typing import Optional
33from w3lib ._types import StrOrBytes
44
5- def str_to_unicode (text : StrOrBytes , encoding : Optional [str ] = None , errors : str = 'strict' ) -> str :
5+
6+ def str_to_unicode (
7+ text : StrOrBytes , encoding : Optional [str ] = None , errors : str = 'strict'
8+ ) -> str :
69 if encoding is None :
710 encoding = 'utf-8'
811 if isinstance (text , bytes ):
912 return text .decode (encoding , errors )
1013 return text
1114
12- def unicode_to_str (text : StrOrBytes , encoding : Optional [str ] = None , errors : str = 'strict' ) -> bytes :
15+ def unicode_to_str (
16+ text : StrOrBytes , encoding : Optional [str ] = None , errors : str = 'strict'
17+ ) -> bytes :
1318 warn (
1419 "The w3lib.utils.unicode_to_str function is deprecated and "
1520 "will be removed in a future release." ,
@@ -22,7 +27,10 @@ def unicode_to_str(text: StrOrBytes, encoding: Optional[str] = None, errors: str
2227 return text .encode (encoding , errors )
2328 return text
2429
25- def to_unicode (text : StrOrBytes , encoding : Optional [str ] = None , errors : str = 'strict' ) -> str :
30+
31+ def to_unicode (
32+ text : StrOrBytes , encoding : Optional [str ] = None , errors : str = 'strict'
33+ ) -> str :
2634 """Return the unicode representation of a bytes object `text`. If `text`
2735 is already an unicode object, return it as-is."""
2836 if isinstance (text , str ):
@@ -35,7 +43,10 @@ def to_unicode(text: StrOrBytes, encoding: Optional[str] = None, errors: str = '
3543 encoding = 'utf-8'
3644 return text .decode (encoding , errors )
3745
38- def to_bytes (text : StrOrBytes , encoding : Optional [str ] = None , errors : str = 'strict' ) -> bytes :
46+
47+ def to_bytes (
48+ text : StrOrBytes , encoding : Optional [str ] = None , errors : str = 'strict'
49+ ) -> bytes :
3950 """Return the binary representation of `text`. If `text`
4051 is already a bytes object, return it as-is."""
4152 if isinstance (text , bytes ):
@@ -48,7 +59,10 @@ def to_bytes(text: StrOrBytes, encoding: Optional[str] = None, errors: str = 'st
4859 encoding = 'utf-8'
4960 return text .encode (encoding , errors )
5061
51- def to_native_str (text : StrOrBytes , encoding : Optional [str ] = None , errors : str = 'strict' ) -> str :
62+
63+ def to_native_str (
64+ text : StrOrBytes , encoding : Optional [str ] = None , errors : str = 'strict'
65+ ) -> str :
5266 """ Return str representation of `text` """
5367 warn (
5468 "The w3lib.utils.to_native_str function is deprecated and "
0 commit comments