Method: pylint.checkers.unicode._fix_utf16_32_line_stream
Calls: 1181, Exceptions: 0, Paths: 3Back
Path 1: 1143 calls (0.97)
BufferedReader (1128) BytesIO (15)
'utf-8' (1134) 'iso-8859-1' (5) 'ascii' (3) 'utf' (1)
bytes (41634) None (1143)
1def _fix_utf16_32_line_stream(steam: Iterable[bytes], codec: str) -> Iterable[bytes]:
2 """Handle line ending for UTF16 and UTF32 correctly.
3
4 Currently, Python simply strips the required zeros after \n after the
5 line ending. Leading to lines that can't be decoded properly
6 """
7 if not codec.startswith("utf-16") and not codec.startswith("utf-32"):
8 yield from steam
9 else:
10 # First we get all the bytes in memory
11 content = b"".join(line for line in steam)
12
13 new_line = _cached_encode_search("\n", codec)
14
15 # Now we split the line by the real new line in the correct encoding
16 # we can't use split as it would strip the \n that we need
17 start = 0
18 while True:
19 pos = content.find(new_line, start)
20 if pos >= 0:
21 yield content[start : pos + len(new_line)]
22 else:
23 # Yield the rest and finish
24 if content[start:]:
25 yield content[start:]
26 break
27
28 start = pos + len(new_line)
Path 2: 24 calls (0.02)
BytesIO (12) BufferedReader (12)
'utf-16le' (8) 'utf-32le' (8) 'utf-16' (2) 'utf-16be' (2) 'utf-32' (2) 'utf-32be' (2)
bytes (112)
1def _fix_utf16_32_line_stream(steam: Iterable[bytes], codec: str) -> Iterable[bytes]:
2 """Handle line ending for UTF16 and UTF32 correctly.
3
4 Currently, Python simply strips the required zeros after \n after the
5 line ending. Leading to lines that can't be decoded properly
6 """
7 if not codec.startswith("utf-16") and not codec.startswith("utf-32"):
8 yield from steam
9 else:
10 # First we get all the bytes in memory
11 content = b"".join(line for line in steam)
12
13 new_line = _cached_encode_search("\n", codec)
14
15 # Now we split the line by the real new line in the correct encoding
16 # we can't use split as it would strip the \n that we need
17 start = 0
18 while True:
19 pos = content.find(new_line, start)
20 if pos >= 0:
21 yield content[start : pos + len(new_line)]
22 else:
23 # Yield the rest and finish
24 if content[start:]:
25 yield content[start:]
26 break
27
28 start = pos + len(new_line)
Path 3: 14 calls (0.01)
BufferedReader (12) BytesIO (2)
'utf-16le' (3) 'utf-32le' (3) 'utf-16' (2) 'utf-16be' (2) 'utf-32' (2) 'utf-32be' (2)
bytes (56)
1def _fix_utf16_32_line_stream(steam: Iterable[bytes], codec: str) -> Iterable[bytes]:
2 """Handle line ending for UTF16 and UTF32 correctly.
3
4 Currently, Python simply strips the required zeros after \n after the
5 line ending. Leading to lines that can't be decoded properly
6 """
7 if not codec.startswith("utf-16") and not codec.startswith("utf-32"):
8 yield from steam
9 else:
10 # First we get all the bytes in memory
11 content = b"".join(line for line in steam)
12
13 new_line = _cached_encode_search("\n", codec)
14
15 # Now we split the line by the real new line in the correct encoding
16 # we can't use split as it would strip the \n that we need
17 start = 0
18 while True:
19 pos = content.find(new_line, start)
20 if pos >= 0:
21 yield content[start : pos + len(new_line)]
22 else:
23 # Yield the rest and finish
24 if content[start:]:
25 yield content[start:]
26 break
27
28 start = pos + len(new_line)