diff options
author | Cyril Roelandt <cyril.roelandt@enovance.com> | 2014-03-18 12:49:27 +0100 |
---|---|---|
committer | Cyril Roelandt <cyril.roelandt@enovance.com> | 2014-03-18 12:49:27 +0100 |
commit | 9789a96ca9aab44bd71fdcfc5c0bed1ef7cf0838 (patch) | |
tree | 543718d130e12237d431dc61a3ce62769ff1c312 | |
parent | 4bdb495a250dc8b44309a8d158fb60a8106e3287 (diff) | |
download | paste-9789a96ca9aab44bd71fdcfc5c0bed1ef7cf0838.tar.gz |
Python 3: add parenthesis to print() to support Python 2 and Python 3
Use also "from __future__ import print_function".
-rwxr-xr-x | paste/debug/debugapp.py | 4 | ||||
-rw-r--r-- | paste/evalexception/middleware.py | 3 | ||||
-rw-r--r-- | paste/fixture.py | 30 | ||||
-rw-r--r-- | paste/util/PySourceColor.py | 4 | ||||
-rw-r--r-- | paste/util/intset.py | 38 | ||||
-rw-r--r-- | paste/util/ip4.py | 12 | ||||
-rw-r--r-- | tests/test_cgitb_catcher.py | 8 | ||||
-rw-r--r-- | tests/test_config.py | 2 | ||||
-rw-r--r-- | tests/test_errordocument.py | 2 | ||||
-rw-r--r-- | tests/test_exceptions/test_formatter.py | 10 | ||||
-rw-r--r-- | tests/test_exceptions/test_httpexceptions.py | 4 | ||||
-rw-r--r-- | tests/test_exceptions/test_reporter.py | 2 | ||||
-rw-r--r-- | tests/test_fileapp.py | 2 | ||||
-rw-r--r-- | tests/test_registry.py | 2 | ||||
-rw-r--r-- | tests/test_urlparser.py | 2 |
15 files changed, 65 insertions, 60 deletions
diff --git a/paste/debug/debugapp.py b/paste/debug/debugapp.py index 190cbdd..8c7c7c2 100755 --- a/paste/debug/debugapp.py +++ b/paste/debug/debugapp.py @@ -41,7 +41,7 @@ class SlowConsumer(object): remaining = int(total) while remaining > 0: if self.progress: - print "%s of %s remaining" % (remaining, total) + print("%s of %s remaining" % (remaining, total)) if remaining > 4096: chunk = environ['wsgi.input'].read(4096) else: @@ -59,7 +59,7 @@ class SlowConsumer(object): '<input type="file" name="file">\n' '<input type="submit" >\n' '</form></body></html>\n') - print "bingles" + print("bingles") start_response("200 OK", [('Content-Type', 'text/html'), ('Content-Length', len(body))]) return [body] diff --git a/paste/evalexception/middleware.py b/paste/evalexception/middleware.py index 455758a..d577003 100644 --- a/paste/evalexception/middleware.py +++ b/paste/evalexception/middleware.py @@ -24,6 +24,9 @@ can look for the header X-Debug-URL in your 500 responses if you want to see the full debuggable traceback. Also, this URL is printed to ``wsgi.errors``, so you can open it up in another browser window. """ + +from __future__ import print_function + import sys import os import cgi diff --git a/paste/fixture.py b/paste/fixture.py index f3140ec..7a684e5 100644 --- a/paste/fixture.py +++ b/paste/fixture.py @@ -9,6 +9,8 @@ for testing WSGI applications, and the `TestFileEnvironment effects of command-line scripts. """ +from __future__ import print_function + import sys import random import mimetypes @@ -687,7 +689,7 @@ class TestResponse(object): def printlog(s): if verbose: - print s + print(s) found_links = [] total_links = 0 @@ -821,14 +823,14 @@ class TestResponse(object): "The only keyword argument allowed is 'no'") for s in strings: if not s in self: - print >> sys.stderr, "Actual response (no %r):" % s - print >> sys.stderr, self + print("Actual response (no %r):" % s, file=sys.stderr) + print(self, file=sys.stderr) raise IndexError( "Body does not contain string %r" % s) for no_s in no: if no_s in self: - print >> sys.stderr, "Actual response (has %r)" % no_s - print >> sys.stderr, self + print("Actual response (has %r)" % no_s, file=sys.stderr) + print(self, file=sys.stderr) raise IndexError( "Body contains string %r" % s) @@ -1409,8 +1411,8 @@ class TestFileEnvironment(object): files_before=files_before, files_after=files_after) if printresult: - print result - print '-'*40 + print(result) + print('-'*40) if not expect_error: result.assert_no_error() if not expect_stderr: @@ -1536,8 +1538,8 @@ class ProcResult(object): def assert_no_stderr(self): __tracebackhide__ = True if self.stderr: - print 'Error output:' - print self.stderr + print('Error output:') + print(self.stderr) raise AssertionError("stderr output not expected") def __str__(self): @@ -1617,11 +1619,11 @@ class FoundFile(object): def mustcontain(self, s): __tracebackhide__ = True - bytes = self.bytes - if s not in bytes: - print 'Could not find %r in:' % s - print bytes - assert s in bytes + bytes_ = self.bytes + if s not in bytes_: + print('Could not find %r in:' % s) + print(bytes_) + assert s in bytes_ def __repr__(self): return '<%s %s:%s>' % ( diff --git a/paste/util/PySourceColor.py b/paste/util/PySourceColor.py index 9de5b84..c2a9363 100644 --- a/paste/util/PySourceColor.py +++ b/paste/util/PySourceColor.py @@ -664,7 +664,7 @@ def Usage(): python PySourceColor.py -i- -o c:/pydoc.py.html -s < c:/Python22/my.py
_____________________________________________________________________________
"""
- print doc % (__version__)
+ print(doc % (__version__))
sys.exit(1)
###################################################### Command line interface
@@ -1172,7 +1172,7 @@ def showpage(path): def _printinfo(message, quiet):
"""Helper to print messages"""
if not quiet:
- print message
+ print(message)
def escape(text):
"""escape text for html. similar to cgi.escape"""
diff --git a/paste/util/intset.py b/paste/util/intset.py index 3873c75..7c7e331 100644 --- a/paste/util/intset.py +++ b/paste/util/intset.py @@ -489,23 +489,23 @@ if __name__ == "__main__": x = IntSet((10,20),30) y = IntSet((10,20)) z = IntSet((10,20),30,(15,19),min=0,max=40) - print x - print x&110 - print x|110 - print x^(15,25) - print x-12 - print 12 in x - print x.issubset(x) - print y.issubset(x) - print x.istruesubset(x) - print y.istruesubset(x) + print(x) + print(x&110) + print(x|110) + print(x^(15,25)) + print(x-12) + print(12 in x) + print(x.issubset(x)) + print(y.issubset(x)) + print(x.istruesubset(x)) + print(y.istruesubset(x)) for val in x: - print val - print x.inverse() - print x == z - print x == y - print x <> y - print hash(x) - print hash(z) - print len(x) - print x.len() + print(val) + print(x.inverse()) + print(x == z) + print(x == y) + print(x != y) + print(hash(x)) + print(hash(z)) + print(len(x)) + print(x.len()) diff --git a/paste/util/ip4.py b/paste/util/ip4.py index b0dfde8..acff6ab 100644 --- a/paste/util/ip4.py +++ b/paste/util/ip4.py @@ -260,14 +260,14 @@ if __name__ == "__main__": # Little test script. x = IP4Range("172.22.162.250/24") y = IP4Range("172.22.162.250","172.22.163.250","172.22.163.253<->255") - print x + print(x) for val in x.itermasks(): - print val + print(val) for val in y.itermasks(): - print val + print(val) for val in (x|y).itermasks(): - print val + print(val) for val in (x^y).iterranges(): - print val + print(val) for val in x: - print val + print(val) diff --git a/tests/test_cgitb_catcher.py b/tests/test_cgitb_catcher.py index 2b80d28..80d052e 100644 --- a/tests/test_cgitb_catcher.py +++ b/tests/test_cgitb_catcher.py @@ -45,7 +45,7 @@ def yielder(args): def test_makes_exception(): res = do_request(bad_app) - print res + print(res) assert 'bad_app() takes no arguments (2 given' in res assert 'iterator = application(environ, start_response_wrapper)' in res assert 'lint.py' in res @@ -53,20 +53,20 @@ def test_makes_exception(): def test_start_res(): res = do_request(start_response_app) - print res + print(res) assert 'ValueError: hi' in res assert 'test_cgitb_catcher.py' in res assert 'line 26, in start_response_app' in res def test_after_start(): res = do_request(after_start_response_app, 200) - print res + print(res) assert 'ValueError: error2' in res assert 'line 30' in res def test_iter_app(): res = do_request(iter_app, 200) - print res + print(res) assert 'None raises error' in res assert 'yielder' in res diff --git a/tests/test_config.py b/tests/test_config.py index 882f82c..ea6be75 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -40,7 +40,7 @@ def test_request_config_multi(): assert 'Variable is: test value' in res assert 'Variable is (in environ): test value' in res assert 'Nesting variable is: nesting value' in res - print res + print(res) assert 'Nesting variable is (in environ): nesting value' in res def test_process_config(request_app=test_request_config): diff --git a/tests/test_errordocument.py b/tests/test_errordocument.py index 24f3022..c284b93 100644 --- a/tests/test_errordocument.py +++ b/tests/test_errordocument.py @@ -89,4 +89,4 @@ def test_bad_error(): app = forward(app, {404: '/404.html'}) app = TestApp(app) resp = app.get('/test', expect_errors=True) - print resp + print(resp) diff --git a/tests/test_exceptions/test_formatter.py b/tests/test_exceptions/test_formatter.py index 2fe4528..3d5bdad 100644 --- a/tests/test_exceptions/test_formatter.py +++ b/tests/test_exceptions/test_formatter.py @@ -74,7 +74,7 @@ def test_content(): raise_error() except: result = format(f) - print result + print(result) assert 'test_object' in result assert 'http://whatever.com' in result assert 'This is some supplemental information' in result @@ -103,7 +103,7 @@ def test_hide(): hide(True, raise_error) except: result = format(f) - print result + print(result) assert 'in hide_inner' not in result assert 'inner(*args, **kw)' not in result else: @@ -112,7 +112,7 @@ def test_hide(): def print_diff(s1, s2): differ = difflib.Differ() result = list(differ.compare(s1.splitlines(), s2.splitlines())) - print '\n'.join(result) + print('\n'.join(result)) def test_hide_supppressed(): """ @@ -153,7 +153,7 @@ def test_hide_after(): raise_error) except: result = format(f) - print strip_html(result).encode('ascii', 'replace') + print(strip_html(result).encode('ascii', 'replace')) assert 'AABB' in result assert 'CCDD' not in result assert 'raise_error' in result @@ -169,7 +169,7 @@ def test_hide_before(): raise_error) except: result = format(f) - print result + print(result) assert 'AABB' not in result assert 'raise_error' in result else: diff --git a/tests/test_exceptions/test_httpexceptions.py b/tests/test_exceptions/test_httpexceptions.py index c833eae..08e23d4 100644 --- a/tests/test_exceptions/test_httpexceptions.py +++ b/tests/test_exceptions/test_httpexceptions.py @@ -72,10 +72,10 @@ def test_redapp(): assert "text/html" == header_value(saved[0][1], 'content-type') assert "/bing/foo" == header_value(saved[0][1],'location') result = list(app({'HTTP_ACCEPT': 'text/plain'},saveit)) - print result[0] == ( + print(result[0] == ( '302 Found\n' 'This resource was found at /bing/foo;\n' - 'you should be redirected automatically.\n') + 'you should be redirected automatically.\n')) assert "text/plain; charset=utf8" == header_value(saved[1][1],'content-type') assert "/bing/foo" == header_value(saved[1][1],'location') diff --git a/tests/test_exceptions/test_reporter.py b/tests/test_exceptions/test_reporter.py index 8f4dc7a..a40666e 100644 --- a/tests/test_exceptions/test_reporter.py +++ b/tests/test_exceptions/test_reporter.py @@ -44,7 +44,7 @@ def test_logger(): assert 0 rep.report(exc_data) content = open(fn).read() - print content + print(content) assert len(content.splitlines()) == 8 assert 'ZeroDivisionError' in content diff --git a/tests/test_fileapp.py b/tests/test_fileapp.py index c0013fb..d5b2a95 100644 --- a/tests/test_fileapp.py +++ b/tests/test_fileapp.py @@ -106,7 +106,7 @@ def test_file(): assert content == res.body assert content == app.content # this is cashed lastmod = res.header('last-modified') - print "updating", tempfile + print("updating", tempfile) file = open(tempfile,"a+") file.write("0123456789") file.close() diff --git a/tests/test_registry.py b/tests/test_registry.py index 7af953f..dfece6a 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -109,7 +109,7 @@ def test_registry_no_object_error(): def test_with_default_object(): app = TestApp(simpleapp_withregistry_default) res = app.get('/') - print res + print(res) assert 'Hello world' in res assert "Value is {'hi': 'people'}" in res diff --git a/tests/test_urlparser.py b/tests/test_urlparser.py index f8c8b9f..d1f3377 100644 --- a/tests/test_urlparser.py +++ b/tests/test_urlparser.py @@ -58,7 +58,7 @@ def test_deep(): assert 'index2' in res res = app.get('/sub') assert res.status == 301 - print res + print(res) assert res.header('location') == 'http://localhost/sub/' assert 'http://localhost/sub/' in res res = app.get('/sub/') |