Plugins/CheckerPlugins/Pep8/pep8.py

branch
Py2 comp.
changeset 2607
e5115553185a
parent 2302
f29e9405c851
child 2847
1843ef6e2656
equal deleted inserted replaced
2602:affc66a603c7 2607:e5115553185a
362 For flowing long blocks of text (docstrings or comments), limiting the 362 For flowing long blocks of text (docstrings or comments), limiting the
363 length to 72 characters is recommended. 363 length to 72 characters is recommended.
364 """ 364 """
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 try:
368 try: 368 # The line could contain multi-byte characters
369 # The line could contain multi-byte characters 369 if hasattr(line, 'decode'): # Python 2 only
370 if hasattr(line, 'decode'): # Python 2 only 370 length = len(line.decode('utf-8'))
371 length = len(line.decode('utf-8')) 371 except (UnicodeDecodeError, UnicodeEncodeError):
372 except UnicodeDecodeError: 372 pass
373 pass
374 if length > MAX_LINE_LENGTH: 373 if length > MAX_LINE_LENGTH:
375 return MAX_LINE_LENGTH, "E501", length 374 return MAX_LINE_LENGTH, "E501", length
376 375
377 376
378 ############################################################################## 377 ##############################################################################
983 if self.indent_char is None and len(line) and line[0] in ' \t': 982 if self.indent_char is None and len(line) and line[0] in ' \t':
984 self.indent_char = line[0] 983 self.indent_char = line[0]
985 for name, check, argument_names in options.physical_checks: 984 for name, check, argument_names in options.physical_checks:
986 result = self.run_check(check, argument_names) 985 result = self.run_check(check, argument_names)
987 if result is not None: 986 if result is not None:
988 offset, code, *args = result 987 offset, code = result[:2]
988 args = result[2:]
989 self.report_error_args(self.line_number, offset, code, check, 989 self.report_error_args(self.line_number, offset, code, check,
990 *args) 990 *args)
991 991
992 def build_tokens_line(self): 992 def build_tokens_line(self):
993 """ 993 """
1039 for name, check, argument_names in options.logical_checks: 1039 for name, check, argument_names in options.logical_checks:
1040 if options.verbose >= 4: 1040 if options.verbose >= 4:
1041 print(' ' + name) 1041 print(' ' + name)
1042 result = self.run_check(check, argument_names) 1042 result = self.run_check(check, argument_names)
1043 if result is not None: 1043 if result is not None:
1044 offset, code, *args = result 1044 offset, code = result[:2]
1045 args = result[2:]
1045 if isinstance(offset, tuple): 1046 if isinstance(offset, tuple):
1046 original_number, original_offset = offset 1047 original_number, original_offset = offset
1047 else: 1048 else:
1048 for token_offset, token in self.mapping: 1049 for token_offset, token in self.mapping:
1049 if offset >= token_offset: 1050 if offset >= token_offset:

eric ide

mercurial