summaryrefslogtreecommitdiffstats
path: root/Doc/tools/rstlint.py
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/tools/rstlint.py')
-rwxr-xr-xDoc/tools/rstlint.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/Doc/tools/rstlint.py b/Doc/tools/rstlint.py
index 0c19003..2cc3d12 100755
--- a/Doc/tools/rstlint.py
+++ b/Doc/tools/rstlint.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Check for stylistic and formal issues in .rst and .py
@@ -72,7 +72,7 @@ def check_syntax(fn, lines):
code = code.replace('\r', '')
try:
compile(code, fn, 'exec')
- except SyntaxError, err:
+ except SyntaxError as err:
yield err.lineno, 'not compilable: %s' % err
@@ -139,7 +139,7 @@ Options: -v verbose (print all checked file names)
try:
gopts, args = getopt.getopt(argv[1:], 'vfs:i:')
except getopt.GetoptError:
- print usage
+ print(usage)
return 2
verbose = False
@@ -161,15 +161,14 @@ Options: -v verbose (print all checked file names)
elif len(args) == 1:
path = args[0]
else:
- print usage
+ print(usage)
return 2
if not exists(path):
- print 'Error: path %s does not exist' % path
+ print('Error: path %s does not exist' % path)
return 2
count = defaultdict(int)
- out = sys.stdout
for root, dirs, files in os.walk(path):
# ignore subdirs controlled by svn
@@ -196,13 +195,13 @@ Options: -v verbose (print all checked file names)
continue
if verbose:
- print 'Checking %s...' % fn
+ print('Checking %s...' % fn)
try:
with open(fn, 'r') as f:
lines = list(f)
- except (IOError, OSError), err:
- print '%s: cannot open: %s' % (fn, err)
+ except (IOError, OSError) as err:
+ print('%s: cannot open: %s' % (fn, err))
count[4] += 1
continue
@@ -212,20 +211,20 @@ Options: -v verbose (print all checked file names)
csev = checker.severity
if csev >= severity:
for lno, msg in checker(fn, lines):
- print >>out, '[%d] %s:%d: %s' % (csev, fn, lno, msg)
+ print('[%d] %s:%d: %s' % (csev, fn, lno, msg))
count[csev] += 1
if verbose:
- print
+ print()
if not count:
if severity > 1:
- print 'No problems with severity >= %d found.' % severity
+ print('No problems with severity >= %d found.' % severity)
else:
- print 'No problems found.'
+ print('No problems found.')
else:
for severity in sorted(count):
number = count[severity]
- print '%d problem%s with severity %d found.' % \
- (number, number > 1 and 's' or '', severity)
+ print('%d problem%s with severity %d found.' %
+ (number, number > 1 and 's' or '', severity))
return int(bool(count))