[Zope3-checkins] SVN: Zope3/branches/Zope-3.1/src/zope/ apply 37947 and 37945 to 3.1 branch

Benji York benji at zope.com
Mon Aug 15 17:09:35 EDT 2005


Log message for revision 37948:
  apply 37947 and 37945 to 3.1 branch
  

Changed:
  U   Zope3/branches/Zope-3.1/src/zope/app/publication/httpfactory.py
  U   Zope3/branches/Zope-3.1/src/zope/app/testing/functional.py
  U   Zope3/branches/Zope-3.1/src/zope/configuration/config.py

-=-
Modified: Zope3/branches/Zope-3.1/src/zope/app/publication/httpfactory.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/publication/httpfactory.py	2005-08-15 20:50:03 UTC (rev 37947)
+++ Zope3/branches/Zope-3.1/src/zope/app/publication/httpfactory.py	2005-08-15 21:09:34 UTC (rev 37948)
@@ -21,6 +21,7 @@
 
 from zope.publisher.http import HTTPRequest
 from zope.publisher.browser import BrowserRequest
+from zope.publisher.interfaces.browser import IBrowserRequest
 from zope.publisher.xmlrpc import XMLRPCRequest
 
 from zope.app.publication import interfaces
@@ -29,47 +30,47 @@
 from zope.app.publication.xmlrpc import XMLRPCPublication
 from zope.app.publication.soap import SOAPPublication
 
-_browser_methods = 'GET', 'POST', 'HEAD'
 
+def chooseClasses(method, environment):
+    if method in ('GET', 'POST', 'HEAD'):
+        content_type = environment.get('CONTENT_TYPE', '')
+        is_xml = content_type.startswith('text/xml')
+
+        soap_request = component.queryUtility(interfaces.ISOAPRequestFactory)
+        if (method == 'POST' and is_xml and environment.get('HTTP_SOAPACTION')
+        and soap_request is not None):
+            request_class = soap_request
+            publication_class = SOAPPublication
+        elif (method == 'POST' and is_xml):
+            request_class = component.queryUtility(
+                interfaces.IXMLRPCRequestFactory, default=XMLRPCRequest)
+            publication_class = XMLRPCPublication
+        else:
+            request_class = component.queryUtility(
+                interfaces.IBrowserRequestFactory, default=BrowserRequest)
+            publication_class = BrowserPublication
+    else:
+        request_class = component.queryUtility(
+            interfaces.IHTTPRequestFactory, default=HTTPRequest)
+        publication_class = HTTPPublication
+
+    return request_class, publication_class
+
+
 class HTTPPublicationRequestFactory(object):
     interface.implements(interfaces.IPublicationRequestFactory)
 
     def __init__(self, db):
         """See `zope.app.publication.interfaces.IPublicationRequestFactory`"""
-        self._http = HTTPPublication(db)
-        self._brower = BrowserPublication(db)
-        self._xmlrpc = XMLRPCPublication(db)
-        self._soappub = SOAPPublication(db)
-        self._soapreq = component.queryUtility(interfaces.ISOAPRequestFactory)
-        self._httpreq = component.queryUtility(
-            interfaces.IHTTPRequestFactory, default=HTTPRequest)
-        self._xmlrpcreq = component.queryUtility(
-            interfaces.IXMLRPCRequestFactory, default=XMLRPCRequest)
-        self._browserrequest = component.queryUtility(
-            interfaces.IBrowserRequestFactory, default=BrowserRequest)
+        self._db = db
 
     def __call__(self, input_stream, output_steam, env):
         """See `zope.app.publication.interfaces.IPublicationRequestFactory`"""
         method = env.get('REQUEST_METHOD', 'GET').upper()
-
-        if method in _browser_methods:
-            content_type = env.get('CONTENT_TYPE', '')
-            is_xml = content_type.startswith('text/xml')
-
-            if (method == 'POST' and is_xml and
-                env.get('HTTP_SOAPACTION', None)
-                and self._soapreq is not None):
-                request = self._soapreq(input_stream, output_steam, env)
-                request.setPublication(self._soappub)
-            elif (method == 'POST' and is_xml):
-                request = self._xmlrpcreq(input_stream, output_steam, env)
-                request.setPublication(self._xmlrpc)
-            else:
-                request = self._browserrequest(input_stream, output_steam, env)
-                request.setPublication(self._brower)
-                setDefaultSkin(request)
-        else:
-            request = self._httpreq(input_stream, output_steam, env)
-            request.setPublication(self._http)
-
+        request_class, publication_class = chooseClasses(method, env)
+        request = request_class(input_stream, output_steam, env)
+        request.setPublication(publication_class(self._db))
+        if IBrowserRequest.providedBy(request):
+            # only browser requests have skins
+            setDefaultSkin(request)
         return request

Modified: Zope3/branches/Zope-3.1/src/zope/app/testing/functional.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/testing/functional.py	2005-08-15 20:50:03 UTC (rev 37947)
+++ Zope3/branches/Zope-3.1/src/zope/app/testing/functional.py	2005-08-15 21:09:34 UTC (rev 37948)
@@ -44,12 +44,13 @@
 from zope.app import zapi
 from zope.app.debug import Debugger
 from zope.app.publication.http import HTTPPublication
-from zope.app.publication.browser import BrowserPublication
+from zope.app.publication.browser import BrowserPublication, setDefaultSkin
 from zope.app.publication.xmlrpc import XMLRPCPublication
 from zope.app.publication.soap import SOAPPublication
 from zope.app.publication.interfaces import ISOAPRequestFactory
 from zope.app.publication.zopepublication import ZopePublication
 from zope.app.publication.http import HTTPPublication
+from zope.app.publication.httpfactory import chooseClasses
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 from zope.publisher.interfaces.browser import IDefaultSkin
 from zope.publisher.interfaces.browser import IBrowserRequest
@@ -87,12 +88,6 @@
         return getattr(self._response, attr)
 
 
-def _getDefaultSkin():
-    """Returns the current default skin as an interface."""
-    adapters = zapi.getSiteManager().adapters
-    skin = adapters.lookup((IBrowserRequest,), IDefaultSkin, '')
-    return skin or IDefaultBrowserLayer
-
 class IManagerSetup(zope.interface.Interface):
     """Utility for enabling up a functional testing manager with needed grants
 
@@ -270,7 +265,7 @@
                                environment=environment,
                                basic=basic, form=form,
                                request=BrowserRequest)
-        interface.directlyProvides(request, _getDefaultSkin())
+        setDefaultSkin(request)
         return request
 
     def publish(self, path, basic=None, form=None, env={},
@@ -582,8 +577,7 @@
         old_site = getSite()
         setSite(None)
 
-        request_cls, publication_cls = self.chooseRequestClass(method, path,
-                                                               environment)
+        request_cls, publication_cls = chooseClasses(method, environment)
 
         app = FunctionalTestSetup().getApplication()
 
@@ -591,9 +585,9 @@
             path, instream, outstream,
             environment=environment,
             request=request_cls, publication=publication_cls)
-        if request_cls is BrowserRequest:
-            # Only browser requests have skins
-            interface.directlyProvides(request, _getDefaultSkin())
+        if IBrowserRequest.providedBy(request):
+            # only browser requests have skins
+            setDefaultSkin(request)
 
         if form is not None:
             if request.form:
@@ -615,36 +609,7 @@
 
         return response
 
-    def chooseRequestClass(self, method, path, environment):
-        """Choose and return a request class and a publication class"""
 
-        content_type = environment.get('CONTENT_TYPE', '')
-        is_xml = content_type.startswith('text/xml')
-
-        if method in ('GET', 'POST', 'HEAD'):
-            if (method == 'POST' and environment.get('HTTP_SOAPACTION')
-                and is_xml):
-                factory = zapi.queryUtility(ISOAPRequestFactory)
-                if factory is not None:
-                    request_cls = factory(StringIO(), StringIO(), {}).__class__
-                    publication_cls = SOAPPublication
-                else:
-                    request_cls = BrowserRequest
-                    publication_cls = BrowserPublication
-            elif (method == 'POST' and is_xml):
-                request_cls = XMLRPCRequest
-                publication_cls = XMLRPCPublication
-            else:
-                request_cls = BrowserRequest
-                publication_cls = BrowserPublication
-
-        else:
-            request_cls = HTTPRequest
-            publication_cls = HTTPPublication
-
-        return request_cls, publication_cls
-
-
 def FunctionalDocFileSuite(*paths, **kw):
     globs = kw.setdefault('globs', {})
     globs['http'] = HTTPCaller()

Modified: Zope3/branches/Zope-3.1/src/zope/configuration/config.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/configuration/config.py	2005-08-15 20:50:03 UTC (rev 37947)
+++ Zope3/branches/Zope-3.1/src/zope/configuration/config.py	2005-08-15 21:09:34 UTC (rev 37948)
@@ -612,25 +612,26 @@
 
 
         """
-        for action in resolveConflicts(self.actions):
-            (discriminator, callable, args, kw, includepath, info, order
-             ) = expand_action(*action)
-            if callable is None:
-                continue
-            try:
-                callable(*args, **kw)
-            except:
-                if testing:
-                    raise
-                t, v = sys.exc_info()[:2]
-                v = ConfigurationExecutionError(t, v, info)
-                t = ConfigurationExecutionError
-                raise t, v, sys.exc_info()[2]
+        try:
+            for action in resolveConflicts(self.actions):
+                (discriminator, callable, args, kw, includepath, info, order
+                 ) = expand_action(*action)
+                if callable is None:
+                    continue
+                try:
+                    callable(*args, **kw)
+                except:
+                    if testing:
+                        raise
+                    t, v = sys.exc_info()[:2]
+                    v = ConfigurationExecutionError(t, v, info)
+                    t = ConfigurationExecutionError
+                    raise t, v, sys.exc_info()[2]
+        finally:
+            if clear:
+                del self.actions[:]
 
-        if clear:
-            del self.actions[:]
 
-
 class ConfigurationExecutionError(ConfigurationError):
     """An error occurred during execution of a configuration action
     """



More information about the Zope3-Checkins mailing list