fixed print statements in pygments for python3
This commit is contained in:
parent
ce8d9af149
commit
be54a19207
8 changed files with 61 additions and 63 deletions
|
@ -119,25 +119,25 @@ def _print_help(what, name):
|
|||
try:
|
||||
if what == 'lexer':
|
||||
cls = find_lexer_class(name)
|
||||
print "Help on the %s lexer:" % cls.name
|
||||
print dedent(cls.__doc__)
|
||||
print("Help on the %s lexer:" % cls.name)
|
||||
print(dedent(cls.__doc__))
|
||||
elif what == 'formatter':
|
||||
cls = find_formatter_class(name)
|
||||
print "Help on the %s formatter:" % cls.name
|
||||
print dedent(cls.__doc__)
|
||||
print("Help on the %s formatter:" % cls.name)
|
||||
print(dedent(cls.__doc__))
|
||||
elif what == 'filter':
|
||||
cls = find_filter_class(name)
|
||||
print "Help on the %s filter:" % name
|
||||
print dedent(cls.__doc__)
|
||||
print("Help on the %s filter:" % name)
|
||||
print(dedent(cls.__doc__))
|
||||
except AttributeError:
|
||||
print >>sys.stderr, "%s not found!" % what
|
||||
print("%s not found!" % what, file=sys.stderr)
|
||||
|
||||
|
||||
def _print_list(what):
|
||||
if what == 'lexer':
|
||||
print
|
||||
print "Lexers:"
|
||||
print "~~~~~~~"
|
||||
print("Lexers:")
|
||||
print("~~~~~~~")
|
||||
|
||||
info = []
|
||||
for fullname, names, exts, _ in get_all_lexers():
|
||||
|
@ -146,12 +146,12 @@ def _print_list(what):
|
|||
info.append(tup)
|
||||
info.sort()
|
||||
for i in info:
|
||||
print ('* %s\n %s %s') % i
|
||||
print(('* %s\n %s %s') % i)
|
||||
|
||||
elif what == 'formatter':
|
||||
print
|
||||
print "Formatters:"
|
||||
print "~~~~~~~~~~~"
|
||||
print("Formatters:")
|
||||
print("~~~~~~~~~~~")
|
||||
|
||||
info = []
|
||||
for cls in get_all_formatters():
|
||||
|
@ -161,27 +161,27 @@ def _print_list(what):
|
|||
info.append(tup)
|
||||
info.sort()
|
||||
for i in info:
|
||||
print ('* %s\n %s %s') % i
|
||||
print(('* %s\n %s %s') % i)
|
||||
|
||||
elif what == 'filter':
|
||||
print
|
||||
print "Filters:"
|
||||
print "~~~~~~~~"
|
||||
print("Filters:")
|
||||
print("~~~~~~~~")
|
||||
|
||||
for name in get_all_filters():
|
||||
cls = find_filter_class(name)
|
||||
print "* " + name + ':'
|
||||
print " %s" % docstring_headline(cls)
|
||||
print("* " + name + ':')
|
||||
print(" %s" % docstring_headline(cls))
|
||||
|
||||
elif what == 'style':
|
||||
print
|
||||
print "Styles:"
|
||||
print "~~~~~~~"
|
||||
print("Styles:")
|
||||
print("~~~~~~~")
|
||||
|
||||
for name in get_all_styles():
|
||||
cls = get_style_by_name(name)
|
||||
print "* " + name + ':'
|
||||
print " %s" % docstring_headline(cls)
|
||||
print("* " + name + ':')
|
||||
print(" %s" % docstring_headline(cls))
|
||||
|
||||
|
||||
def main(args=sys.argv):
|
||||
|
@ -203,7 +203,7 @@ def main(args=sys.argv):
|
|||
try:
|
||||
popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:hVHg")
|
||||
except getopt.GetoptError as err:
|
||||
print >>sys.stderr, usage
|
||||
print(usage, file=sys.stderr)
|
||||
return 2
|
||||
opts = {}
|
||||
O_opts = []
|
||||
|
@ -219,25 +219,25 @@ def main(args=sys.argv):
|
|||
opts[opt] = arg
|
||||
|
||||
if not opts and not args:
|
||||
print usage
|
||||
print(usage)
|
||||
return 0
|
||||
|
||||
if opts.pop('-h', None) is not None:
|
||||
print usage
|
||||
print(usage)
|
||||
return 0
|
||||
|
||||
if opts.pop('-V', None) is not None:
|
||||
print 'Pygments version %s, (c) 2006-2013 by Georg Brandl.' % __version__
|
||||
print('Pygments version %s, (c) 2006-2013 by Georg Brandl.' % __version__)
|
||||
return 0
|
||||
|
||||
# handle ``pygmentize -L``
|
||||
L_opt = opts.pop('-L', None)
|
||||
if L_opt is not None:
|
||||
if opts:
|
||||
print >>sys.stderr, usage
|
||||
print(usage, file=sys.stderr)
|
||||
return 2
|
||||
|
||||
# print version
|
||||
# print(version)
|
||||
main(['', '-V'])
|
||||
if not args:
|
||||
args = ['lexer', 'formatter', 'filter', 'style']
|
||||
|
@ -249,12 +249,12 @@ def main(args=sys.argv):
|
|||
H_opt = opts.pop('-H', None)
|
||||
if H_opt is not None:
|
||||
if opts or len(args) != 2:
|
||||
print >>sys.stderr, usage
|
||||
print(usage, file=sys.stderr)
|
||||
return 2
|
||||
|
||||
what, name = args
|
||||
if what not in ('lexer', 'formatter', 'filter'):
|
||||
print >>sys.stderr, usage
|
||||
print(usage, file=sys.stderr)
|
||||
return 2
|
||||
|
||||
_print_help(what, name)
|
||||
|
@ -282,10 +282,10 @@ def main(args=sys.argv):
|
|||
except ClassNotFound as err:
|
||||
lexer = TextLexer()
|
||||
except OptionError as err:
|
||||
print >>sys.stderr, 'Error:', err
|
||||
print('Error:', err, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
print lexer.aliases[0]
|
||||
print(lexer.aliases[0])
|
||||
return 0
|
||||
|
||||
# handle ``pygmentize -S``
|
||||
|
@ -294,30 +294,30 @@ def main(args=sys.argv):
|
|||
if S_opt is not None:
|
||||
f_opt = opts.pop('-f', None)
|
||||
if not f_opt:
|
||||
print >>sys.stderr, usage
|
||||
print(usage, file=sys.stderr)
|
||||
return 2
|
||||
if opts or args:
|
||||
print >>sys.stderr, usage
|
||||
print(usage, file=sys.stderr)
|
||||
return 2
|
||||
|
||||
try:
|
||||
parsed_opts['style'] = S_opt
|
||||
fmter = get_formatter_by_name(f_opt, **parsed_opts)
|
||||
except ClassNotFound as err:
|
||||
print >>sys.stderr, err
|
||||
print(err, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
arg = a_opt or ''
|
||||
try:
|
||||
print fmter.get_style_defs(arg)
|
||||
print(fmter.get_style_defs(arg))
|
||||
except Exception as err:
|
||||
print >>sys.stderr, 'Error:', err
|
||||
print('Error:', err, file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
# if no -S is given, -a is not allowed
|
||||
if a_opt is not None:
|
||||
print >>sys.stderr, usage
|
||||
print(usage, file=sys.stderr)
|
||||
return 2
|
||||
|
||||
# parse -F options
|
||||
|
@ -331,7 +331,7 @@ def main(args=sys.argv):
|
|||
try:
|
||||
fmter = get_formatter_by_name(fmter, **parsed_opts)
|
||||
except (OptionError, ClassNotFound) as err:
|
||||
print >>sys.stderr, 'Error:', err
|
||||
print('Error:', err, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if outfn:
|
||||
|
@ -339,12 +339,12 @@ def main(args=sys.argv):
|
|||
try:
|
||||
fmter = get_formatter_for_filename(outfn, **parsed_opts)
|
||||
except (OptionError, ClassNotFound) as err:
|
||||
print >>sys.stderr, 'Error:', err
|
||||
print('Error:', err, file=sys.stderr)
|
||||
return 1
|
||||
try:
|
||||
outfile = open(outfn, 'wb')
|
||||
except Exception as err:
|
||||
print >>sys.stderr, 'Error: cannot open outfile:', err
|
||||
print('Error: cannot open outfile:', err, file=sys.stderr)
|
||||
return 1
|
||||
else:
|
||||
if not fmter:
|
||||
|
@ -357,19 +357,19 @@ def main(args=sys.argv):
|
|||
try:
|
||||
lexer = get_lexer_by_name(lexer, **parsed_opts)
|
||||
except (OptionError, ClassNotFound) as err:
|
||||
print >>sys.stderr, 'Error:', err
|
||||
print('Error:', err, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if args:
|
||||
if len(args) > 1:
|
||||
print >>sys.stderr, usage
|
||||
print(usage, file=sys.stderr)
|
||||
return 2
|
||||
|
||||
infn = args[0]
|
||||
try:
|
||||
code = open(infn, 'rb').read()
|
||||
except Exception as err:
|
||||
print >>sys.stderr, 'Error: cannot read infile:', err
|
||||
print('Error: cannot read infile:', err, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if not lexer:
|
||||
|
@ -382,10 +382,10 @@ def main(args=sys.argv):
|
|||
except ClassNotFound:
|
||||
lexer = TextLexer(**parsed_opts)
|
||||
else:
|
||||
print >>sys.stderr, 'Error:', err
|
||||
print('Error:', err, file=sys.stderr)
|
||||
return 1
|
||||
except OptionError as err:
|
||||
print >>sys.stderr, 'Error:', err
|
||||
print('Error:', err, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
else:
|
||||
|
@ -396,8 +396,7 @@ def main(args=sys.argv):
|
|||
except ClassNotFound:
|
||||
lexer = TextLexer(**parsed_opts)
|
||||
elif not lexer:
|
||||
print >>sys.stderr, 'Error: no lexer name given and reading ' + \
|
||||
'from stdin (try using -g or -l <lexer>)'
|
||||
print('Error: no lexer name given and reading from stdin (try using -g or -l <lexer>)', file=sys.stderr)
|
||||
return 2
|
||||
else:
|
||||
code = sys.stdin.read()
|
||||
|
@ -433,9 +432,9 @@ def main(args=sys.argv):
|
|||
if len(info) >= 3:
|
||||
# extract relevant file and position info
|
||||
msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:]
|
||||
print >>sys.stderr
|
||||
print >>sys.stderr, '*** Error while highlighting:'
|
||||
print >>sys.stderr, msg
|
||||
print('', file=sys.stderr)
|
||||
print('*** Error while highlighting:', file=sys.stderr)
|
||||
print(msg, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
|
|
@ -57,7 +57,7 @@ if __name__ == '__main__':
|
|||
for filename in os.listdir('.'):
|
||||
if filename.endswith('.py') and not filename.startswith('_'):
|
||||
module_name = 'pygments.formatters.%s' % filename[:-3]
|
||||
print module_name
|
||||
print(module_name)
|
||||
module = __import__(module_name, None, None, [''])
|
||||
for formatter_name in module.__all__:
|
||||
imports.append((module_name, formatter_name))
|
||||
|
|
|
@ -505,8 +505,7 @@ class HtmlFormatter(Formatter):
|
|||
cssfilename = os.path.join(os.path.dirname(filename),
|
||||
self.cssfile)
|
||||
except AttributeError:
|
||||
print >>sys.stderr, 'Note: Cannot determine output file name, ' \
|
||||
'using current directory as base for the CSS file name'
|
||||
print('Note: Cannot determine output file name, using current directory as base for the CSS file name', file=sys.stderr)
|
||||
cssfilename = self.cssfile
|
||||
# write CSS file only if noclobber_cssfile isn't given as an option.
|
||||
try:
|
||||
|
|
|
@ -118,7 +118,7 @@ def get_lexer_for_filename(_fn, code=None, **options):
|
|||
|
||||
if matches:
|
||||
matches.sort(key=get_rating)
|
||||
#print "Possible lexers, after sort:", matches
|
||||
#print("Possible lexers, after sort:", matches)
|
||||
return matches[-1][0](**options)
|
||||
raise ClassNotFound('no lexer for filename %r found' % _fn)
|
||||
|
||||
|
|
|
@ -233,13 +233,13 @@ if __name__ == '__main__':
|
|||
|
||||
def run():
|
||||
version = get_newest_version()
|
||||
print '> Downloading function index for Lua %s' % version
|
||||
print('> Downloading function index for Lua %s' % version)
|
||||
functions = get_lua_functions(version)
|
||||
print '> %d functions found:' % len(functions)
|
||||
print('> %d functions found:' % len(functions))
|
||||
|
||||
modules = {}
|
||||
for full_function_name in functions:
|
||||
print '>> %s' % full_function_name
|
||||
print('>> %s' % full_function_name)
|
||||
m = get_function_module(full_function_name)
|
||||
modules.setdefault(m, []).append(full_function_name)
|
||||
|
||||
|
|
|
@ -319,7 +319,7 @@ if __name__ == '__main__':
|
|||
for filename in os.listdir('.'):
|
||||
if filename.endswith('.py') and not filename.startswith('_'):
|
||||
module_name = 'pygments.lexers.%s' % filename[:-3]
|
||||
print module_name
|
||||
print(module_name)
|
||||
module = __import__(module_name, None, None, [''])
|
||||
for lexer_name in module.__all__:
|
||||
lexer = getattr(module, lexer_name)
|
||||
|
|
|
@ -3777,10 +3777,10 @@ if __name__ == '__main__':
|
|||
f.close()
|
||||
|
||||
def run():
|
||||
print '>> Downloading Function Index'
|
||||
print('>> Downloading Function Index')
|
||||
modules = get_php_functions()
|
||||
total = sum(len(v) for v in modules.itervalues())
|
||||
print '%d functions found' % total
|
||||
print('%d functions found' % total)
|
||||
regenerate(__file__, modules)
|
||||
shutil.rmtree(PHP_MANUAL_DIR)
|
||||
|
||||
|
|
|
@ -1057,13 +1057,13 @@ if __name__ == '__main__':
|
|||
|
||||
def run():
|
||||
version = get_version()
|
||||
print '> Downloading function index for SourceMod %s' % version
|
||||
print('> Downloading function index for SourceMod %s' % version)
|
||||
functions = get_sm_functions()
|
||||
print '> %d functions found:' % len(functions)
|
||||
print('> %d functions found:' % len(functions))
|
||||
|
||||
functionlist = []
|
||||
for full_function_name in functions:
|
||||
print '>> %s' % full_function_name
|
||||
print('>> %s' % full_function_name)
|
||||
functionlist.append(full_function_name)
|
||||
|
||||
regenerate(__file__, functionlist)
|
||||
|
|
Loading…
Reference in a new issue