[Zope3-checkins] SVN: Zope3/branches/jinty-zodbless/src/zope/app/server/ convert zope.app.server to use resource and application factories.

Brian Sutherland jinty at web.de
Mon Apr 9 18:40:28 EDT 2007


Log message for revision 74069:
  convert zope.app.server to use resource and application factories.

Changed:
  U   Zope3/branches/jinty-zodbless/src/zope/app/server/ftp.py
  U   Zope3/branches/jinty-zodbless/src/zope/app/server/main.py
  U   Zope3/branches/jinty-zodbless/src/zope/app/server/server.py
  U   Zope3/branches/jinty-zodbless/src/zope/app/server/servertype.py
  U   Zope3/branches/jinty-zodbless/src/zope/app/server/tests/test_server.py
  U   Zope3/branches/jinty-zodbless/src/zope/app/server/tests/test_servertype.py
  U   Zope3/branches/jinty-zodbless/src/zope/app/server/wsgi.py

-=-
Modified: Zope3/branches/jinty-zodbless/src/zope/app/server/ftp.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/server/ftp.py	2007-04-09 22:07:17 UTC (rev 74068)
+++ Zope3/branches/jinty-zodbless/src/zope/app/server/ftp.py	2007-04-09 22:40:27 UTC (rev 74069)
@@ -26,8 +26,8 @@
 class FTPRequestFactory(object):
     """FTP Request factory
 
-    FTP request factories for a given database create FTP requets with
-    publications on the given database:
+    FTP request factories for a given resource factory create FTP requests with
+    publications on the given resource factory:
 
       >>> from zope.app.publication.interfaces import IResourceFactory
       >>> class Stub:
@@ -42,8 +42,8 @@
     """
     zope.interface.implements(IPublicationRequestFactory)
 
-    def __init__(self, db):
-        self.publication = FTPPublication(db)
+    def __init__(self, resource_factory):
+        self.publication = FTPPublication(resource_factory)
 
     def __call__(self, input_stream, env):
         request = FTPRequest(input_stream, env)

Modified: Zope3/branches/jinty-zodbless/src/zope/app/server/main.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/server/main.py	2007-04-09 22:07:17 UTC (rev 74068)
+++ Zope3/branches/jinty-zodbless/src/zope/app/server/main.py	2007-04-09 22:40:27 UTC (rev 74069)
@@ -27,6 +27,7 @@
 import zope.app.appsetup.appsetup
 import zope.app.appsetup.interfaces
 import zope.app.appsetup.product
+from zope.app.appsetup import appsetup
 from zope.event import notify
 from zope.server.taskthreads import ThreadedTaskDispatcher
 
@@ -64,14 +65,11 @@
 
 def debug(args=None):
     options = load_options(args)
-
     zope.app.appsetup.config(options.site_definition)
+    app_factory = appsetup.setup_app_factory(options.databases)
+    return app_factory
 
-    db = zope.app.appsetup.appsetup.multi_database(options.databases)[0][0]
-    notify(zope.app.appsetup.interfaces.DatabaseOpened(db))
-    return db
 
-
 def run():
     try:
         ThreadedAsync.loop()
@@ -113,16 +111,14 @@
 
     zope.app.appsetup.config(options.site_definition, features=features)
 
-    db = zope.app.appsetup.appsetup.multi_database(options.databases)[0][0]
+    app_factory = appsetup.setup_app_factory(options.databases)
 
-    notify(zope.app.appsetup.interfaces.DatabaseOpened(db))
-
     task_dispatcher = ThreadedTaskDispatcher()
     task_dispatcher.setThreadCount(options.threads)
 
     for server in options.servers:
-        server.create(task_dispatcher, db)
+        server.create(task_dispatcher, app_factory)
 
     notify(zope.app.appsetup.interfaces.ProcessStarting())
 
-    return db
+    return app_factory

Modified: Zope3/branches/jinty-zodbless/src/zope/app/server/server.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/server/server.py	2007-04-09 22:07:17 UTC (rev 74068)
+++ Zope3/branches/jinty-zodbless/src/zope/app/server/server.py	2007-04-09 22:40:27 UTC (rev 74069)
@@ -33,14 +33,14 @@
         self.address = section.address
         self.verbose = section.verbose
 
-    def create(self, task_dispatcher, database):
+    def create(self, task_dispatcher, resource_factory):
         """Return a server based on the server types defined via ZCML."""
 
         servertype = zapi.getUtility(IServerType, self.type)
         # The server object self-registers with the asyncore mainloop.
         return servertype.create(
             self.type,
-            task_dispatcher, database,
+            task_dispatcher, resource_factory,
             ip=self.address[0],
             port=self.address[1],
             verbose=self.verbose)

Modified: Zope3/branches/jinty-zodbless/src/zope/app/server/servertype.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/server/servertype.py	2007-04-09 22:07:17 UTC (rev 74068)
+++ Zope3/branches/jinty-zodbless/src/zope/app/server/servertype.py	2007-04-09 22:40:27 UTC (rev 74069)
@@ -25,10 +25,13 @@
     a ZCML directive and we shouldn't be able to change them.
     """
 
-    def create(name, task_dispatcher, db, port=None, verbose=None, ip=None):
-        """Create the server knowing the port, task dispatcher and the ZODB.
-
-        Returns the new server.
+    def create(name, task_dispatcher, resource_factory, port=None,
+               verbose=None, ip=None):
+        """Create the server.
+        
+        Returns the server knowing the port, task dispatcher and the resource
+        factory. See zope.app.publication.interfaces.IResourceFactory for
+        details on the resource factory.
         """
 
 class ServerType(object):
@@ -45,11 +48,11 @@
         self._defaultIP = defaultIP
 
 
-    def create(self, name, task_dispatcher, db, port=None,
+    def create(self, name, task_dispatcher, resource_factory, port=None,
                verbose=None, ip=None):
         'See IServerType'
 
-        request_factory = self._requestFactory(db)
+        request_factory = self._requestFactory(resource_factory)
 
         if port is None:
             port = self._defaultPort

Modified: Zope3/branches/jinty-zodbless/src/zope/app/server/tests/test_server.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/server/tests/test_server.py	2007-04-09 22:07:17 UTC (rev 74068)
+++ Zope3/branches/jinty-zodbless/src/zope/app/server/tests/test_server.py	2007-04-09 22:40:27 UTC (rev 74069)
@@ -34,13 +34,13 @@
         >>> from zope.app.server.servertype import IServerType
         >>> class MyServerType:
         ...     implements(IServerType)
-        ...     def create(self, name, task_dispatcher, db, port='unknown',
-        ...                verbose='unspecified', ip=''):
+        ...     def create(self, name, task_dispatcher, resource_factory,
+        ...                port='unknown', verbose='unspecified', ip=''):
         ...         if not ip:
         ...             ip = '*' # listen on all interfaces
         ...         return ('%s server on %s:%d, registered with %s,\n'
         ...                 'serving from %s, verbosity %s'
-        ...                 % (name, ip, port, task_dispatcher, db, verbose))
+        ...                 % (name, ip, port, task_dispatcher, resource_factory, verbose))
         >>> ztapi.provideUtility(IServerType, MyServerType(), name='HTTP')
         >>> ztapi.provideUtility(IServerType, MyServerType(), name='FTP')
 
@@ -62,10 +62,10 @@
     database object.
 
         >>> task_dispatcher = 'my task dispatcher'
-        >>> db = 'my db'
-        >>> print sf.create(task_dispatcher, db)
+        >>> resource_factory = 'my resource factory'
+        >>> print sf.create(task_dispatcher, resource_factory)
         HTTP server on *:8080, registered with my task dispatcher,
-        serving from my db, verbosity False
+        serving from my resource factory, verbosity False
 
     The settings actually work
 
@@ -73,9 +73,9 @@
         >>> my_section.address = ('127.0.0.1', 8021)
         >>> my_section.verbose = True
         >>> sf = ServerFactory(my_section)
-        >>> print sf.create(task_dispatcher, db)
+        >>> print sf.create(task_dispatcher, resource_factory)
         FTP server on 127.0.0.1:8021, registered with my task dispatcher,
-        serving from my db, verbosity True
+        serving from my resource factory, verbosity True
 
     That's it.
 

Modified: Zope3/branches/jinty-zodbless/src/zope/app/server/tests/test_servertype.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/server/tests/test_servertype.py	2007-04-09 22:07:17 UTC (rev 74068)
+++ Zope3/branches/jinty-zodbless/src/zope/app/server/tests/test_servertype.py	2007-04-09 22:40:27 UTC (rev 74069)
@@ -53,8 +53,8 @@
     zope.server.http.publisherhttpserver).  It is, in fact, a request factory
     factory.
 
-        >>> def requestFactory(db):
-        ...     return 'my request factory for %s' % db
+        >>> def requestFactory(resource_factory):
+        ...     return 'my request factory for %s' % resource_factory
 
     The 'logFactory' argument specifies the factory for an access logger (e.g.
     CommonAccessLogger from zope.server.http.commonaccesslogger).
@@ -83,18 +83,18 @@
     of servers listening on a specific port.
 
     When you create an instance of a server, you need to tell it the task
-    dispatcher (see IDispatcher in zope.server.interfaces), and the ZODB
-    database object.
+    dispatcher (see IDispatcher in zope.server.interfaces), and the resource
+    factory (see IResourceFactory in zope.app.publication.interfaces).
 
     The `name` argument to create is, as far as I can tell, purely informative.
     It is used to construct a server identifier that appears in log files and,
     for example, the 'Server' HTTP header.
 
         >>> dispatcher = 'my task dispatcher'
-        >>> db = 'my database'
-        >>> st.create('Sample Server', dispatcher, db)
+        >>> resource_factory = 'my resource factory'
+        >>> st.create('Sample Server', dispatcher, resource_factory)
         Starting a server (Sample Server) on *:8080
-        This server will use my request factory for my database to construct requests
+        This server will use my request factory for my resource factory to construct requests
         This server will use my logger for hit logging
         This server will not be verbose
         This server will be managed by my task dispatcher
@@ -102,17 +102,18 @@
     You can, of course, create multiple instances of the same server type, and
     bind them to different ports.
 
-        >>> st.create('Sample Server 2', dispatcher, db, port=1234, verbose=True)
+        >>> st.create('Sample Server 2', dispatcher, resource_factory,
+        ...           port=1234, verbose=True)
         Starting a server (Sample Server 2) on *:1234
-        This server will use my request factory for my database to construct requests
+        This server will use my request factory for my resource factory to construct requests
         This server will use my logger for hit logging
         This server will be verbose
         This server will be managed by my task dispatcher
 
-        >>> st.create('Sample Server 3', dispatcher, db, port=9090,
-        ...           ip='127.0.0.1')
+        >>> st.create('Sample Server 3', dispatcher, resource_factory,
+        ...           port=9090, ip='127.0.0.1')
         Starting a server (Sample Server 3) on 127.0.0.1:9090
-        This server will use my request factory for my database to construct requests
+        This server will use my request factory for my resource factory to construct requests
         This server will use my logger for hit logging
         This server will not be verbose
         This server will be managed by my task dispatcher

Modified: Zope3/branches/jinty-zodbless/src/zope/app/server/wsgi.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/server/wsgi.py	2007-04-09 22:07:17 UTC (rev 74068)
+++ Zope3/branches/jinty-zodbless/src/zope/app/server/wsgi.py	2007-04-09 22:40:27 UTC (rev 74069)
@@ -42,12 +42,12 @@
         self._defaultIP = defaultIP
 
 
-    def create(self, name, task_dispatcher, db, port=None,
+    def create(self, name, task_dispatcher, resource_factory, port=None,
                verbose=None, ip=None):
         'See IServerType'
 
         application = self._applicationFactory(
-            db, factory=self._requestFactory)
+            resource_factory, factory=self._requestFactory)
 
         if port is None:
             port = self._defaultPort



More information about the Zope3-Checkins mailing list