Commits

Robert Brewer  committed 7338c52

Test support for wsgiref.validate (new '--validate' arg to test.py), plus a couple minor fixes based on the first validation run.

  • Participants
  • Parent commits e11dafe

Comments (0)

Files changed (6)

File cherrypy/_cpwsgiserver.py

         
         # Must use keys() here for Python 2.3 (rfc822.Message had no __iter__).
         for k in headers.keys():
+            if k in ('transfer-encoding', 'content-type', 'content-length'):
+                continue
+            
             envname = "HTTP_" + k.upper().replace("-", "_")
             if k in comma_separated_headers:
                 existing = environ.get(envname)
                     environ[envname] = ", ".join([existing] + headers.getheaders(k))
                 else:
                     environ[envname] = ", ".join(headers.getheaders(k))
-            elif k in ('Transfer-Encoding',):
-                pass
             else:
                 environ[envname] = headers[k]
         return environ

File cherrypy/lib/wsgiapp.py

-"""a WSGI application tool for CherryPy"""
+"""A CherryPy tool for hosting a foreign WSGI application."""
 
 import sys
 

File cherrypy/test/helper.py

     cherrypy.engine.start_with_callback(_run_test_suite_thread,
                                         args=(moduleNames, conf))
 
-def sync_apps(profile=False):
+def sync_apps(profile=False, validate=False):
     apps = []
     for base, app in cherrypy.tree.apps.iteritems():
         if base == "/":
             base = ""
         if profile:
-            apps.append((base, profiler.make_app(app, aggregate=False)))
-        else:
-            apps.append((base, app))
+            app = profiler.make_app(app, aggregate=False)
+        if validate:
+            try:
+                from wsgiref import validate
+            except ImportError:
+                warnings.warn("Error importing wsgiref. The validator will not run.")
+            app = validate.validator(app)
+        apps.append((base, app))
     apps.sort()
     apps.reverse()
     for s in cherrypy.server.httpservers:
         
         # The setup functions probably mounted new apps.
         # Tell our server about them.
-        sync_apps(profile=conf.get("profiling.on", False))
+        sync_apps(profile=conf.get("profiling.on", False),
+                  validate=conf.get("validator.on", False))
         
         suite = CPTestLoader.loadTestsFromName(testmod)
         CPTestRunner.run(suite)

File cherrypy/test/test.py

         self.available_tests = available_tests
         self.cover = False
         self.profile = False
+        self.validate = False
         self.server = None
         self.protocol = "HTTP/1.1"
         
-        longopts = ['cover', 'profile', '1.0', 'help', 'basedir=', 'port=',
+        longopts = ['cover', 'profile', 'validate', '1.0', 'help', 'basedir=', 'port=',
                     'server=']
         longopts.extend(self.available_tests)
         try:
                 self.cover = True
             elif o == "--profile":
                 self.profile = True
+            elif o == "--validate":
+                self.validate = True
             elif o == "--1.0":
                 self.protocol = "HTTP/1.0"
             elif o == "--basedir":
         
         print """CherryPy Test Program
     Usage:
-        test.py --server=* --port=%s --1.0 --cover --basedir=path --profile --tests**
+        test.py --server=* --port=%s --1.0 --cover --basedir=path --profile --validate --tests**
         
     """ % self.__class__.port
         print '    * servers:'
     --basedir=path: display coverage stats for some path other than cherrypy.
     
     --profile: turn on profiling tool
+    --validate: use wsgiref.validate (builtin in Python 2.5).
     """ % self.__class__.port
         
         print '    ** tests:'
             conf = conf or {}
             conf['profiling.on'] = True
         
+        if self.validate:
+            conf = conf or {}
+            conf['validator.on'] = True
+        
         if self.server == 'cpmodpy':
             from cherrypy.test import modpy
             h = modpy.ModPythonTestHarness(self.tests, self.server,
         h.run(conf)
         
         if self.profile:
-            del conf['profiling.on']
             print
             print ("run /cherrypy/lib/profiler.py as a script to serve "
                    "profiling results on port 8080")

File cherrypy/test/test_config.py

         elif key == 'output':
             handler = cherrypy.request.handler
             def wrapper():
+                # 'value' is a type (like int or str).
                 return value(handler())
             cherrypy.request.handler = wrapper
     cherrypy.engine.request_class.namespaces['raw'] = raw_namespace

File cherrypy/test/test_wsgiapps.py

                 results = "".join(results)
             results = list(results)
             results.reverse()
-            return "".join(results)
+            return ["".join(results)]
         return _app
     
     class Root: