mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Modernize the code now that Python 2.5 is no longer supported
- Use print function instead of print statement; - Use new exception handling; - Use in operator instead of has_key(); - Do not use tuple arguments in functions; - Other miscellaneous improvements. This is based on output of `futurize --stage1`, with some manual corrections.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
:copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import sys, os, re
|
||||
import cStringIO
|
||||
@@ -54,7 +55,7 @@ if sys.version_info < (3, 0):
|
||||
def check_syntax(fn, lines):
|
||||
try:
|
||||
compile(b('').join(lines), fn, "exec")
|
||||
except SyntaxError, err:
|
||||
except SyntaxError as err:
|
||||
yield 0, "not compilable: %s" % err
|
||||
|
||||
|
||||
@@ -77,9 +78,9 @@ def check_style_and_encoding(fn, lines):
|
||||
yield lno+1, 'using == None/True/False'
|
||||
try:
|
||||
line.decode(encoding)
|
||||
except UnicodeDecodeError, err:
|
||||
except UnicodeDecodeError as err:
|
||||
yield lno+1, "not decodable: %s\n Line: %r" % (err, line)
|
||||
except LookupError, err:
|
||||
except LookupError as err:
|
||||
yield 0, "unknown encoding: %s" % encoding
|
||||
encoding = 'latin1'
|
||||
|
||||
@@ -183,7 +184,7 @@ def main(argv):
|
||||
elif len(args) == 1:
|
||||
path = args[0]
|
||||
else:
|
||||
print args
|
||||
print(args)
|
||||
parser.error('No more then one path supported')
|
||||
|
||||
verbose = options.verbose
|
||||
@@ -214,7 +215,7 @@ def main(argv):
|
||||
continue
|
||||
|
||||
if verbose:
|
||||
print "Checking %s..." % fn
|
||||
print("Checking %s..." % fn)
|
||||
|
||||
try:
|
||||
f = open(fn, 'rb')
|
||||
@@ -222,8 +223,8 @@ def main(argv):
|
||||
lines = list(f)
|
||||
finally:
|
||||
f.close()
|
||||
except (IOError, OSError), err:
|
||||
print "%s: cannot open: %s" % (fn, err)
|
||||
except (IOError, OSError) as err:
|
||||
print("%s: cannot open: %s" % (fn, err))
|
||||
num += 1
|
||||
continue
|
||||
|
||||
@@ -231,15 +232,15 @@ def main(argv):
|
||||
if not in_check_pkg and checker.only_pkg:
|
||||
continue
|
||||
for lno, msg in checker(fn, lines):
|
||||
print >>out, "%s:%d: %s" % (fn, lno, msg)
|
||||
print("%s:%d: %s" % (fn, lno, msg), file=out)
|
||||
num += 1
|
||||
if verbose:
|
||||
print
|
||||
print()
|
||||
if num == 0:
|
||||
print "No errors found."
|
||||
print("No errors found.")
|
||||
else:
|
||||
print out.getvalue().rstrip('\n')
|
||||
print "%d error%s found." % (num, num > 1 and "s" or "")
|
||||
print(out.getvalue().rstrip('\n'))
|
||||
print("%d error%s found." % (num, num > 1 and "s" or ""))
|
||||
return int(num > 0)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user