diff options
-rw-r--r-- | cherrypy/_cperror.py | 3 | ||||
-rw-r--r-- | cherrypy/_cplogging.py | 5 | ||||
-rw-r--r-- | cherrypy/lib/caching.py | 2 | ||||
-rw-r--r-- | cherrypy/test/benchmark.py | 10 | ||||
-rw-r--r-- | cherrypy/test/test_bus.py | 2 | ||||
-rw-r--r-- | cherrypy/test/test_static.py | 43 |
6 files changed, 49 insertions, 16 deletions
diff --git a/cherrypy/_cperror.py b/cherrypy/_cperror.py index 106c9dd2..f26de061 100644 --- a/cherrypy/_cperror.py +++ b/cherrypy/_cperror.py @@ -117,7 +117,8 @@ class HTTPRedirect(CherryPyException): 303: "This resource can be found at <a href='%s'>%s</a>.", 307: "This resource has moved temporarily to <a href='%s'>%s</a>.", }[status] - response.body = "<br />\n".join([msg % (u, u) for u in self.urls]) + msgs = [msg % (u, u) for u in self.urls] + response.body = "<br />\n".join(msgs) # Previous code may have set C-L, so we have to reset it # (allow finalize to set it). response.headers.pop('Content-Length', None) diff --git a/cherrypy/_cplogging.py b/cherrypy/_cplogging.py index 554a5294..ec4ee498 100644 --- a/cherrypy/_cplogging.py +++ b/cherrypy/_cplogging.py @@ -6,7 +6,6 @@ import logging logging.Logger.manager.emittedNoHandlerWarning = 1 logfmt = logging.Formatter("%(message)s") import os -import rfc822 import sys import cherrypy @@ -111,7 +110,9 @@ class LogManager(object): def time(self): """Return now() in Apache Common Log Format (no timezone).""" now = datetime.datetime.now() - month = rfc822._monthnames[now.month - 1].capitalize() + monthnames = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', + 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'] + month = monthnames[now.month - 1].capitalize() return ('[%02d/%s/%04d:%02d:%02d:%02d]' % (now.day, month, now.year, now.hour, now.minute, now.second)) diff --git a/cherrypy/lib/caching.py b/cherrypy/lib/caching.py index e97decb6..cebf5399 100644 --- a/cherrypy/lib/caching.py +++ b/cherrypy/lib/caching.py @@ -137,6 +137,8 @@ class MemoryCache: # See tickets #99 and #180 for more information. while time: now = time.time() + # Must make a copy of expirations so it doesn't change size + # during iteration for expiration_time, objects in self.expirations.items(): if expiration_time <= now: for obj_size, obj_key in objects: diff --git a/cherrypy/test/benchmark.py b/cherrypy/test/benchmark.py index 277bcb6d..93377020 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: - print(_cperror.format_exc()) + print _cperror.format_exc() raise for attr, name, pattern in self.parse_patterns: @@ -246,7 +246,7 @@ def thread_report(path=SCRIPT_NAME + "/hello", concurrency=safe_threads): sess.run() row = [c] for attr in attrs: - val = getattr(sess, attr) + val = float(getattr(sess, attr)) avg[attr] += float(val) row.append(val) rows.append(row) @@ -377,7 +377,11 @@ if __name__ == '__main__': if "--null" in opts: print("\nUsing null Request object") try: - run_standard_benchmarks() + try: + run_standard_benchmarks() + except: + print _cperror.format_exc() + raise finally: cherrypy.engine.exit() diff --git a/cherrypy/test/test_bus.py b/cherrypy/test/test_bus.py index 6b3afe6b..aab17819 100644 --- a/cherrypy/test/test_bus.py +++ b/cherrypy/test/test_bus.py @@ -70,7 +70,7 @@ class PublishSubscribeTests(unittest.TestCase): b.subscribe(channel, lambda: None, priority=20) for channel in channels: - self.assertRaises(TypeError, b.publish, channel, 123) + self.assertRaises(wspbus.ChannelFailures, b.publish, channel, 123) expected.append(msg % (1, channel, 123)) self.assertEqual(self.responses, expected) diff --git a/cherrypy/test/test_static.py b/cherrypy/test/test_static.py index 943ffc3b..524db795 100644 --- a/cherrypy/test/test_static.py +++ b/cherrypy/test/test_static.py @@ -1,6 +1,7 @@ from cherrypy.test import test test.prefer_parent_path() +from httplib import HTTPConnection, HTTPSConnection try: import cStringIO as StringIO except ImportError: @@ -32,7 +33,9 @@ def setup_server(): bigfile._cp_config = {'response.stream': True} def tell(self): - return repr(self.f.input.tell()) + if self.f.input.closed: + return '' + return repr(self.f.input.tell()).rstrip('L') tell.exposed = True def fileobj(self): @@ -229,20 +232,42 @@ class StaticTest(helper.CPWebCase): body = '' remaining = BIGFILE_SIZE - # By this point, the webserver has already written one chunk to - # the socket and queued another. So we start with i=1. - i = 1 while remaining > 0: - i += 1 - s, h, b = helper.webtest.openURL( - "/tell", headers=[], host=self.HOST, port=self.PORT) - if remaining != 65536: - self.assertEqual(long(b), 65536 * i) data = response.fp.read(65536) if not data: break body += data remaining -= len(data) + + if self.scheme == "https": + newconn = HTTPSConnection + else: + newconn = HTTPConnection + s, h, b = helper.webtest.openURL( + "/tell", headers=[], host=self.HOST, port=self.PORT, + http_conn=newconn) + if not b: + # The file was closed on the server. + tell_position = BIGFILE_SIZE + else: + tell_position = int(b) + + expected = len(body) + if tell_position >= BIGFILE_SIZE: + # We can't exactly control how much content the server asks for. + # Fudge it by only checking the first half of the reads. + if expected < (BIGFILE_SIZE / 2): + self.fail( + "The file should have advanced to position %r, but has " + "already advanced to the end of the file. It may not be " + "streamed as intended, or at the wrong chunk size (64k)" % + expected) + elif tell_position < expected: + self.fail( + "The file should have advanced to position %r, but has " + "only advanced to position %r. It may not be streamed " + "as intended, or at the wrong chunk size (65536)" % + (expected, tell_position)) if body != "x" * BIGFILE_SIZE: self.fail("Body != 'x' * %d. Got %r instead (%d bytes)." % |