387 """ |
387 """ |
388 line = physical_line.rstrip() |
388 line = physical_line.rstrip() |
389 length = len(line) |
389 length = len(line) |
390 if length > max_line_length and not noqa(line): |
390 if length > max_line_length and not noqa(line): |
391 if hasattr(line, 'decode'): # Python 2 |
391 if hasattr(line, 'decode'): # Python 2 |
392 # The line could contain multi-byte characters |
392 # The line could contain multi-byte characters |
393 try: |
393 try: |
394 length = len(line.decode('utf-8')) |
394 length = len(line.decode('utf-8')) |
395 except (UnicodeDecodeError, UnicodeEncodeError): |
395 except (UnicodeDecodeError, UnicodeEncodeError): |
396 pass |
396 pass |
397 if length > max_line_length: |
397 if length > max_line_length: |
1376 elif self.lines[0][:3] == '\xef\xbb\xbf': |
1376 elif self.lines[0][:3] == '\xef\xbb\xbf': |
1377 self.lines[0] = self.lines[0][3:] |
1377 self.lines[0] = self.lines[0][3:] |
1378 self.report = report or options.report |
1378 self.report = report or options.report |
1379 self.report_error = self.report.error |
1379 self.report_error = self.report.error |
1380 self.report_error_args = self.report.error_args |
1380 self.report_error_args = self.report.error_args |
|
1381 |
|
1382 # added for eric5 integration |
|
1383 self.options = options |
1381 |
1384 |
1382 def report_invalid_syntax(self): |
1385 def report_invalid_syntax(self): |
1383 exc_type, exc = sys.exc_info()[:2] |
1386 exc_type, exc = sys.exc_info()[:2] |
1384 if len(exc.args) > 1: |
1387 if len(exc.args) > 1: |
1385 offset = exc.args[1] |
1388 offset = exc.args[1] |
1386 if len(offset) > 2: |
1389 if len(offset) > 2: |
1387 offset = offset[1:3] |
1390 offset = offset[1:3] |
1388 else: |
1391 else: |
1389 offset = (1, 0) |
1392 offset = (1, 0) |
1390 self.report_error_args(offset[0], offset[1] or 0, |
1393 self.report_error_args(offset[0], offset[1] or 0, |
1391 'E901', exc_type.__name__, exc.args[0], |
1394 'E901', self.report_invalid_syntax, |
1392 self.report_invalid_syntax) |
1395 exc_type.__name__, exc.args[0]) |
1393 report_invalid_syntax.__doc__ = " Check if the syntax is valid." |
1396 report_invalid_syntax.__doc__ = " Check if the syntax is valid." |
1394 |
1397 |
1395 def readline(self): |
1398 def readline(self): |
1396 """ |
1399 """ |
1397 Get the next line from the input buffer. |
1400 Get the next line from the input buffer. |
1508 try: |
1511 try: |
1509 tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST) |
1512 tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST) |
1510 except (SyntaxError, TypeError): |
1513 except (SyntaxError, TypeError): |
1511 return self.report_invalid_syntax() |
1514 return self.report_invalid_syntax() |
1512 for name, cls, _ in self._ast_checks: |
1515 for name, cls, _ in self._ast_checks: |
1513 checker = cls(tree, self.filename) |
1516 # extended API for eric5 integration |
|
1517 checker = cls(tree, self.filename, self.options) |
1514 for args in checker.run(): |
1518 for args in checker.run(): |
1515 lineno = args.pop(0) |
1519 lineno = args[0] |
1516 if not noqa(self.lines[lineno - 1]): |
1520 if not noqa(self.lines[lineno - 1]): |
1517 self.report_error_args(lineno, *args) |
1521 self.report_error_args(lineno, *args[1:]) |
1518 |
1522 |
1519 def generate_tokens(self): |
1523 def generate_tokens(self): |
1520 if self._io_error: |
1524 if self._io_error: |
1521 self.report_error(1, 0, 'E902 %s' % self._io_error, readlines) |
1525 self.report_error(1, 0, 'E902 %s' % self._io_error, readlines) |
1522 tokengen = tokenize.generate_tokens(self.readline_check_physical) |
1526 tokengen = tokenize.generate_tokens(self.readline_check_physical) |