fixed print statements for python3

This commit is contained in:
Alan Hamlett 2013-09-22 14:29:16 -07:00
parent bdaf07d941
commit ffdee6b48c
8 changed files with 61 additions and 63 deletions

View file

@ -119,25 +119,25 @@ def _print_help(what, name):
try: try:
if what == 'lexer': if what == 'lexer':
cls = find_lexer_class(name) cls = find_lexer_class(name)
print "Help on the %s lexer:" % cls.name print("Help on the %s lexer:" % cls.name)
print dedent(cls.__doc__) print(dedent(cls.__doc__))
elif what == 'formatter': elif what == 'formatter':
cls = find_formatter_class(name) cls = find_formatter_class(name)
print "Help on the %s formatter:" % cls.name print("Help on the %s formatter:" % cls.name)
print dedent(cls.__doc__) print(dedent(cls.__doc__))
elif what == 'filter': elif what == 'filter':
cls = find_filter_class(name) cls = find_filter_class(name)
print "Help on the %s filter:" % name print("Help on the %s filter:" % name)
print dedent(cls.__doc__) print(dedent(cls.__doc__))
except AttributeError: except AttributeError:
print >>sys.stderr, "%s not found!" % what print("%s not found!" % what, file=sys.stderr)
def _print_list(what): def _print_list(what):
if what == 'lexer': if what == 'lexer':
print print
print "Lexers:" print("Lexers:")
print "~~~~~~~" print("~~~~~~~")
info = [] info = []
for fullname, names, exts, _ in get_all_lexers(): for fullname, names, exts, _ in get_all_lexers():
@ -146,12 +146,12 @@ def _print_list(what):
info.append(tup) info.append(tup)
info.sort() info.sort()
for i in info: for i in info:
print ('* %s\n %s %s') % i print(('* %s\n %s %s') % i)
elif what == 'formatter': elif what == 'formatter':
print print
print "Formatters:" print("Formatters:")
print "~~~~~~~~~~~" print("~~~~~~~~~~~")
info = [] info = []
for cls in get_all_formatters(): for cls in get_all_formatters():
@ -161,27 +161,27 @@ def _print_list(what):
info.append(tup) info.append(tup)
info.sort() info.sort()
for i in info: for i in info:
print ('* %s\n %s %s') % i print(('* %s\n %s %s') % i)
elif what == 'filter': elif what == 'filter':
print print
print "Filters:" print("Filters:")
print "~~~~~~~~" print("~~~~~~~~")
for name in get_all_filters(): for name in get_all_filters():
cls = find_filter_class(name) cls = find_filter_class(name)
print "* " + name + ':' print("* " + name + ':')
print " %s" % docstring_headline(cls) print(" %s" % docstring_headline(cls))
elif what == 'style': elif what == 'style':
print print
print "Styles:" print("Styles:")
print "~~~~~~~" print("~~~~~~~")
for name in get_all_styles(): for name in get_all_styles():
cls = get_style_by_name(name) cls = get_style_by_name(name)
print "* " + name + ':' print("* " + name + ':')
print " %s" % docstring_headline(cls) print(" %s" % docstring_headline(cls))
def main(args=sys.argv): def main(args=sys.argv):
@ -203,7 +203,7 @@ def main(args=sys.argv):
try: try:
popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:hVHg") popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:hVHg")
except getopt.GetoptError as err: except getopt.GetoptError as err:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
opts = {} opts = {}
O_opts = [] O_opts = []
@ -219,25 +219,25 @@ def main(args=sys.argv):
opts[opt] = arg opts[opt] = arg
if not opts and not args: if not opts and not args:
print usage print(usage)
return 0 return 0
if opts.pop('-h', None) is not None: if opts.pop('-h', None) is not None:
print usage print(usage)
return 0 return 0
if opts.pop('-V', None) is not None: 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 return 0
# handle ``pygmentize -L`` # handle ``pygmentize -L``
L_opt = opts.pop('-L', None) L_opt = opts.pop('-L', None)
if L_opt is not None: if L_opt is not None:
if opts: if opts:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
# print version # print(version)
main(['', '-V']) main(['', '-V'])
if not args: if not args:
args = ['lexer', 'formatter', 'filter', 'style'] args = ['lexer', 'formatter', 'filter', 'style']
@ -249,12 +249,12 @@ def main(args=sys.argv):
H_opt = opts.pop('-H', None) H_opt = opts.pop('-H', None)
if H_opt is not None: if H_opt is not None:
if opts or len(args) != 2: if opts or len(args) != 2:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
what, name = args what, name = args
if what not in ('lexer', 'formatter', 'filter'): if what not in ('lexer', 'formatter', 'filter'):
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
_print_help(what, name) _print_help(what, name)
@ -282,10 +282,10 @@ def main(args=sys.argv):
except ClassNotFound as err: except ClassNotFound as err:
lexer = TextLexer() lexer = TextLexer()
except OptionError as err: except OptionError as err:
print >>sys.stderr, 'Error:', err print('Error:', err, file=sys.stderr)
return 1 return 1
print lexer.aliases[0] print(lexer.aliases[0])
return 0 return 0
# handle ``pygmentize -S`` # handle ``pygmentize -S``
@ -294,30 +294,30 @@ def main(args=sys.argv):
if S_opt is not None: if S_opt is not None:
f_opt = opts.pop('-f', None) f_opt = opts.pop('-f', None)
if not f_opt: if not f_opt:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
if opts or args: if opts or args:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
try: try:
parsed_opts['style'] = S_opt parsed_opts['style'] = S_opt
fmter = get_formatter_by_name(f_opt, **parsed_opts) fmter = get_formatter_by_name(f_opt, **parsed_opts)
except ClassNotFound as err: except ClassNotFound as err:
print >>sys.stderr, err print(err, file=sys.stderr)
return 1 return 1
arg = a_opt or '' arg = a_opt or ''
try: try:
print fmter.get_style_defs(arg) print(fmter.get_style_defs(arg))
except Exception as err: except Exception as err:
print >>sys.stderr, 'Error:', err print('Error:', err, file=sys.stderr)
return 1 return 1
return 0 return 0
# if no -S is given, -a is not allowed # if no -S is given, -a is not allowed
if a_opt is not None: if a_opt is not None:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
# parse -F options # parse -F options
@ -331,7 +331,7 @@ def main(args=sys.argv):
try: try:
fmter = get_formatter_by_name(fmter, **parsed_opts) fmter = get_formatter_by_name(fmter, **parsed_opts)
except (OptionError, ClassNotFound) as err: except (OptionError, ClassNotFound) as err:
print >>sys.stderr, 'Error:', err print('Error:', err, file=sys.stderr)
return 1 return 1
if outfn: if outfn:
@ -339,12 +339,12 @@ def main(args=sys.argv):
try: try:
fmter = get_formatter_for_filename(outfn, **parsed_opts) fmter = get_formatter_for_filename(outfn, **parsed_opts)
except (OptionError, ClassNotFound) as err: except (OptionError, ClassNotFound) as err:
print >>sys.stderr, 'Error:', err print('Error:', err, file=sys.stderr)
return 1 return 1
try: try:
outfile = open(outfn, 'wb') outfile = open(outfn, 'wb')
except Exception as err: except Exception as err:
print >>sys.stderr, 'Error: cannot open outfile:', err print('Error: cannot open outfile:', err, file=sys.stderr)
return 1 return 1
else: else:
if not fmter: if not fmter:
@ -357,19 +357,19 @@ def main(args=sys.argv):
try: try:
lexer = get_lexer_by_name(lexer, **parsed_opts) lexer = get_lexer_by_name(lexer, **parsed_opts)
except (OptionError, ClassNotFound) as err: except (OptionError, ClassNotFound) as err:
print >>sys.stderr, 'Error:', err print('Error:', err, file=sys.stderr)
return 1 return 1
if args: if args:
if len(args) > 1: if len(args) > 1:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
infn = args[0] infn = args[0]
try: try:
code = open(infn, 'rb').read() code = open(infn, 'rb').read()
except Exception as err: except Exception as err:
print >>sys.stderr, 'Error: cannot read infile:', err print('Error: cannot read infile:', err, file=sys.stderr)
return 1 return 1
if not lexer: if not lexer:
@ -382,10 +382,10 @@ def main(args=sys.argv):
except ClassNotFound: except ClassNotFound:
lexer = TextLexer(**parsed_opts) lexer = TextLexer(**parsed_opts)
else: else:
print >>sys.stderr, 'Error:', err print('Error:', err, file=sys.stderr)
return 1 return 1
except OptionError as err: except OptionError as err:
print >>sys.stderr, 'Error:', err print('Error:', err, file=sys.stderr)
return 1 return 1
else: else:
@ -396,8 +396,7 @@ def main(args=sys.argv):
except ClassNotFound: except ClassNotFound:
lexer = TextLexer(**parsed_opts) lexer = TextLexer(**parsed_opts)
elif not lexer: elif not lexer:
print >>sys.stderr, 'Error: no lexer name given and reading ' + \ print('Error: no lexer name given and reading from stdin (try using -g or -l <lexer>)', file=sys.stderr)
'from stdin (try using -g or -l <lexer>)'
return 2 return 2
else: else:
code = sys.stdin.read() code = sys.stdin.read()
@ -433,9 +432,9 @@ def main(args=sys.argv):
if len(info) >= 3: if len(info) >= 3:
# extract relevant file and position info # extract relevant file and position info
msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:] msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:]
print >>sys.stderr print('', file=sys.stderr)
print >>sys.stderr, '*** Error while highlighting:' print('*** Error while highlighting:', file=sys.stderr)
print >>sys.stderr, msg print(msg, file=sys.stderr)
return 1 return 1
return 0 return 0

View file

@ -57,7 +57,7 @@ if __name__ == '__main__':
for filename in os.listdir('.'): for filename in os.listdir('.'):
if filename.endswith('.py') and not filename.startswith('_'): if filename.endswith('.py') and not filename.startswith('_'):
module_name = 'pygments.formatters.%s' % filename[:-3] module_name = 'pygments.formatters.%s' % filename[:-3]
print module_name print(module_name)
module = __import__(module_name, None, None, ['']) module = __import__(module_name, None, None, [''])
for formatter_name in module.__all__: for formatter_name in module.__all__:
imports.append((module_name, formatter_name)) imports.append((module_name, formatter_name))

View file

@ -505,8 +505,7 @@ class HtmlFormatter(Formatter):
cssfilename = os.path.join(os.path.dirname(filename), cssfilename = os.path.join(os.path.dirname(filename),
self.cssfile) self.cssfile)
except AttributeError: except AttributeError:
print >>sys.stderr, 'Note: Cannot determine output file name, ' \ print('Note: Cannot determine output file name, using current directory as base for the CSS file name', file=sys.stderr)
'using current directory as base for the CSS file name'
cssfilename = self.cssfile cssfilename = self.cssfile
# write CSS file only if noclobber_cssfile isn't given as an option. # write CSS file only if noclobber_cssfile isn't given as an option.
try: try:

View file

@ -118,7 +118,7 @@ def get_lexer_for_filename(_fn, code=None, **options):
if matches: if matches:
matches.sort(key=get_rating) matches.sort(key=get_rating)
#print "Possible lexers, after sort:", matches #print("Possible lexers, after sort:", matches)
return matches[-1][0](**options) return matches[-1][0](**options)
raise ClassNotFound('no lexer for filename %r found' % _fn) raise ClassNotFound('no lexer for filename %r found' % _fn)

View file

@ -233,13 +233,13 @@ if __name__ == '__main__':
def run(): def run():
version = get_newest_version() 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) functions = get_lua_functions(version)
print '> %d functions found:' % len(functions) print('> %d functions found:' % len(functions))
modules = {} modules = {}
for full_function_name in functions: for full_function_name in functions:
print '>> %s' % full_function_name print('>> %s' % full_function_name)
m = get_function_module(full_function_name) m = get_function_module(full_function_name)
modules.setdefault(m, []).append(full_function_name) modules.setdefault(m, []).append(full_function_name)

View file

@ -319,7 +319,7 @@ if __name__ == '__main__':
for filename in os.listdir('.'): for filename in os.listdir('.'):
if filename.endswith('.py') and not filename.startswith('_'): if filename.endswith('.py') and not filename.startswith('_'):
module_name = 'pygments.lexers.%s' % filename[:-3] module_name = 'pygments.lexers.%s' % filename[:-3]
print module_name print(module_name)
module = __import__(module_name, None, None, ['']) module = __import__(module_name, None, None, [''])
for lexer_name in module.__all__: for lexer_name in module.__all__:
lexer = getattr(module, lexer_name) lexer = getattr(module, lexer_name)

View file

@ -3777,10 +3777,10 @@ if __name__ == '__main__':
f.close() f.close()
def run(): def run():
print '>> Downloading Function Index' print('>> Downloading Function Index')
modules = get_php_functions() modules = get_php_functions()
total = sum(len(v) for v in modules.itervalues()) total = sum(len(v) for v in modules.itervalues())
print '%d functions found' % total print('%d functions found' % total)
regenerate(__file__, modules) regenerate(__file__, modules)
shutil.rmtree(PHP_MANUAL_DIR) shutil.rmtree(PHP_MANUAL_DIR)

View file

@ -1057,13 +1057,13 @@ if __name__ == '__main__':
def run(): def run():
version = get_version() version = get_version()
print '> Downloading function index for SourceMod %s' % version print('> Downloading function index for SourceMod %s' % version)
functions = get_sm_functions() functions = get_sm_functions()
print '> %d functions found:' % len(functions) print('> %d functions found:' % len(functions))
functionlist = [] functionlist = []
for full_function_name in functions: for full_function_name in functions:
print '>> %s' % full_function_name print('>> %s' % full_function_name)
functionlist.append(full_function_name) functionlist.append(full_function_name)
regenerate(__file__, functionlist) regenerate(__file__, functionlist)