Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._internal.utils.encoding Namespace Reference

Functions

str auto_decode (bytes data)
 

Variables

list BOMS
 
 ENCODING_RE = re.compile(rb"coding[:=]\s*([-\w.]+)")
 

Function Documentation

◆ auto_decode()

str auto_decode ( bytes  data)
Check a bytes string for a BOM to correctly detect the encoding

Fallback to locale.getpreferredencoding(False) like open() on Python3

Definition at line 20 of file encoding.py.

20def auto_decode(data: bytes) -> str:
21 """Check a bytes string for a BOM to correctly detect the encoding
22
23 Fallback to locale.getpreferredencoding(False) like open() on Python3"""
24 for bom, encoding in BOMS:
25 if data.startswith(bom):
26 return data[len(bom) :].decode(encoding)
27 # Lets check the first two lines as in PEP263
28 for line in data.split(b"\n")[:2]:
29 if line[0:1] == b"#" and ENCODING_RE.search(line):
30 result = ENCODING_RE.search(line)
31 assert result is not None
32 encoding = result.groups()[0].decode("ascii")
33 return data.decode(encoding)
34 return data.decode(
36 )
for i

References i.

Variable Documentation

◆ BOMS

list BOMS
Initial value:
1= [
2 (codecs.BOM_UTF8, "utf-8"),
3 (codecs.BOM_UTF16, "utf-16"),
4 (codecs.BOM_UTF16_BE, "utf-16-be"),
5 (codecs.BOM_UTF16_LE, "utf-16-le"),
6 (codecs.BOM_UTF32, "utf-32"),
7 (codecs.BOM_UTF32_BE, "utf-32-be"),
8 (codecs.BOM_UTF32_LE, "utf-32-le"),
9]

Definition at line 7 of file encoding.py.

◆ ENCODING_RE

ENCODING_RE = re.compile(rb"coding[:=]\s*([-\w.]+)")

Definition at line 17 of file encoding.py.