254 line = physical_line.rstrip() |
254 line = physical_line.rstrip() |
255 length = len(line) |
255 length = len(line) |
256 if length > MAX_LINE_LENGTH: |
256 if length > MAX_LINE_LENGTH: |
257 try: |
257 try: |
258 # The line could contain multi-byte characters |
258 # The line could contain multi-byte characters |
259 if not hasattr(line, 'decode'): # Python 3 |
259 if hasattr(line, 'decode'): # Python 2 only |
260 line = line.encode('latin-1') |
260 length = len(line.decode('utf-8')) |
261 length = len(line.decode('utf-8')) |
|
262 except UnicodeDecodeError: |
261 except UnicodeDecodeError: |
263 pass |
262 pass |
264 if length > MAX_LINE_LENGTH: |
263 if length > MAX_LINE_LENGTH: |
265 return MAX_LINE_LENGTH, "E501", length |
264 return MAX_LINE_LENGTH, "E501", length |
266 |
265 |