Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove Python 2-only code in suspicious
  • Loading branch information
AA-Turner committed Jun 11, 2022
commit 9c9a2c142738e1a1e6e46102d989d5dad7b961c4
41 changes: 7 additions & 34 deletions Doc/tools/extensions/suspicious.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import os
import re
import csv
import sys

from docutils import nodes
from sphinx.builders import Builder
Expand All @@ -55,9 +54,7 @@
:[a-zA-Z][a-zA-Z0-9]+| # :foo
`| # ` (seldom used by itself)
(?<!\.)\.\.[ \t]*\w+: # .. foo: (but NOT ... else:)
''', re.UNICODE | re.VERBOSE).finditer

py3 = sys.version_info >= (3, 0)
''', re.VERBOSE).finditer


class Rule:
Expand Down Expand Up @@ -152,32 +149,15 @@ def is_ignored(self, line, lineno, issue):
def report_issue(self, text, lineno, issue):
self.any_issue = True
self.write_log_entry(lineno, issue, text)
if py3:
self.logger.warning('[%s:%d] "%s" found in "%-.120s"' %
self.logger.warning('[%s:%d] "%s" found in "%-.120s"' %
(self.docname, lineno, issue, text))
else:
self.logger.warning(
'[%s:%d] "%s" found in "%-.120s"' % (
self.docname.encode(sys.getdefaultencoding(),'replace'),
lineno,
issue.encode(sys.getdefaultencoding(),'replace'),
text.strip().encode(sys.getdefaultencoding(),'replace')))
self.app.statuscode = 1

def write_log_entry(self, lineno, issue, text):
if py3:
f = open(self.log_file_name, 'a')
writer = csv.writer(f, dialect)
writer.writerow([self.docname, lineno, issue, text.strip()])
f.close()
else:
f = open(self.log_file_name, 'ab')
writer = csv.writer(f, dialect)
writer.writerow([self.docname.encode('utf-8'),
lineno,
issue.encode('utf-8'),
text.strip().encode('utf-8')])
f.close()
f = open(self.log_file_name, 'a')
writer = csv.writer(f, dialect)
writer.writerow([self.docname, lineno, issue, text.strip()])
f.close()

def load_rules(self, filename):
"""Load database of previously ignored issues.
Expand All @@ -188,10 +168,7 @@ def load_rules(self, filename):
self.logger.info("loading ignore rules... ", nonl=1)
self.rules = rules = []
try:
if py3:
f = open(filename, 'r')
else:
f = open(filename, 'rb')
f = open(filename, 'r')
except IOError:
return
for i, row in enumerate(csv.reader(f)):
Expand All @@ -203,10 +180,6 @@ def load_rules(self, filename):
lineno = int(lineno)
else:
lineno = None
if not py3:
docname = docname.decode('utf-8')
issue = issue.decode('utf-8')
text = text.decode('utf-8')
rule = Rule(docname, lineno, issue, text)
rules.append(rule)
f.close()
Expand Down