365 line = physical_line.rstrip() |
365 line = physical_line.rstrip() |
366 length = len(line) |
366 length = len(line) |
367 if length > MAX_LINE_LENGTH: |
367 if length > MAX_LINE_LENGTH: |
368 try: |
368 try: |
369 # The line could contain multi-byte characters |
369 # The line could contain multi-byte characters |
370 if not hasattr(line, 'decode'): # Python 3 |
370 if hasattr(line, 'decode'): # Python 2 only |
371 line = line.encode('latin-1') |
371 length = len(line.decode('utf-8')) |
372 length = len(line.decode('utf-8')) |
|
373 except UnicodeDecodeError: |
372 except UnicodeDecodeError: |
374 pass |
373 pass |
375 if length > MAX_LINE_LENGTH: |
374 if length > MAX_LINE_LENGTH: |
376 return MAX_LINE_LENGTH, "E501", length |
375 return MAX_LINE_LENGTH, "E501", length |
377 |
376 |