Method: pylint.checkers.unicode.extract_codec_from_bom
Calls: 19, Exceptions: 1, Paths: 2Back
Path 1: 18 calls (0.95)
bytes (18)
'utf-16le' (8) 'utf-32le' (8) 'utf-16be' (1) 'utf-32be' (1)
1def extract_codec_from_bom(first_line: bytes) -> str:
2 """Try to extract the codec (unicode only) by checking for the BOM.
3
4 For details about BOM see https://unicode.org/faq/utf_bom.html#BOM
5
6 Args:
7 first_line: the first line of a file
8
9 Returns:
10 a codec name
11
12 Raises:
13 ValueError: if no codec was found
14 """
15 for bom, codec in BOM_SORTED_TO_CODEC.items():
16 if first_line.startswith(bom):
17 return codec
18
19 raise ValueError("No BOM found. Could not detect Unicode codec.")
Path 2: 1 calls (0.05)
bytes (1)
ValueError (1)
1def extract_codec_from_bom(first_line: bytes) -> str:
2 """Try to extract the codec (unicode only) by checking for the BOM.
3
4 For details about BOM see https://unicode.org/faq/utf_bom.html#BOM
5
6 Args:
7 first_line: the first line of a file
8
9 Returns:
10 a codec name
11
12 Raises:
13 ValueError: if no codec was found
14 """
15 for bom, codec in BOM_SORTED_TO_CODEC.items():
16 if first_line.startswith(bom):
17 return codec
18
19 raise ValueError("No BOM found. Could not detect Unicode codec.")