Tidy comments in PNM header parsing
@@ -88,11 +88,11 @@ def read_pnm_header(infile):
expected = 3
header = [type]
- # We have to read the rest of the header byte by byte because the
- # final whitespace character (immediately following the MAXVAL in
- # the case of P6) may not be a newline. Of course all PNM files in
- # the wild use a newline at this point, so it's tempting to use
- # readline; but it would be wrong.
+ # We must read the rest of the header byte by byte because
+ # the final whitespace character may not be a newline.
+ # Of course all PNM files in the wild use a newline at this point,
+ # but we are strong and so we avoid
+ # the temptation to use readline.
def getc():
c = infile.read(1)
if not c:
@@ -112,15 +112,14 @@ def read_pnm_header(infile):
raise Error('unexpected character %s found in header' % c)
# According to the specification it is legal to have comments
# that appear in the middle of a token.
- # This is bonkers; I've never seen it; and it's a bit awkward to
- # code good lexers in Python (no goto). So we break on such
- # cases.
+ # I've never seen it; and,
+ # it's a bit awkward to code good lexers in Python (no goto).
+ # So we break on such cases.
token = b''
while c.isdigit():
token += c
c = getc()
- # Slight hack. All "tokens" are decimal integers, so convert
- # them here.
+ # All "tokens" are decimal integers, so convert them here.
header.append(int(token))
if len(header) == expected:
break
