1. cherrypy
  2. CherryPy

Commits

Robert Brewer  committed e19e8aa

Some cross ports from the python3 branch, including two test fixes.

  • Participants
  • Parent commits ace0fa8
  • Branches default

Comments (0)

Files changed (6)

File cherrypy/_cperror.py

View file
  • Ignore whitespace
                    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)

File cherrypy/_cplogging.py

View file
  • Ignore whitespace
 logging.Logger.manager.emittedNoHandlerWarning = 1
 logfmt = logging.Formatter("%(message)s")
 import os
-import rfc822
 import sys
 
 import cherrypy
     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))
     

File cherrypy/lib/caching.py

View file
  • Ignore whitespace
         # 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:

File cherrypy/test/benchmark.py

View file
  • Ignore whitespace
         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:
         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)
             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()
     

File cherrypy/test/test_bus.py

View file
  • Ignore whitespace
             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)

File cherrypy/test/test_static.py

View file
  • Ignore whitespace
 from cherrypy.test import test
 test.prefer_parent_path()
 
+from httplib import HTTPConnection, HTTPSConnection
 try:
     import cStringIO as StringIO
 except ImportError:
         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):
         
         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)." %