From 4c177fce89fee925f0f4fbfde00ce2e1252562c0 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 19 Mar 2014 12:51:48 +0100 Subject: Python 3: fix more submodules * print syntax * replace "except Exception, exc:" with "except Exception as exc:" --- paste/auth/auth_tkt.py | 8 ++++---- paste/cascade.py | 2 +- paste/debug/doctest_webapp.py | 20 ++++++++++---------- paste/debug/fsdiff.py | 4 ++-- paste/debug/testserver.py | 4 ++-- paste/debug/watchthreads.py | 4 ++-- paste/flup_session.py | 2 +- paste/registry.py | 6 +++--- paste/reloader.py | 9 +++++---- paste/request.py | 4 ++-- paste/transaction.py | 2 +- paste/util/PySourceColor.py | 2 +- paste/util/finddata.py | 11 +++++------ paste/util/looper.py | 4 ++-- paste/util/quoting.py | 4 ++-- paste/util/template.py | 8 ++++---- paste/wsgilib.py | 17 ++++++++--------- 17 files changed, 55 insertions(+), 56 deletions(-) diff --git a/paste/auth/auth_tkt.py b/paste/auth/auth_tkt.py index e960653..da8ddbd 100644 --- a/paste/auth/auth_tkt.py +++ b/paste/auth/auth_tkt.py @@ -75,10 +75,10 @@ class AuthTicket(object): token = auth_tkt.AuthTick('sharedsecret', 'username', os.environ['REMOTE_ADDR'], tokens=['admin']) - print 'Status: 200 OK' - print 'Content-type: text/html' - print token.cookie() - print + print('Status: 200 OK') + print('Content-type: text/html') + print(token.cookie()) + print("") ... redirect HTML ... Webware usage:: diff --git a/paste/cascade.py b/paste/cascade.py index 1c4acfb..424794e 100644 --- a/paste/cascade.py +++ b/paste/cascade.py @@ -123,7 +123,7 @@ class Cascade(object): list(v) # then close: v.close() - except self.catch_exceptions, e: + except self.catch_exceptions: pass if copy_wsgi_input: environ['wsgi.input'].seek(0) diff --git a/paste/debug/doctest_webapp.py b/paste/debug/doctest_webapp.py index 935b291..f399ac3 100755 --- a/paste/debug/doctest_webapp.py +++ b/paste/debug/doctest_webapp.py @@ -30,7 +30,7 @@ paste_parent = os.path.dirname( def run(command): data = run_raw(command) if data: - print data + print(data) def run_raw(command): """ @@ -56,7 +56,7 @@ def run_command(command, name, and_print=False): show_file('shell-command', name, description='shell transcript', data=data) if and_print and output: - print output + print(output) def _make_env(): env = os.environ.copy() @@ -88,7 +88,7 @@ def ls(dir=None, recurse=False, indent=0): full = os.path.join(dir, fn) if os.path.isdir(full): fn = fn + '/' - print ' '*indent + fn + print(' '*indent + fn) if os.path.isdir(full) and recurse: ls(dir=full, recurse=True, indent=indent+2) @@ -158,13 +158,13 @@ def show(path_info, example_name): expected = f.read() f.close() if not html_matches(expected, result): - print 'Pages did not match. Expected from %s:' % fn - print '-'*60 - print expected - print '='*60 - print 'Actual output:' - print '-'*60 - print result + print('Pages did not match. Expected from %s:' % fn) + print('-'*60) + print(expected) + print('='*60) + print('Actual output:') + print('-'*60) + print(result) def html_matches(pattern, text): regex = re.escape(pattern) diff --git a/paste/debug/fsdiff.py b/paste/debug/fsdiff.py index f680bf6..156a2e4 100644 --- a/paste/debug/fsdiff.py +++ b/paste/debug/fsdiff.py @@ -263,8 +263,8 @@ class File(object): __tracebackhide__ = True bytes = self.bytes if s not in bytes: - print 'Could not find %r in:' % s - print bytes + print('Could not find %r in:' % s) + print(bytes) assert s in bytes def __repr__(self): diff --git a/paste/debug/testserver.py b/paste/debug/testserver.py index 0adeefc..4817161 100755 --- a/paste/debug/testserver.py +++ b/paste/debug/testserver.py @@ -47,7 +47,7 @@ class WSGIRegressionServer(WSGIServer): if now > self.expires and self.timeout: # note regression test doesn't handle exceptions in # threads very well; so we just print and exit - print "\nWARNING: WSGIRegressionServer timeout exceeded\n" + print("\nWARNING: WSGIRegressionServer timeout exceeded\n") break if self.pending: self.handle_request() @@ -62,7 +62,7 @@ class WSGIRegressionServer(WSGIServer): def serve(application, host=None, port=None, handler=None): server = WSGIRegressionServer(application, host, port, handler) - print "serving on %s:%s" % server.server_address + print("serving on %s:%s" % server.server_address) server.serve_forever() return server diff --git a/paste/debug/watchthreads.py b/paste/debug/watchthreads.py index 1048213..c877942 100644 --- a/paste/debug/watchthreads.py +++ b/paste/debug/watchthreads.py @@ -290,7 +290,7 @@ def format_environ(environ): environ_template.substitute( key=cgi.escape(str(key)), value=cgi.escape(str(value)))) - except Exception, e: + except Exception as e: environ_rows.append( environ_template.substitute( key=cgi.escape(str(key)), @@ -339,7 +339,7 @@ def make_bad_app(global_conf, pause=0): else: count = 0 while 1: - print "I'm alive %s (%s)" % (count, thread.get_ident()) + print("I'm alive %s (%s)" % (count, thread.get_ident())) time.sleep(10) count += 1 start_response('200 OK', [('content-type', 'text/plain')]) diff --git a/paste/flup_session.py b/paste/flup_session.py index b230ab8..6903c6f 100644 --- a/paste/flup_session.py +++ b/paste/flup_session.py @@ -81,7 +81,7 @@ class SessionMiddleware(object): try: app_iter = self.application(environ, cookie_start_response) - except httpexceptions.HTTPException, e: + except httpexceptions.HTTPException as e: headers = (e.headers or {}).items() service.addCookie(headers) e.headers = dict(headers) diff --git a/paste/registry.py b/paste/registry.py index 61a5d13..1148632 100644 --- a/paste/registry.py +++ b/paste/registry.py @@ -378,11 +378,11 @@ class RegistryManager(object): try: app_iter = self.application(environ, start_response) - #print "REG ", type(app_iter) + #print("REG ", type(app_iter)) if isinstance(app_iter, (list, tuple)): - #print "DIRECT" + #print("DIRECT") return app_iter - #print "STREAMING" + #print("STREAMING") return self.streaming_iter(app_iter, reg, environ) except Exception as e: diff --git a/paste/reloader.py b/paste/reloader.py index a0e3850..29b1891 100644 --- a/paste/reloader.py +++ b/paste/reloader.py @@ -40,6 +40,7 @@ Then every time the reloader polls files it will call ``watch_config_files`` and check all the filenames it returns. """ +from __future__ import print_function import os import sys import time @@ -93,12 +94,13 @@ class Monitor(object): try: filenames.extend(file_callback()) except: - print >> sys.stderr, "Error calling paste.reloader callback %r:" % file_callback + print("Error calling paste.reloader callback %r:" % file_callback, + file=sys.stderr) traceback.print_exc() for module in sys.modules.values(): try: filename = module.__file__ - except (AttributeError, ImportError), exc: + except (AttributeError, ImportError) as exc: continue if filename is not None: filenames.append(filename) @@ -119,8 +121,7 @@ class Monitor(object): if not self.module_mtimes.has_key(filename): self.module_mtimes[filename] = mtime elif self.module_mtimes[filename] < mtime: - print >> sys.stderr, ( - "%s changed; reloading..." % filename) + print("%s changed; reloading..." % filename, file=sys.stderr) return False return True diff --git a/paste/request.py b/paste/request.py index 71eca30..28b1f67 100644 --- a/paste/request.py +++ b/paste/request.py @@ -295,8 +295,8 @@ def path_info_pop(environ): >>> def call_it(script_name, path_info): ... env = {'SCRIPT_NAME': script_name, 'PATH_INFO': path_info} ... result = path_info_pop(env) - ... print 'SCRIPT_NAME=%r; PATH_INFO=%r; returns=%r' % ( - ... env['SCRIPT_NAME'], env['PATH_INFO'], result) + ... print('SCRIPT_NAME=%r; PATH_INFO=%r; returns=%r' % ( + ... env['SCRIPT_NAME'], env['PATH_INFO'], result)) >>> call_it('/foo', '/bar') SCRIPT_NAME='/foo/bar'; PATH_INFO=''; returns='bar' >>> call_it('/foo/bar', '') diff --git a/paste/transaction.py b/paste/transaction.py index a283067..1347acd 100644 --- a/paste/transaction.py +++ b/paste/transaction.py @@ -116,5 +116,5 @@ if '__main__' == __name__ and False: curr = conn.cursor() curr.execute("SELECT now(), %s" % conn.quote("B'n\\'gles")) (time, bing) = curr.fetchone() - print bing, time + print(bing, time) diff --git a/paste/util/PySourceColor.py b/paste/util/PySourceColor.py index 35efc7f..1c11041 100644 --- a/paste/util/PySourceColor.py +++ b/paste/util/PySourceColor.py @@ -832,7 +832,7 @@ def _test(show=0, quiet=0): @A @B(arghh) @C def LlamaSaysNi(arg='Ni!',arg2="RALPH"): """This docstring is deeply disturbed by all the llama references""" - print '%s The Wonder Llama says %s'% (arg2,arg) + print('%s The Wonder Llama says %s'% (arg2,arg)) # So I was like duh!, and he was like ya know?!, # and so we were both like huh...wtf!? RTFM!! LOL!!;) @staticmethod## Double comments are KewL. diff --git a/paste/util/finddata.py b/paste/util/finddata.py index af29c04..05c8546 100644 --- a/paste/util/finddata.py +++ b/paste/util/finddata.py @@ -4,6 +4,7 @@ # you can't import this from another package, when you don't know if # that package is installed yet. +from __future__ import print_function import os import sys from fnmatch import fnmatchcase @@ -61,9 +62,8 @@ def find_package_data( or fn.lower() == pattern.lower()): bad_name = True if show_ignored: - print >> sys.stderr, ( - "Directory %s ignored by pattern %s" - % (fn, pattern)) + print("Directory %s ignored by pattern %s" + % (fn, pattern), file=sys.stderr) break if bad_name: continue @@ -84,9 +84,8 @@ def find_package_data( or fn.lower() == pattern.lower()): bad_name = True if show_ignored: - print >> sys.stderr, ( - "File %s ignored by pattern %s" - % (fn, pattern)) + print("File %s ignored by pattern %s" + % (fn, pattern), file=sys.stderr) break if bad_name: continue diff --git a/paste/util/looper.py b/paste/util/looper.py index 8116323..efe7fdf 100644 --- a/paste/util/looper.py +++ b/paste/util/looper.py @@ -7,9 +7,9 @@ These can be awkward to manage in a normal Python loop, but using the looper you can get a better sense of the context. Use like:: >>> for loop, item in looper(['a', 'b', 'c']): - ... print loop.number, item + ... print(loop.number, item) ... if not loop.last: - ... print '---' + ... print('---') 1 a --- 2 b diff --git a/paste/util/quoting.py b/paste/util/quoting.py index 8c578ee..8c4c749 100644 --- a/paste/util/quoting.py +++ b/paste/util/quoting.py @@ -87,8 +87,8 @@ def comment_quote(s): """ comment = str(s) #comment = _bad_chars_re.sub('', comment) - #print 'in ', repr(str(s)) - #print 'out', repr(comment) + #print('in ', repr(str(s))) + #print('out', repr(comment)) comment = _comment_quote_re.sub('->', comment) return comment diff --git a/paste/util/template.py b/paste/util/template.py index cdf503a..afeb353 100644 --- a/paste/util/template.py +++ b/paste/util/template.py @@ -213,7 +213,7 @@ class Template(object): def _exec(self, code, ns, pos): __traceback_hide__ = True try: - exec code in ns + six.exec_(code, ns) except: exc_info = sys.exc_info() e = exc_info[1] @@ -715,8 +715,8 @@ def fill_command(args=None): help="Put the environment in as top-level variables") options, args = parser.parse_args(args) if len(args) < 1: - print 'You must give a template filename' - print dir(parser) + print('You must give a template filename') + print(dir(parser)) assert 0 template_name = args[0] args = args[1:] @@ -725,7 +725,7 @@ def fill_command(args=None): vars.update(os.environ) for value in args: if '=' not in value: - print 'Bad argument: %r' % value + print('Bad argument: %r' % value) sys.exit(2) name, value = value.split('=', 1) if name.startswith('py:'): diff --git a/paste/wsgilib.py b/paste/wsgilib.py index 879a43e..1234ef9 100644 --- a/paste/wsgilib.py +++ b/paste/wsgilib.py @@ -5,6 +5,8 @@ A module of many disparate routines. """ +from __future__ import print_function + # functions which moved to paste.request and paste.response # Deprecated around 15 Dec 2005 from paste.request import get_cookies, parse_querystring, parse_formvars @@ -53,10 +55,9 @@ class add_close(object): def __del__(self): if not self._closed: # We can't raise an error or anything at this stage - print >> sys.stderr, ( - "Error: app_iter.close() was not called when finishing " + print("Error: app_iter.close() was not called when finishing " "WSGI request. finalization function %s not called" - % self.close_func) + % self.close_func, file=sys.stderr) class add_start_close(object): """ @@ -92,10 +93,9 @@ class add_start_close(object): def __del__(self): if not self._closed: # We can't raise an error or anything at this stage - print >> sys.stderr, ( - "Error: app_iter.close() was not called when finishing " + print("Error: app_iter.close() was not called when finishing " "WSGI request. finalization function %s not called" - % self.close_func) + % self.close_func, file=sys.stderr) class chained_app_iters(object): @@ -137,10 +137,9 @@ class chained_app_iters(object): def __del__(self): if not self._closed: # We can't raise an error or anything at this stage - print >> sys.stderr, ( - "Error: app_iter.close() was not called when finishing " + print("Error: app_iter.close() was not called when finishing " "WSGI request. finalization function %s not called" - % self.close_func) + % self.close_func, file=sys.stderr) class encode_unicode_app_iter(object): """ -- cgit v1.2.1