MCPcopy
hub / github.com/scrapy/scrapy / to_unicode

Function to_unicode

scrapy/utils/python.py:72–85  ·  view source on GitHub ↗

Return the unicode representation of a bytes object ``text``. If ``text`` is already an unicode object, return it as-is.

(
    text: str | bytes, encoding: str | None = None, errors: str = "strict"
)

Source from the content-addressed store, hash-verified

70
71
72def to_unicode(
73 text: str | bytes, encoding: str | None = None, errors: str = "strict"
74) -> str:
75 """Return the unicode representation of a bytes object ``text``. If
76 ``text`` is already an unicode object, return it as-is."""
77 if isinstance(text, str):
78 return text
79 if not isinstance(text, (bytes, str)):
80 raise TypeError(
81 f"to_unicode must receive a bytes or str object, got {type(text).__name__}"
82 )
83 if encoding is None:
84 encoding = "utf-8"
85 return text.decode(encoding, errors)
86
87
88def to_bytes(

Callers 15

_build_rowMethod · 0.90
_serialize_valueMethod · 0.90
decode_robotstxtFunction · 0.90
allowedMethod · 0.90
allowedMethod · 0.90
allowedMethod · 0.90
from_content_typeMethod · 0.90
ffi_buf_to_stringFunction · 0.90
response_status_messageFunction · 0.90
fingerprintFunction · 0.90
referer_strFunction · 0.90

Calls

no outgoing calls