diff options
32 files changed, 161 insertions, 173 deletions
diff --git a/cherrypy/__init__.py b/cherrypy/__init__.py index 710a6588..1f887d53 100644 --- a/cherrypy/__init__.py +++ b/cherrypy/__init__.py @@ -550,7 +550,6 @@ def url(path="", qs="", script_name=None, base=None, relative=None): return newurl -from cherrypy.py3util import py3print # import _cpconfig last so it can reference other top-level objects from cherrypy import _cpconfig diff --git a/cherrypy/_cpmodpy.py b/cherrypy/_cpmodpy.py index d26af8b0..414bfcb9 100644 --- a/cherrypy/_cpmodpy.py +++ b/cherrypy/_cpmodpy.py @@ -56,14 +56,16 @@ Then restart apache2 and access http://127.0.0.1:8080 """ import logging +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO import cherrypy -from cherrypy.py3util import StringIO from cherrypy._cperror import format_exc, bare_error from cherrypy.lib import httputil - # ------------------------------ Request-handling diff --git a/cherrypy/_cpwsgi.py b/cherrypy/_cpwsgi.py index a35fc36d..8243b406 100644 --- a/cherrypy/_cpwsgi.py +++ b/cherrypy/_cpwsgi.py @@ -3,7 +3,10 @@ import sys as _sys import cherrypy as _cherrypy -from cherrypy.py3util import StringIO +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO from cherrypy import _cperror from cherrypy.lib import httputil diff --git a/cherrypy/lib/encoding.py b/cherrypy/lib/encoding.py index d5886af1..287228dc 100644 --- a/cherrypy/lib/encoding.py +++ b/cherrypy/lib/encoding.py @@ -1,4 +1,8 @@ try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO +try: set except NameError: from sets import Set as set @@ -197,7 +201,6 @@ def compress(body, compress_level): def decompress(body): import gzip - from cherrypy.py3util import StringIO zbuf = StringIO() zbuf.write(body) diff --git a/cherrypy/lib/profiler.py b/cherrypy/lib/profiler.py index 41382b92..75ea17bc 100644 --- a/cherrypy/lib/profiler.py +++ b/cherrypy/lib/profiler.py @@ -54,7 +54,10 @@ except ImportError: import os, os.path import sys -from cherrypy.py3util import StringIO +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO _count = 0 diff --git a/cherrypy/lib/tidy.py b/cherrypy/lib/tidy.py index eff2ec60..98268693 100644 --- a/cherrypy/lib/tidy.py +++ b/cherrypy/lib/tidy.py @@ -2,7 +2,10 @@ import cgi import os -from cherrypy.py3util import StringIO +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO import traceback import cherrypy diff --git a/cherrypy/py3util.py b/cherrypy/py3util.py index ed35c1a6..ed722dba 100644 --- a/cherrypy/py3util.py +++ b/cherrypy/py3util.py @@ -3,18 +3,6 @@ A simple module that helps unify the code between a python2 and python3 library. """ import sys -def py3print(*args, **kwargs): - sep = kwargs.get('sep', ' ') - end = kwargs.get('end', '\n') - file = kwargs.get('file', sys.stdout) - output = sep.join(['%s' % arg for arg in args]) + end - file.write(output) - -try: - from cStringIO import StringIO -except ImportError: - from StringIO import StringIO - def sorted(lst): newlst = list(lst) newlst.sort() diff --git a/cherrypy/test/benchmark.py b/cherrypy/test/benchmark.py index 05667721..277bcb6d 100644 --- a/cherrypy/test/benchmark.py +++ b/cherrypy/test/benchmark.py @@ -217,7 +217,7 @@ Finished 1000 requests try: self.output = _cpmodpy.read_process(AB_PATH or "ab", self.args()) except: - cherrypy.py3print(_cperror.format_exc()) + print(_cperror.format_exc()) raise for attr, name, pattern in self.parse_patterns: @@ -272,25 +272,25 @@ def print_report(rows): lengths = [len(str(row[i])) for row in rows] widths.append(max(lengths)) for row in rows: - cherrypy.py3print() + print("") for i, val in enumerate(row): - cherrypy.py3print(str(val).rjust(widths[i]), "|", end=' ') - cherrypy.py3print() + print str(val).rjust(widths[i]), "|", + print("") def run_standard_benchmarks(): - cherrypy.py3print() - cherrypy.py3print("Client Thread Report (1000 requests, 14 byte response body, " + print("") + print("Client Thread Report (1000 requests, 14 byte response body, " "%s server threads):" % cherrypy.server.thread_pool) print_report(thread_report()) - cherrypy.py3print() - cherrypy.py3print("Client Thread Report (1000 requests, 14 bytes via staticdir, " + print("") + print("Client Thread Report (1000 requests, 14 bytes via staticdir, " "%s server threads):" % cherrypy.server.thread_pool) print_report(thread_report("%s/static/index.html" % SCRIPT_NAME)) - cherrypy.py3print() - cherrypy.py3print("Size Report (1000 requests, 50 client threads, " + print("") + print("Size Report (1000 requests, 50 client threads, " "%s server threads):" % cherrypy.server.thread_pool) print_report(size_report()) @@ -315,7 +315,7 @@ def startup_modpython(req=None): def run_modpython(use_wsgi=False): - cherrypy.py3print("Starting mod_python...") + print("Starting mod_python...") pyopts = [] # Pass the null and ab=path options through Apache @@ -350,11 +350,11 @@ if __name__ == '__main__': switches, args = getopt.getopt(sys.argv[1:], "", longopts) opts = dict(switches) except getopt.GetoptError: - cherrypy.py3print(__doc__) + print(__doc__) sys.exit(2) if "--help" in opts: - cherrypy.py3print(__doc__) + print(__doc__) sys.exit(0) if "--ab" in opts: @@ -365,23 +365,23 @@ if __name__ == '__main__': # can be tested from a standard web browser. def run(): port = cherrypy.server.socket_port - cherrypy.py3print("You may now open http://127.0.0.1:%s%s/" % + print("You may now open http://127.0.0.1:%s%s/" % (port, SCRIPT_NAME)) if "--null" in opts: - cherrypy.py3print("Using null Request object") + print("Using null Request object") else: def run(): end = time.time() - start - cherrypy.py3print("Started in %s seconds" % end) + print("Started in %s seconds" % end) if "--null" in opts: - cherrypy.py3print("\nUsing null Request object") + print("\nUsing null Request object") try: run_standard_benchmarks() finally: cherrypy.engine.exit() - cherrypy.py3print("Starting CherryPy app server...") + print("Starting CherryPy app server...") class NullWriter(object): """Suppresses the printing of socket errors.""" diff --git a/cherrypy/test/helper.py b/cherrypy/test/helper.py index 60ade71f..6377b76b 100644 --- a/cherrypy/test/helper.py +++ b/cherrypy/test/helper.py @@ -57,6 +57,9 @@ class CPWebCase(webtest.WebCase): url = httputil.urljoin(self.script_name, url) return webtest.WebCase.getPage(self, url, headers, method, body, protocol) + def skip(self, msg='skipped '): + sys.stdout.write(msg) + def assertErrorPage(self, status, message=None, pattern=''): """Compare the response body with a built in error page. @@ -83,7 +86,9 @@ class CPWebCase(webtest.WebCase): if m and m.group(1): self._handlewebError('Error page contains traceback') else: - if (m is None) or (not re.search(re.escape(pattern), m.group(1))): + if (m is None) or ( + not re.search(re.escape(pattern), + m.group(1))): msg = 'Error page does not contain %s in traceback' self._handlewebError(msg % repr(pattern)) @@ -191,15 +196,16 @@ server.ssl_private_key: r'%s' else: ssl = "" + conf = self.config_template % { + 'host': self.host, + 'port': self.port, + 'error_log': self.error_log, + 'access_log': self.access_log, + 'ssl': ssl, + 'extra': extra, + } f = open(self.config_file, 'wb') - f.write(self.config_template % - {'host': self.host, - 'port': self.port, - 'error_log': self.error_log, - 'access_log': self.access_log, - 'ssl': ssl, - 'extra': extra, - }) + f.write(conf) f.close() def start(self, imports=None): diff --git a/cherrypy/test/logtest.py b/cherrypy/test/logtest.py index 78d7a740..c093da2c 100644 --- a/cherrypy/test/logtest.py +++ b/cherrypy/test/logtest.py @@ -3,6 +3,8 @@ import sys import time +import cherrypy + try: # On Windows, msvcrt.getch reads a single char without output. @@ -41,36 +43,36 @@ class LogCase(object): markerPrefix = "test suite marker: " def _handleLogError(self, msg, data, marker, pattern): - cherrypy.py3print() - cherrypy.py3print(" ERROR:", msg) + print("") + print(" ERROR: %s" % msg) if not self.interactive: raise self.failureException(msg) p = " Show: [L]og [M]arker [P]attern; [I]gnore, [R]aise, or sys.e[X]it >> " - cherrypy.py3print(p, end=' ') + print p, # ARGH sys.stdout.flush() while True: i = getchar().upper() if i not in "MPLIRX": continue - cherrypy.py3print(i.upper()) # Also prints new line + print(i.upper()) # Also prints new line if i == "L": for x, line in enumerate(data): if (x + 1) % self.console_height == 0: # The \r and comma should make the next line overwrite - cherrypy.py3print("<-- More -->\r", end=' ') + print "<-- More -->\r", m = getchar().lower() # Erase our "More" prompt - cherrypy.py3print(" \r", end=' ') + print " \r", if m == "q": break - cherrypy.py3print(line.rstrip()) + print(line.rstrip()) elif i == "M": - cherrypy.py3print(repr(marker or self.lastmarker)) + print(repr(marker or self.lastmarker)) elif i == "P": - cherrypy.py3print(repr(pattern)) + print(repr(pattern)) elif i == "I": # return without raising the normal exception return @@ -78,7 +80,7 @@ class LogCase(object): raise self.failureException(msg) elif i == "X": self.exit() - cherrypy.py3print(p, end=' ') + print p, def exit(self): sys.exit() diff --git a/cherrypy/test/modfcgid.py b/cherrypy/test/modfcgid.py index e97ebf88..8bfa9ad1 100644 --- a/cherrypy/test/modfcgid.py +++ b/cherrypy/test/modfcgid.py @@ -110,7 +110,7 @@ class ServerControl(test.LocalServer): result = read_process(APACHE_PATH, "-k start -f %s" % fcgiconf) if result: - cherrypy.py3print(result) + print(result) def stop(self): """Gracefully shutdown a server that is serving forever.""" diff --git a/cherrypy/test/modpy.py b/cherrypy/test/modpy.py index a39238f4..61a76976 100644 --- a/cherrypy/test/modpy.py +++ b/cherrypy/test/modpy.py @@ -116,7 +116,7 @@ class ServerControl(object): result = read_process(APACHE_PATH, "-k start -f %s" % mpconf) if result: - cherrypy.py3print(result) + print(result) def stop(self): """Gracefully shutdown a server that is serving forever.""" diff --git a/cherrypy/test/modwsgi.py b/cherrypy/test/modwsgi.py index 6e578d3f..31f69f3c 100644 --- a/cherrypy/test/modwsgi.py +++ b/cherrypy/test/modwsgi.py @@ -115,7 +115,7 @@ class ServerControl(object): result = read_process(APACHE_PATH, "-k start -f %s" % mpconf) if result: - cherrypy.py3print(result) + print(result) # Make a request so mod_wsgi starts up our app. # If we don't, concurrent initial requests will 404. diff --git a/cherrypy/test/test.py b/cherrypy/test/test.py index bcb4b135..3d75b6bf 100644 --- a/cherrypy/test/test.py +++ b/cherrypy/test/test.py @@ -40,15 +40,15 @@ class TestHarness(object): """Run the test harness (using the given [global] conf).""" import cherrypy v = sys.version.split()[0] - cherrypy.py3print("Python version used to run this test script:", v) - cherrypy.py3print("CherryPy version", cherrypy.__version__) + print("Python version used to run this test script: %s" % v) + print("CherryPy version: %s" % cherrypy.__version__) if self.scheme == "https": - ssl = "(ssl)" + ssl = " (ssl)" else: ssl = "" - cherrypy.py3print("HTTP server version", self.protocol, ssl) - cherrypy.py3print("PID:", os.getpid()) - cherrypy.py3print() + print("HTTP server version: %s%s" % (self.protocol, ssl)) + print("PID: %s" % os.getpid()) + print("") if isinstance(conf, basestring): parser = cherrypy.config._Parser() @@ -75,8 +75,8 @@ class TestHarness(object): webtest.WebCase.interactive = self.interactive if self.scheme == "https": webtest.WebCase.HTTP_CONN = HTTPSConnection - cherrypy.py3print() - cherrypy.py3print("Running tests:", self.server) + print("") + print("Running tests: %s" % self.server) return helper.run_test_suite(self.tests, baseconf, self.server) @@ -245,7 +245,7 @@ class CommandLineParser(object): import cherrypy if self.cover and self.profile: # Print error message and exit - cherrypy.py3print('Error: you cannot run the profiler and the ' + print('Error: you cannot run the profiler and the ' 'coverage tool at the same time.') sys.exit(2) @@ -259,20 +259,20 @@ class CommandLineParser(object): """Print help for test.py command-line options.""" import cherrypy - cherrypy.py3print("""CherryPy Test Program + print("""CherryPy Test Program Usage: test.py --help --server=* --host=%s --port=%s --1.0 --ssl --cover --basedir=path --profile --validate --conquer --dumb --tests** """ % (self.__class__.host, self.__class__.port)) - cherrypy.py3print(' * servers:') + print(' * servers:') for name, val in self.available_servers.items(): if name == self.default_server: - cherrypy.py3print(' --server=%s: %s (default)' % (name, val)) + print(' --server=%s: %s (default)' % (name, val)) else: - cherrypy.py3print(' --server=%s: %s' % (name, val)) + print(' --server=%s: %s' % (name, val)) - cherrypy.py3print(""" + print(""" --host=<name or IP addr>: use a host other than the default (%s). Not yet available with mod_python servers. @@ -288,9 +288,9 @@ class CommandLineParser(object): --dumb: turn off the interactive output features. """ % (self.__class__.host, self.__class__.port)) - cherrypy.py3print(' ** tests:') + print(' ** tests:') for name in self.available_tests: - cherrypy.py3print(' --' + name) + print(' --' + name) def start_coverage(self): """Start the coverage tool. @@ -327,7 +327,7 @@ class CommandLineParser(object): if self.coverage: self.coverage.save() self.report_coverage() - cherrypy.py3print("run cherrypy/lib/covercp.py as a script to serve " + print("run cherrypy/lib/covercp.py as a script to serve " "coverage results on port 8080") def report_coverage(self): @@ -350,8 +350,8 @@ class CommandLineParser(object): total_statements = 0 total_executed = 0 - cherrypy.py3print() - cherrypy.py3print("CODE COVERAGE (this might take a while)", end=' ') + print("") + sys.stdout.write("CODE COVERAGE (this might take a while)") for morf in morfs: sys.stdout.write(".") sys.stdout.flush() @@ -374,7 +374,7 @@ class CommandLineParser(object): if total_statements > 0: pc = 100.0 * total_executed / total_statements - cherrypy.py3print("\nTotal: %s Covered: %s Percent: %2d%%" + print("\nTotal: %s Covered: %s Percent: %2d%%" % (total_statements, total_executed, pc)) def run(self, conf=None): @@ -424,8 +424,8 @@ class CommandLineParser(object): success = h.run(conf) if self.profile: - cherrypy.py3print() - cherrypy.py3print("run /cherrypy/lib/profiler.py as a script to serve " + print("") + print("run /cherrypy/lib/profiler.py as a script to serve " "profiling results on port 8080") if self.cover: @@ -496,7 +496,7 @@ def run(): success = clp.run() import cherrypy if clp.interactive: - cherrypy.py3print() + print("") raw_input('hit enter') sys.exit(success) diff --git a/cherrypy/test/test_config.py b/cherrypy/test/test_config.py index 680a7c5d..9bc31204 100644 --- a/cherrypy/test/test_config.py +++ b/cherrypy/test/test_config.py @@ -6,10 +6,14 @@ test.prefer_parent_path() import os, sys localDir = os.path.join(os.getcwd(), os.path.dirname(__file__)) -import cherrypy -from cherrypy.py3util import StringIO +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO import unittest +import cherrypy + def setup_server(): class Root: diff --git a/cherrypy/test/test_config_server.py b/cherrypy/test/test_config_server.py index c656dffa..a95c5cd5 100644 --- a/cherrypy/test/test_config_server.py +++ b/cherrypy/test/test_config_server.py @@ -77,8 +77,7 @@ class ServerConfigTests(helper.CPWebCase): def testMaxRequestSizePerHandler(self): if getattr(cherrypy.server, "using_apache", False): - cherrypy.py3print("skipped due to known Apache differences...", end=' ') - return + return self.skip("skipped due to known Apache differences... ") self.getPage('/tinyupload?maxlen=100', method="POST", body="x" * 100) self.assertStatus(200) @@ -88,8 +87,7 @@ class ServerConfigTests(helper.CPWebCase): def testMaxRequestSize(self): if getattr(cherrypy.server, "using_apache", False): - cherrypy.py3print("skipped due to known Apache differences...", end=' ') - return + return self.skip("skipped due to known Apache differences... ") for size in (500, 5000, 50000): self.getPage("/", headers=[('From', "x" * 500)]) diff --git a/cherrypy/test/test_conn.py b/cherrypy/test/test_conn.py index ccdbf626..ea499aec 100644 --- a/cherrypy/test/test_conn.py +++ b/cherrypy/test/test_conn.py @@ -92,8 +92,7 @@ class ConnectionCloseTests(helper.CPWebCase): def test_HTTP11(self): if cherrypy.server.protocol_version != "HTTP/1.1": - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() self.PROTOCOL = "HTTP/1.1" @@ -249,8 +248,7 @@ class PipelineTests(helper.CPWebCase): # If we timeout without sending any data, # the server will close the conn with a 408. if cherrypy.server.protocol_version != "HTTP/1.1": - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() self.PROTOCOL = "HTTP/1.1" @@ -290,8 +288,7 @@ class PipelineTests(helper.CPWebCase): # If we timeout after at least one request has succeeded, # the server will close the conn without 408. if cherrypy.server.protocol_version != "HTTP/1.1": - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() self.PROTOCOL = "HTTP/1.1" @@ -387,8 +384,7 @@ class PipelineTests(helper.CPWebCase): def test_HTTP11_pipelining(self): if cherrypy.server.protocol_version != "HTTP/1.1": - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() self.PROTOCOL = "HTTP/1.1" @@ -425,8 +421,7 @@ class PipelineTests(helper.CPWebCase): def test_100_Continue(self): if cherrypy.server.protocol_version != "HTTP/1.1": - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() self.PROTOCOL = "HTTP/1.1" @@ -480,8 +475,7 @@ class ConnectionTests(helper.CPWebCase): def test_readall_or_close(self): if cherrypy.server.protocol_version != "HTTP/1.1": - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() self.PROTOCOL = "HTTP/1.1" @@ -552,8 +546,7 @@ class ConnectionTests(helper.CPWebCase): def test_No_Message_Body(self): if cherrypy.server.protocol_version != "HTTP/1.1": - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() self.PROTOCOL = "HTTP/1.1" @@ -582,14 +575,12 @@ class ConnectionTests(helper.CPWebCase): def test_Chunked_Encoding(self): if cherrypy.server.protocol_version != "HTTP/1.1": - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() if (hasattr(self, 'harness') and "modpython" in self.harness.__class__.__name__.lower()): # mod_python forbids chunked encoding - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() self.PROTOCOL = "HTTP/1.1" diff --git a/cherrypy/test/test_core.py b/cherrypy/test/test_core.py index 0d544c2b..c500f308 100644 --- a/cherrypy/test/test_core.py +++ b/cherrypy/test/test_core.py @@ -569,8 +569,7 @@ class CoreRequestHandlingTest(helper.CPWebCase): def test_expose_decorator(self): if not sys.version_info >= (2, 5): - cherrypy.py3print("skipped (Python 2.5+ only)", end=' ') - return + return self.skip("skipped (Python 2.5+ only) ") # Test @expose self.getPage("/expose_dec/no_call") diff --git a/cherrypy/test/test_encoding.py b/cherrypy/test/test_encoding.py index 36d9591b..7fe61c3e 100644 --- a/cherrypy/test/test_encoding.py +++ b/cherrypy/test/test_encoding.py @@ -1,11 +1,16 @@ from cherrypy.test import test test.prefer_parent_path() -import sys import gzip +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO from httplib import IncompleteRead +import sys + import cherrypy -from cherrypy.py3util import StringIO + europoundUnicode = u'\x80\xa3' sing = u"\u6bdb\u6cfd\u4e1c: Sing, Little Birdie?" sing8 = sing.encode('utf-8') diff --git a/cherrypy/test/test_http.py b/cherrypy/test/test_http.py index f9ebcdc6..1b37fce6 100644 --- a/cherrypy/test/test_http.py +++ b/cherrypy/test/test_http.py @@ -129,8 +129,7 @@ class HTTPTests(helper.CPWebCase): def test_malformed_request_line(self): if getattr(cherrypy.server, "using_apache", False): - cherrypy.py3print("skipped due to known Apache differences...", end=' ') - return + return self.skip("skipped due to known Apache differences...") # Test missing version in Request-Line if self.scheme == 'https': @@ -147,8 +146,7 @@ class HTTPTests(helper.CPWebCase): def test_http_over_https(self): if self.scheme != 'https': - cherrypy.py3print("skipped (not running HTTPS)...", end=' ') - return + return self.skip("skipped (not running HTTPS)... ") # Try connecting without SSL. conn = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT)) diff --git a/cherrypy/test/test_json.py b/cherrypy/test/test_json.py index 26a8ef1f..55464125 100644 --- a/cherrypy/test/test_json.py +++ b/cherrypy/test/test_json.py @@ -5,7 +5,7 @@ import cherrypy from cherrypy.lib.jsontools import json if json is None: - cherrypy.py3print("skipped (simplejson not found) ", end=' ') + print "skipped (simplejson not found) " else: def setup_server(): class Root(object): diff --git a/cherrypy/test/test_request_obj.py b/cherrypy/test/test_request_obj.py index 4b3b30a1..23c5578c 100644 --- a/cherrypy/test/test_request_obj.py +++ b/cherrypy/test/test_request_obj.py @@ -709,8 +709,7 @@ class RequestObjectTests(helper.CPWebCase): def test_CONNECT_method(self): if getattr(cherrypy.server, "using_apache", False): - cherrypy.py3print("skipped due to known Apache differences...", end=' ') - return + return self.skip("skipped due to known Apache differences... ") self.getPage("/method/", method="CONNECT") self.assertBody("CONNECT") diff --git a/cherrypy/test/test_session.py b/cherrypy/test/test_session.py index a258e3cf..dbcd00ba 100755 --- a/cherrypy/test/test_session.py +++ b/cherrypy/test/test_session.py @@ -236,7 +236,7 @@ class SessionTest(helper.CPWebCase): else: data_dict[index] = max(data_dict[index], int(body)) # Uncomment the following line to prove threads overlap. -## cherrypy.py3print(index, end=' ') +## print index, # Start <request_count> requests from each of # <client_thread_count> concurrent clients @@ -254,7 +254,7 @@ class SessionTest(helper.CPWebCase): expected = 1 + (client_thread_count * request_count) for e in errors: - cherrypy.py3print(e) + print(e) self.assertEqual(hitcount, expected) def test_3_Redirect(self): @@ -381,7 +381,7 @@ except (ImportError, socket.error): class MemcachedSessionTest(helper.CPWebCase): def test(self): - cherrypy.py3print("skipped", end=' ') + return self.skip("memcached not reachable ") else: class MemcachedSessionTest(helper.CPWebCase): @@ -428,7 +428,7 @@ else: for i in xrange(request_count): self.getPage("/", cookies) # Uncomment the following line to prove threads overlap. -## cherrypy.py3print(index, end=' ') +## print index, if not self.body.isdigit(): self.fail(self.body) data_dict[index] = v = int(self.body) diff --git a/cherrypy/test/test_states.py b/cherrypy/test/test_states.py index ad31f277..579104dd 100644 --- a/cherrypy/test/test_states.py +++ b/cherrypy/test/test_states.py @@ -209,7 +209,7 @@ class ServerStateTests(helper.CPWebCase): except BadStatusLine: pass else: - cherrypy.py3print(self.body) + print(self.body) self.fail("AssertionError: BadStatusLine not raised") engine.block() @@ -230,7 +230,7 @@ class ServerStateTests(helper.CPWebCase): self.assertBody("Hello World") # request.close is called async. while engine.timeout_monitor.servings: - cherrypy.py3print(".", end=' ') + print ".", time.sleep(0.01) # Request a page that explicitly checks itself for deadlock. @@ -295,8 +295,7 @@ class PluginTests(helper.CPWebCase): def test_daemonize(self): if os.name not in ['posix']: - cherrypy.py3print("skipped (not on posix) ", end=' ') - return + return self.skip("skipped (not on posix) ") self.HOST = '127.0.0.1' self.PORT = 8081 # Spawn the process and wait, when this returns, the original process @@ -333,8 +332,7 @@ class SignalHandlingTests(helper.CPWebCase): try: from signal import SIGHUP except ImportError: - cherrypy.py3print("skipped (no SIGHUP) ", end=' ') - return + return self.skip("skipped (no SIGHUP) ") # Spawn the process. p = helper.CPProcess(ssl=(self.scheme.lower()=='https')) @@ -351,12 +349,10 @@ class SignalHandlingTests(helper.CPWebCase): try: from signal import SIGHUP except ImportError: - cherrypy.py3print("skipped (no SIGHUP) ", end=' ') - return + return self.skip("skipped (no SIGHUP) ") if os.name not in ['posix']: - cherrypy.py3print("skipped (not on posix) ", end=' ') - return + return self.skip("skipped (not on posix) ") # Spawn the process and wait, when this returns, the original process # is finished. If it daemonized properly, we should still be able @@ -387,14 +383,12 @@ class SignalHandlingTests(helper.CPWebCase): try: from signal import SIGTERM except ImportError: - cherrypy.py3print("skipped (no SIGTERM) ", end=' ') - return + return self.skip("skipped (no SIGTERM) ") try: from os import kill except ImportError: - cherrypy.py3print("skipped (no os.kill) ", end=' ') - return + return self.skip("skipped (no os.kill) ") # Spawn a normal, undaemonized process. p = helper.CPProcess(ssl=(self.scheme.lower()=='https')) @@ -422,14 +416,12 @@ class SignalHandlingTests(helper.CPWebCase): try: from signal import SIGTERM except ImportError: - cherrypy.py3print("skipped (no SIGTERM) ", end=' ') - return + return self.skip("skipped (no SIGTERM) ") try: from os import kill except ImportError: - cherrypy.py3print("skipped (no os.kill) ", end=' ') - return + return self.skip("skipped (no os.kill) ") # Spawn a normal, undaemonized process. p = helper.CPProcess(ssl=(self.scheme.lower()=='https')) diff --git a/cherrypy/test/test_static.py b/cherrypy/test/test_static.py index 13a5df49..943ffc3b 100644 --- a/cherrypy/test/test_static.py +++ b/cherrypy/test/test_static.py @@ -213,8 +213,7 @@ class StaticTest(helper.CPWebCase): def test_file_stream(self): if cherrypy.server.protocol_version != "HTTP/1.1": - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() self.PROTOCOL = "HTTP/1.1" @@ -252,8 +251,7 @@ class StaticTest(helper.CPWebCase): def test_file_stream_deadlock(self): if cherrypy.server.protocol_version != "HTTP/1.1": - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() self.PROTOCOL = "HTTP/1.1" diff --git a/cherrypy/test/test_tidy.py b/cherrypy/test/test_tidy.py index 85a5bc40..afcee832 100644 --- a/cherrypy/test/test_tidy.py +++ b/cherrypy/test/test_tidy.py @@ -49,8 +49,7 @@ class TidyTest(helper.CPWebCase): def test_Tidy_Tool(self): if not os.path.exists(tidy_path) and not os.path.exists(tidy_path + ".exe"): - cherrypy.py3print("skipped (tidy not found) ", end=' ') - return + return self.skip("skipped (tidy not found) ") self.getPage('/validhtml') self.assertStatus(200) diff --git a/cherrypy/test/test_tools.py b/cherrypy/test/test_tools.py index afb908dd..56d03698 100644 --- a/cherrypy/test/test_tools.py +++ b/cherrypy/test/test_tools.py @@ -1,6 +1,10 @@ """Test the various means of instantiating and invoking tools.""" import gzip +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO import sys from httplib import IncompleteRead import time @@ -11,7 +15,6 @@ from cherrypy.test import test test.prefer_parent_path() import cherrypy -from cherrypy.py3util import StringIO from cherrypy import tools @@ -295,8 +298,7 @@ class ToolTests(helper.CPWebCase): httpserver = cherrypy.server.httpserver old_timeout = httpserver.timeout except (AttributeError, IndexError): - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() try: httpserver.timeout = timeout @@ -374,8 +376,7 @@ class ToolTests(helper.CPWebCase): def testToolWithConfig(self): if not sys.version_info >= (2, 5): - cherrypy.py3print("skipped (Python 2.5+ only)", end=' ') - return + return self.skip("skipped (Python 2.5+ only)") self.getPage('/tooldecs/blah') self.assertHeader('Content-Type', 'application/data') diff --git a/cherrypy/test/test_wsgi_ns.py b/cherrypy/test/test_wsgi_ns.py index 0832d476..9aa36b85 100644 --- a/cherrypy/test/test_wsgi_ns.py +++ b/cherrypy/test/test_wsgi_ns.py @@ -76,8 +76,7 @@ class WSGI_Namespace_Test(helper.CPWebCase): def test_pipeline(self): if not cherrypy.server.httpserver: - cherrypy.py3print("skipped ", end=' ') - return + return self.skip() self.getPage("/") # If body is "HEXXO WORXD!", the middleware was applied out of order. diff --git a/cherrypy/test/test_wsgi_vhost.py b/cherrypy/test/test_wsgi_vhost.py index c5d5e772..c3bf7810 100644 --- a/cherrypy/test/test_wsgi_vhost.py +++ b/cherrypy/test/test_wsgi_vhost.py @@ -33,8 +33,7 @@ class WSGI_VirtualHost_Test(helper.CPWebCase): def test_welcome(self): if not cherrypy.server.using_wsgi: - cherrypy.py3print("skipped (not using WSGI)...", end=' ') - return + return self.skip("skipped (not using WSGI)... ") for year in range(1997, 2008): self.getPage("/", headers=[('Host', 'www.classof%s.example' % year)]) diff --git a/cherrypy/test/test_wsgiapps.py b/cherrypy/test/test_wsgiapps.py index 89b95341..5854560a 100644 --- a/cherrypy/test/test_wsgiapps.py +++ b/cherrypy/test/test_wsgiapps.py @@ -89,8 +89,7 @@ This is a wsgi app running within CherryPy!''' def test_04_pure_wsgi(self): import cherrypy if not cherrypy.server.using_wsgi: - cherrypy.py3print("skipped (not using WSGI)...", end=' ') - return + return self.skip("skipped (not using WSGI)... ") self.getPage("/hosted/app1") self.assertHeader("Content-Type", "text/plain") self.assertInBody(self.wsgi_output) @@ -98,8 +97,7 @@ This is a wsgi app running within CherryPy!''' def test_05_wrapped_cp_app(self): import cherrypy if not cherrypy.server.using_wsgi: - cherrypy.py3print("skipped (not using WSGI)...", end=' ') - return + return self.skip("skipped (not using WSGI)... ") self.getPage("/hosted/app2/") body = list("I'm a regular CherryPy page handler!") body.reverse() @@ -109,8 +107,7 @@ This is a wsgi app running within CherryPy!''' def test_06_empty_string_app(self): import cherrypy if not cherrypy.server.using_wsgi: - cherrypy.py3print("skipped (not using WSGI)...", end=' ') - return + return self.skip("skipped (not using WSGI)... ") self.getPage("/hosted/app3") self.assertHeader("Content-Type", "text/plain") self.assertInBody('Hello world') diff --git a/cherrypy/test/webtest.py b/cherrypy/test/webtest.py index d6c79bdf..475cbfae 100644 --- a/cherrypy/test/webtest.py +++ b/cherrypy/test/webtest.py @@ -243,38 +243,38 @@ class WebCase(TestCase): def _handlewebError(self, msg): import cherrypy - cherrypy.py3print() - cherrypy.py3print(" ERROR:", msg) + print("") + print(" ERROR: %s" % msg) if not self.interactive: raise self.failureException(msg) p = " Show: [B]ody [H]eaders [S]tatus [U]RL; [I]gnore, [R]aise, or sys.e[X]it >> " - cherrypy.py3print(p, end=' ') + print p, # ARGH! sys.stdout.flush() while True: i = getchar().upper() if i not in "BHSUIRX": continue - cherrypy.py3print(i.upper()) # Also prints new line + print(i.upper()) # Also prints new line if i == "B": for x, line in enumerate(self.body.splitlines()): if (x + 1) % self.console_height == 0: # The \r and comma should make the next line overwrite - cherrypy.py3print("<-- More -->\r", end=' ') + print "<-- More -->\r", m = getchar().lower() # Erase our "More" prompt - cherrypy.py3print(" \r", end=' ') + print " \r", if m == "q": break - cherrypy.py3print(line) + print(line) elif i == "H": pprint.pprint(self.headers) elif i == "S": - cherrypy.py3print(self.status) + print(self.status) elif i == "U": - cherrypy.py3print(self.url) + print(self.url) elif i == "I": # return without raising the normal exception return @@ -282,7 +282,7 @@ class WebCase(TestCase): raise self.failureException(msg) elif i == "X": self.exit() - cherrypy.py3print(p, end=' ') + print p, # ARGH sys.stdout.flush() def exit(self): @@ -591,7 +591,7 @@ def server_error(exc=None): return False else: ServerError.on = True - cherrypy.py3print() - cherrypy.py3print("".join(traceback.format_exception(*exc))) + print("") + print("".join(traceback.format_exception(*exc))) return True diff --git a/cherrypy/tutorial/bonus-sqlobject.py b/cherrypy/tutorial/bonus-sqlobject.py index 257773d1..c43feb45 100644 --- a/cherrypy/tutorial/bonus-sqlobject.py +++ b/cherrypy/tutorial/bonus-sqlobject.py @@ -163,6 +163,6 @@ class ContactManager: reset.exposed = True -cherrypy.py3print("If you're running this application for the first time, please go to http://localhost:8080/reset once in order to create the database!") +print("If you're running this application for the first time, please go to http://localhost:8080/reset once in order to create the database!") cherrypy.quickstart(ContactManager()) |