[Checkins] SVN: zope.app.wsgi/trunk/src/zope/app/wsgi/ Notify WSGIPublisherApplicationCreated event when WSGI application is

Yusei Tahara yusei at domen.cx
Thu Jan 3 17:52:56 EST 2008


Log message for revision 82663:
  Notify WSGIPublisherApplicationCreated event when WSGI application is
  created.
  

Changed:
  U   zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt
  U   zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py
  U   zope.app.wsgi/trunk/src/zope/app/wsgi/interfaces.py

-=-
Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt	2008-01-03 20:58:02 UTC (rev 82662)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt	2008-01-03 22:52:56 UTC (rev 82663)
@@ -125,10 +125,27 @@
   ... </eventlog>
   ... ''' %sitezcml)
 
+
+Create an handler for the event.
+
+  >>> import zope.component
+  >>> from zope.app.wsgi.interfaces import IWSGIPublisherApplicationCreatedEvent
+  >>> called = []
+  >>> @zope.component.adapter(IWSGIPublisherApplicationCreatedEvent)
+  ... def handler(event):
+  ...     called.append(event)
+
+  >>> zope.component.provideHandler(handler)
+
+Create an WSGI application.
+
   >>> app = wsgi.getWSGIApplication(configFile)
   >>> app
   <zope.app.wsgi.WSGIPublisherApplication object at ...>
 
+  >>> called[0].application is app
+  True
+
   >>> import shutil
   >>> shutil.rmtree(temp_dir)
 

Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py	2008-01-03 20:58:02 UTC (rev 82662)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py	2008-01-03 22:52:56 UTC (rev 82663)
@@ -132,4 +132,9 @@
 def getWSGIApplication(configfile, schemafile=None, features=(),
                        requestFactory=HTTPPublicationRequestFactory):
     db = config(configfile, schemafile, features)
-    return WSGIPublisherApplication(db, requestFactory)
+    application = WSGIPublisherApplication(db, requestFactory)
+
+    # Create the application, notify subscribers.
+    notify(interfaces.WSGIPublisherApplicationCreated(application))
+
+    return application

Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/interfaces.py
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/interfaces.py	2008-01-03 20:58:02 UTC (rev 82662)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/interfaces.py	2008-01-03 22:52:56 UTC (rev 82663)
@@ -19,7 +19,7 @@
 """
 __docformat__ = "reStructuredText"
 
-from zope.interface import Interface
+import zope.interface
 from zope.publisher.interfaces.http import IHeaderOutput
 
 
@@ -42,7 +42,7 @@
         ``start_response()`` callable to begin the response.
         """
 
-class IWSGIApplication(Interface):
+class IWSGIApplication(zope.interface.Interface):
     """A WSGI application."""
 
     def __call__(environ, start_response):
@@ -67,8 +67,21 @@
         """
 
 
-class IWSGIServer(Interface):
+class IWSGIServer(zope.interface.Interface):
     """A WSGI server."""
 
     def set_application(app):
         """Tells the server about the application to use."""
+
+
+class IWSGIPublisherApplicationCreatedEvent(zope.interface.Interface):
+    """A WSGI application has been created."""
+
+    application = zope.interface.Attribute("The WSGI application.")
+
+
+class WSGIPublisherApplicationCreated(object):
+    zope.interface.implements(IWSGIPublisherApplicationCreatedEvent)
+
+    def __init__(self, application):
+        self.application = application



More information about the Checkins mailing list