[Checkins] SVN: zope.app.wsgi/trunk/ Add an application factory definition for PasteDeploy.

Dan Korostelev nadako at gmail.com
Mon Feb 9 19:16:42 EST 2009


Log message for revision 96355:
  Add an application factory definition for PasteDeploy.
  Make wsgi.handleErrors variable customizable on application creation.
  Split changelog into a separate file.
  Fix package metadata.
  

Changed:
  A   zope.app.wsgi/trunk/CHANGES.txt
  U   zope.app.wsgi/trunk/README.txt
  U   zope.app.wsgi/trunk/buildout.cfg
  U   zope.app.wsgi/trunk/setup.py
  U   zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py
  A   zope.app.wsgi/trunk/src/zope/app/wsgi/paste.py
  A   zope.app.wsgi/trunk/src/zope/app/wsgi/paste.txt
  U   zope.app.wsgi/trunk/src/zope/app/wsgi/tests.py

-=-
Added: zope.app.wsgi/trunk/CHANGES.txt
===================================================================
--- zope.app.wsgi/trunk/CHANGES.txt	                        (rev 0)
+++ zope.app.wsgi/trunk/CHANGES.txt	2009-02-10 00:16:42 UTC (rev 96355)
@@ -0,0 +1,51 @@
+=======
+CHANGES
+=======
+
+3.5.0 (unreleased)
+------------------
+
+- Add an application factory for Paste. So Zope application can now be
+  easily deployed with Paste .ini configuration like this::
+  
+    [app:main]
+    use = egg:zope.app.wsgi
+    config_file = %(here)s/zope.conf
+    handle_errors = false
+
+  The config_file is a required argument, however the handle_errors
+  defaults to True if not specified. Setting it to False allows you to
+  make WSGIPublisherApplication not handle exceptions itself but
+  propagate them to an upper middleware, like WebError or something. 
+
+- The ``WSGIPublisherApplication`` constructor and ``getWSGIApplication``
+  function now accept optional ``handle_errors`` argument, described
+  above. 
+
+- Change mailing list address to zope-dev at zope.org instead of retired
+  one.
+
+3.4.1 (2008-07-30)
+------------------
+
+- Added Trove classifiers.
+
+- Notify WSGIPublisherApplicationCreated event when WSGI application is
+  created.
+
+- Fixed deprecation warning in ftesting.zcml: ZopeSecurityPolicy moved to
+  zope.securitypolicy.
+
+3.4.0 (2007-09-14)
+------------------
+
+- Fixed the tests to run on Python 2.5 as well as Python 2.4.
+
+- Split ``getApplication`` into ``config`` and ``getApplication`` so
+  that ``config`` could be reused, for example for debugging.
+
+3.4.0a1 (2007-04-22)
+--------------------
+
+Initial release as a separate project, corresponds to zope.app.wsgi
+from Zope 3.4.0a1

Modified: zope.app.wsgi/trunk/README.txt
===================================================================
--- zope.app.wsgi/trunk/README.txt	2009-02-09 23:57:06 UTC (rev 96354)
+++ zope.app.wsgi/trunk/README.txt	2009-02-10 00:16:42 UTC (rev 96355)
@@ -9,40 +9,16 @@
 This is especially useful for debugging.
 
 To bring up Zope and obtain the WSGI application object at the same
-time, use the ``getWSGIApplication`` function.  Here's an example of a
-factory a la PasteDeploy_::
+time, use the ``getWSGIApplication`` function.
 
-    def application_factory(global_conf):
-        zope_conf = os.path.join(global_conf['here'], 'zope.conf')
-        return zope.app.wsgi.getWSGIApplication(zope_conf)
+This package also provides an easy to use application factory for
+PasteDeploy_. You can simply specify an application configuration
+like this in your Paste configuration file::
 
-.. _PasteDeploy: http://pythonpaste.org/deploy/
+    [app:main]
+    use = egg:zope.app.wsgi
+    config_file = %(here)s/zope.conf
 
+Look for more documentation inside the package itself.
 
-Changes
-=======
-
-3.4.1 (2008-07-30)
-------------------
-
-* Added Trove classifiers.
-
-* Notify WSGIPublisherApplicationCreated event when WSGI application is
-  created.
-
-* Fixed deprecation warning in ftesting.zcml: ZopeSecurityPolicy moved to
-  zope.securitypolicy.
-
-3.4.0 (2007-09-14)
-------------------
-
-* Fixed the tests to run on Python 2.5 as well as Python 2.4.
-
-* Split ``getApplication`` into ``config`` and ``getApplication`` so
-  that ``config`` could be reused, for example for debugging.
-
-3.4.0a1 (2007-04-22)
---------------------
-
-Initial release as a separate project, corresponds to zope.app.wsgi
-from Zope 3.4.0a1
+.. _PasteDeploy: http://pythonpaste.org/deploy/

Modified: zope.app.wsgi/trunk/buildout.cfg
===================================================================
--- zope.app.wsgi/trunk/buildout.cfg	2009-02-09 23:57:06 UTC (rev 96354)
+++ zope.app.wsgi/trunk/buildout.cfg	2009-02-10 00:16:42 UTC (rev 96355)
@@ -1,7 +1,6 @@
 [buildout]
 develop = . 
 parts = test
-find-links = http://download.zope.org/distribution/
 
 [test]
 recipe = zc.recipe.testrunner

Modified: zope.app.wsgi/trunk/setup.py
===================================================================
--- zope.app.wsgi/trunk/setup.py	2009-02-09 23:57:06 UTC (rev 96354)
+++ zope.app.wsgi/trunk/setup.py	2009-02-10 00:16:42 UTC (rev 96355)
@@ -18,13 +18,16 @@
 from setuptools import setup, find_packages, Extension
 
 setup(name='zope.app.wsgi',
-      version = '3.4.2dev',
+      version = '3.5.0dev',
       url='http://pypi.python.org/pypi/zope.app.wsgi',
       license='ZPL 2.1',
       description='WSGI application for the zope.publisher',
-      long_description=open('README.txt').read(),
+      long_description=\
+          open('README.txt').read() + \
+          '\n\n' + \
+          open('CHANGES.txt').read(),
       author='Zope Corporation and Contributors',
-      author_email='zope3-dev at zope.org',
+      author_email='zope-dev at zope.org',
       classifiers=['Environment :: Web Environment',
                    'Intended Audience :: Developers',
                    'License :: OSI Approved :: Zope Public License',
@@ -49,6 +52,11 @@
                         'zope.publisher',
                         'zope.security',
                         ],
+      entry_points={
+          'paste.app_factory': [
+              'main = zope.app.wsgi.paste:ZopeApplication'
+          ]
+      },
       include_package_data = True,
       zip_safe = False,
       )

Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py	2009-02-09 23:57:06 UTC (rev 96354)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py	2009-02-10 00:16:42 UTC (rev 96355)
@@ -38,8 +38,10 @@
     """
     implements(interfaces.IWSGIApplication)
 
-    def __init__(self, db=None, factory=HTTPPublicationRequestFactory):
+    def __init__(self, db=None, factory=HTTPPublicationRequestFactory,
+                 handle_errors=True):
         self.requestFactory = None
+        self.handleErrors = handle_errors
 
         if db is not None:
             self.requestFactory = factory(db)
@@ -49,7 +51,7 @@
         request = self.requestFactory(environ['wsgi.input'], environ)
 
         # Let's support post-mortem debugging
-        handle_errors = environ.get('wsgi.handleErrors', True)
+        handle_errors = environ.get('wsgi.handleErrors', self.handleErrors)
 
         request = publish(request, handle_errors=handle_errors)
         response = request.response
@@ -63,8 +65,13 @@
 
 class PMDBWSGIPublisherApplication(WSGIPublisherApplication):
 
+    def __init__(self, db=None, factory=HTTPPublicationRequestFactory,
+                 handle_errors=False):
+        super(PMDBWSGIPublisherApplication, self).__init__(db, factory,
+                                                           handle_errors)
+
     def __call__(self, environ, start_response):
-        environ['wsgi.handleErrors'] = False
+        environ['wsgi.handleErrors'] = self.handleErrors
 
         # Call the application to handle the request and write a response
         try:
@@ -130,9 +137,10 @@
     return db
 
 def getWSGIApplication(configfile, schemafile=None, features=(),
-                       requestFactory=HTTPPublicationRequestFactory):
+                       requestFactory=HTTPPublicationRequestFactory,
+                       handle_errors=True):
     db = config(configfile, schemafile, features)
-    application = WSGIPublisherApplication(db, requestFactory)
+    application = WSGIPublisherApplication(db, requestFactory, handle_errors)
 
     # Create the application, notify subscribers.
     notify(interfaces.WSGIPublisherApplicationCreated(application))

Added: zope.app.wsgi/trunk/src/zope/app/wsgi/paste.py
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/paste.py	                        (rev 0)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/paste.py	2009-02-10 00:16:42 UTC (rev 96355)
@@ -0,0 +1,31 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""An application factory for Paste
+
+$Id$
+"""
+from zope.app.wsgi import getWSGIApplication
+
+def asbool(obj):
+    if isinstance(obj, basestring):
+        obj = obj.lower()
+        if obj in ('1', 'true', 'yes', 't', 'y'):
+            return True
+        if obj in ('0', 'false', 'no', 'f', 'n'):
+            return False
+    return bool(obj)
+
+def ZopeApplication(global_config, config_file, handle_errors=True, **options):
+    handle_errors = asbool(handle_errors)
+    return getWSGIApplication(config_file, handle_errors=handle_errors)


Property changes on: zope.app.wsgi/trunk/src/zope/app/wsgi/paste.py
___________________________________________________________________
Added: svn:keywords
   + Id

Added: zope.app.wsgi/trunk/src/zope/app/wsgi/paste.txt
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/paste.txt	                        (rev 0)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/paste.txt	2009-02-10 00:16:42 UTC (rev 96355)
@@ -0,0 +1,87 @@
+==================================================
+Zope WSGI application integration with PasteDeploy
+==================================================
+
+PasteDeploy provides a framework for defining WSGI component factories
+that are used for assembling an application using simple configuration
+files. The ``zope.app.wsgi.paste`` package provides an paste application
+factory for the Zope WSGI application server, created using the
+configuration file, typically the ``zope.conf``.
+
+To use in Paste, you include a configuration section like this::
+
+  [app:main]
+  use = egg:zope.app.wsgi
+  config_file = %(here)s/zope.conf
+
+This example defines a "main" application using the zope.app.wsgi
+factory.  The only option that is required by zope.app.wsgi is the
+path to a configuration file. That file typically defines a path to a
+site definition file (the ``site.zcml``) and things like eventlog
+configuration or enabling developer mode.
+
+The factory also accepts the ``handle_errors`` boolean argument.
+It's useful, when you don't want Zope application to handle exceptions
+and want it to propagate them to upper WSGI middlewares.
+
+The application factory only creates the WSGI application using the
+``zope.app.wsgi.getWSGIApplication`` function. So we don't test it
+here. Instead, we'll only examine the Paste application factory
+provided by ``zope.app.wsgi.paste.ZopeApplication``.
+
+Let's create testing site.zcml and zope.conf file.
+
+  >>> import os, tempfile
+  >>> temp_dir = tempfile.mkdtemp()
+  >>> sitezcml = os.path.join(temp_dir, 'site.zcml')
+  >>> open(sitezcml, 'w').write('<configure />')
+  >>> zopeconf = os.path.join(temp_dir, 'zope.conf')
+  >>> open(zopeconf, 'w').write('''
+  ... site-definition %s
+  ...
+  ... <zodb>
+  ...   <mappingstorage />
+  ... </zodb>
+  ...
+  ... <eventlog>
+  ...   <logfile>
+  ...     path STDOUT
+  ...   </logfile>
+  ... </eventlog>
+  ... ''' % sitezcml)
+
+Let's end any security interaction we have, as application will try to
+create new interaction for its tasks.
+
+  >>> from zope.security import management
+  >>> if management.queryInteraction(): management.endInteraction()
+
+Now, let's create the application using our application factory as
+Paste does.
+
+  >>> from zope.app.wsgi.paste import ZopeApplication
+  >>> app = ZopeApplication({}, zopeconf)
+
+  >>> app
+  <zope.app.wsgi.WSGIPublisherApplication object at 0x...>
+  >>> app.handleErrors
+  True
+
+We can also specify handle_errors as false using boolean or strings:
+
+  >>> app = ZopeApplication({}, zopeconf, handle_errors=False)
+  >>> app.handleErrors
+  False
+  
+  >>> for v in ('0', 'false', 'no', 'f', 'n'):
+  ...     print ZopeApplication({}, zopeconf, handle_errors=v).handleErrors
+  False
+  False
+  False
+  False
+  False
+
+Okay, remove the temporary files.
+
+  >>> import shutil
+  >>> shutil.rmtree(temp_dir)

Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/tests.py
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/tests.py	2009-02-09 23:57:06 UTC (rev 96354)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/tests.py	2009-02-10 00:16:42 UTC (rev 96355)
@@ -112,7 +112,7 @@
     return unittest.TestSuite((
         functional_suite,
         doctest.DocFileSuite(
-            'README.txt', 'fileresult.txt',
+            'README.txt', 'fileresult.txt', 'paste.txt',
             setUp=setUp, checker=checker,
             tearDown=placelesssetup.tearDown,
             optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),



More information about the Checkins mailing list