In Python 3.x, a single element of a bytes array is returned as
an integer number. Thus, NEWLINE is an int variable, and attempting
to add it to the line array will fail with a type mismatch error
that may be demonstrated as follows:
[roam@straylight ~]$ python3 -c 'b"hello" + b"\n"[0]'
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: can't concat int to bytes
[roam@straylight ~]$
the first line always ends in a :\n:, even if it is the last line and :data:
doesn't end in :\n:.
"""
- NEWLINE = b"\n"[0]
+ NEWLINE = b"\n"
if data == b'':
return (None, data)
data = data[end_idx:]
assert len(line) != 0
- if line[-1] != NEWLINE:
+ if not line.endswith(NEWLINE):
line += NEWLINE
return (line, data)