Log message for revision 123206:
  Merge elro-remove-request-container branch into elro-parent-pointers branch

Changed:
  U   Zope/branches/elro-parent-pointers/setup.py
  U   Zope/branches/elro-parent-pointers/sources.cfg
  U   Zope/branches/elro-parent-pointers/src/OFS/Application.py
  U   
Zope/branches/elro-parent-pointers/src/Products/Five/browser/tests/aqlegacy_ftest.txt
  U   Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/base.py
  U   Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/connections.py
  U   Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/functional.py
  U   Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/sandbox.py
  U   Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/utils.py
  U   Zope/branches/elro-parent-pointers/src/Testing/makerequest.py
  U   Zope/branches/elro-parent-pointers/src/ZPublisher/BaseRequest.py
  U   Zope/branches/elro-parent-pointers/src/ZPublisher/Publish.py
  U   Zope/branches/elro-parent-pointers/versions.cfg

-=-
Modified: Zope/branches/elro-parent-pointers/setup.py
===================================================================
--- Zope/branches/elro-parent-pointers/setup.py 2011-10-31 21:12:18 UTC (rev 
123205)
+++ Zope/branches/elro-parent-pointers/setup.py 2011-10-31 21:16:48 UTC (rev 
123206)
@@ -82,6 +82,7 @@
       'zope.deferredimport',
       'zope.event',
       'zope.exceptions',
+      'zope.globalrequest',
       'zope.i18n [zcml]',
       'zope.i18nmessageid',
       'zope.interface',

Modified: Zope/branches/elro-parent-pointers/sources.cfg
===================================================================
--- Zope/branches/elro-parent-pointers/sources.cfg      2011-10-31 21:12:18 UTC 
(rev 123205)
+++ Zope/branches/elro-parent-pointers/sources.cfg      2011-10-31 21:16:48 UTC 
(rev 123206)
@@ -22,6 +22,7 @@
 zExceptions = svn ${buildout:svn-zope-org}/zExceptions/trunk
 zLOG = svn ${buildout:svn-zope-org}/zLOG/trunk
 ZopeUndo = svn ${buildout:svn-zope-org}/ZopeUndo/trunk
+zope.globalrequest = svn ^/zope.globalrequest/trunk
 
 # Deprecated / CMF dependencies
 Products.BTreeFolder2 = svn 
${buildout:svn-zope-org}/Products.BTreeFolder2/trunk

Modified: Zope/branches/elro-parent-pointers/src/OFS/Application.py
===================================================================
--- Zope/branches/elro-parent-pointers/src/OFS/Application.py   2011-10-31 
21:12:18 UTC (rev 123205)
+++ Zope/branches/elro-parent-pointers/src/OFS/Application.py   2011-10-31 
21:16:48 UTC (rev 123206)
@@ -31,6 +31,7 @@
 from webdav.NullResource import NullResource
 from zExceptions import Redirect as RedirectException, Forbidden
 
+from zope.globalrequest import getRequest
 from zope.interface import implements
 
 import Folder
@@ -85,7 +86,7 @@
     def getId(self):
         try:
             return self.REQUEST['SCRIPT_NAME'][1:]
-        except (KeyError, TypeError):
+        except (KeyError, TypeError, AttributeError):
             return self.title
 
     def title_and_id(self):
@@ -184,6 +185,33 @@
         # We're at the base of the path.
         return ('', )
 
+    @property
+    def REQUEST(self):
+        # Return the current request
+        request = self.__dict__.get('REQUEST', None)
+        if request is None:
+            request = getRequest()
+        if request is None:
+            raise AttributeError('REQUEST')
+        return request
+    
+    @REQUEST.setter
+    def REQUEST(self, value):
+        # Set the current request as an attribute (used in tests)
+        self.__dict__['REQUEST'] = value
+
+    @REQUEST.deleter
+    def REQUEST(self):
+        del self.__dict__['REQUEST']
+
+    @property
+    def aq_explicit(self):
+        # aq_explict is a property of acquisition wrappers. As the Application
+        # object is no longer wrapped in a RequestContainer, it must be
+        # supported directly.
+        return self
+
+
 InitializeClass(Application)
 
 

Modified: 
Zope/branches/elro-parent-pointers/src/Products/Five/browser/tests/aqlegacy_ftest.txt
===================================================================
--- 
Zope/branches/elro-parent-pointers/src/Products/Five/browser/tests/aqlegacy_ftest.txt
       2011-10-31 21:12:18 UTC (rev 123205)
+++ 
Zope/branches/elro-parent-pointers/src/Products/Five/browser/tests/aqlegacy_ftest.txt
       2011-10-31 21:16:48 UTC (rev 123206)
@@ -23,8 +23,7 @@
   >>> print browser.contents
   [<Products.Five.metaclass.LegacyAttributes object at ...>,
    <Folder at /test_folder_1_>,
-   <Application at >,
-   <ZPublisher.BaseRequest.RequestContainer object at ...>]
+   <Application at >]
 
 The same goes for browser views that just mix in Acquisition.Explicit:
 
@@ -32,8 +31,7 @@
   >>> print browser.contents
   [<Products.Five.metaclass.ExplicitLegacyAttributes object at ...>,
    <Folder at /test_folder_1_>,
-   <Application at >,
-   <ZPublisher.BaseRequest.RequestContainer object at ...>]
+   <Application at >]
 
 Let's do some more manual tests with the view object.  But first we
 must get it:

Modified: Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/base.py
===================================================================
--- Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/base.py 
2011-10-31 21:12:18 UTC (rev 123205)
+++ Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/base.py 
2011-10-31 21:16:48 UTC (rev 123206)
@@ -21,6 +21,7 @@
 import connections
 import layer
 
+from zope.globalrequest import setRequest, clearRequest
 from zope.interface import implements
 from AccessControl.SecurityManagement import noSecurityManager
 
@@ -106,7 +107,11 @@
 
     def _app(self):
         '''Returns the app object for a test.'''
-        return app()
+        app = Zope2.app()
+        req = utils.newrequest()
+        setRequest(req)
+        connections.register(app)
+        return app
 
     def _setup(self):
         '''Sets up the fixture. Framework authors may
@@ -120,6 +125,7 @@
             self.beforeClose()
         self._close()
         self.logout()
+        clearRequest()
         self.afterClear()
 
     def _close(self):

Modified: 
Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/connections.py
===================================================================
--- Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/connections.py  
2011-10-31 21:12:18 UTC (rev 123205)
+++ Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/connections.py  
2011-10-31 21:16:48 UTC (rev 123206)
@@ -25,10 +25,12 @@
         self._conns = []
 
     def register(self, conn):
-        self._conns.append(conn)
+        connset = self._getConnSet(conn)
+        self._conns.append(connset)
 
     def contains(self, conn):
-        return conn in self._conns
+        connset = self._getConnSet(conn)
+        return connset in self._conns
 
     def __len__(self):
         return len(self._conns)
@@ -37,23 +39,26 @@
         return len(self)
 
     def close(self, conn):
+        connset = self._getConnSet(conn)
         if self.contains(conn):
-            self._conns.remove(conn)
-        self._do_close(conn)
+            self._conns.remove(connset)
+        self._do_close(connset)
 
     def closeAll(self):
-        for conn in self._conns:
-            self._do_close(conn)
+        for connset in self._conns:
+            self._do_close(connset)
         self._conns = []
 
-    def _do_close(self, conn):
-        if hasattr(conn, 'close'):
+    def _do_close(self, connset):
+        for conn in connset:
             conn.close()
+
+    def _getConnSet(self, conn):
+        if hasattr(conn, '_p_jar'):
+            return (conn.REQUEST, conn._p_jar)
         else:
-            conn.REQUEST.close()
-            conn._p_jar.close()
+            return (conn,)
 
-
 registry = ConnectionRegistry()
 register = registry.register
 contains = registry.contains

Modified: 
Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/functional.py
===================================================================
--- Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/functional.py   
2011-10-31 21:12:18 UTC (rev 123205)
+++ Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/functional.py   
2011-10-31 21:16:48 UTC (rev 123206)
@@ -31,14 +31,16 @@
     from AccessControl.SecurityManagement import setSecurityManager
     from zope.site.hooks import getSite
     from zope.site.hooks import setSite
+    from zope.globalrequest import getRequest, setRequest
 
     def wrapped_func(*args, **kw):
-        sm, site = getSecurityManager(), getSite()
+        sm, site, request = getSecurityManager(), getSite(), getRequest()
         try:
             return func(*args, **kw)
         finally:
             setSecurityManager(sm)
             setSite(site)
+            setRequest(request)
     return wrapped_func
 
 

Modified: Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/sandbox.py
===================================================================
--- Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/sandbox.py      
2011-10-31 21:12:18 UTC (rev 123205)
+++ Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/sandbox.py      
2011-10-31 21:16:48 UTC (rev 123206)
@@ -19,7 +19,9 @@
 import utils
 import connections
 
+from zope.globalrequest import setRequest, clearRequest
 
+
 class Sandboxed:
     '''Derive from this class and an xTestCase to make each test
        run in its own ZODB sandbox::
@@ -32,7 +34,8 @@
         '''Returns the app object for a test.'''
         app = Zope2.app(Zope2.sandbox().open())
         AppZapper().set(app)
-        app = utils.makerequest(app)
+        req = utils.newrequest()
+        setRequest(req)
         connections.register(app)
         return app
 
@@ -41,6 +44,7 @@
         AppZapper().clear()
         transaction.abort()
         connections.closeAll()
+        clearRequest()
 
 
 class AppZapper:

Modified: Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/utils.py
===================================================================
--- Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/utils.py        
2011-10-31 21:12:18 UTC (rev 123205)
+++ Zope/branches/elro-parent-pointers/src/Testing/ZopeTestCase/utils.py        
2011-10-31 21:16:48 UTC (rev 123206)
@@ -118,6 +118,16 @@
     return _makerequest(app, stdout=stdout, environ=environ)
 
 
+def newrequest(stdout=sys.stdout):
+    '''Creates a new request for testing'''
+    from Testing.makerequest import newrequest as _newrequest
+    environ = {}
+    environ['SERVER_NAME'] = _Z2HOST or 'nohost'
+    environ['SERVER_PORT'] = '%d' % (_Z2PORT or 80)
+    environ['REQUEST_METHOD'] = 'GET'
+    return _newrequest(stdout=stdout, environ=environ)
+
+
 def appcall(func, *args, **kw):
     '''Calls a function passing 'app' as first argument.'''
     from base import app, close
@@ -150,6 +160,7 @@
     'importObjectFromFile',
     'appcall',
     'makerequest',
+    'newrequest',
     'makelist',
 ]
 

Modified: Zope/branches/elro-parent-pointers/src/Testing/makerequest.py
===================================================================
--- Zope/branches/elro-parent-pointers/src/Testing/makerequest.py       
2011-10-31 21:12:18 UTC (rev 123205)
+++ Zope/branches/elro-parent-pointers/src/Testing/makerequest.py       
2011-10-31 21:16:48 UTC (rev 123206)
@@ -19,8 +19,41 @@
 from sys import stdin, stdout
 from ZPublisher.HTTPRequest import HTTPRequest
 from ZPublisher.HTTPResponse import HTTPResponse
-from ZPublisher.BaseRequest import RequestContainer
+from ExtensionClass import Base 
 
+class RequestContainer(Base): 
+    __roles__=None 
+    def __init__(self,**kw): 
+        for k,v in kw.items(): self.__dict__[k]=v 
+
+
+def newrequest(stdout=stdout, environ=None):
+    """
+    Creates a new request for testing.
+
+    *stdout* is an optional file-like object and is used by
+    REQUEST.RESPONSE. The default is sys.stdout.
+
+    *environ* is an optional mapping to be used in the request.
+    Default is a fresh dictionary. Passing os.environ is not
+    recommended; tests should not pollute the real os.environ.
+    """
+    if environ is None:
+        environ = {}
+    resp = HTTPResponse(stdout=stdout)
+    environ.setdefault('SERVER_NAME', 'foo')
+    environ.setdefault('SERVER_PORT', '80')
+    environ.setdefault('REQUEST_METHOD',  'GET')
+    req = HTTPRequest(stdin, environ, resp)
+    req._steps = ['noobject']  # Fake a published object.
+    req['ACTUAL_URL'] = req.get('URL') # Zope 2.7.4
+    
+    # set Zope3-style default skin so that the request is usable for
+    # Zope3-style view look-ups.
+    from zope.publisher.browser import setDefaultSkin
+    setDefaultSkin(req)
+    return req
+
 def makerequest(app, stdout=stdout, environ=None):
     """
     Adds an HTTPRequest at app.REQUEST, and returns
@@ -47,20 +80,6 @@
     Default is a fresh dictionary. Passing os.environ is not
     recommended; tests should not pollute the real os.environ.
     """
-    if environ is None:
-        environ = {}
-    resp = HTTPResponse(stdout=stdout)
-    environ.setdefault('SERVER_NAME', 'foo')
-    environ.setdefault('SERVER_PORT', '80')
-    environ.setdefault('REQUEST_METHOD',  'GET')
-    req = HTTPRequest(stdin, environ, resp)
-    req._steps = ['noobject']  # Fake a published object.
-    req['ACTUAL_URL'] = req.get('URL') # Zope 2.7.4
-    
-    # set Zope3-style default skin so that the request is usable for
-    # Zope3-style view look-ups.
-    from zope.publisher.browser import setDefaultSkin
-    setDefaultSkin(req)
-
+    req = newrequest(stdout, environ)
     requestcontainer = RequestContainer(REQUEST = req)
     return app.__of__(requestcontainer)

Modified: Zope/branches/elro-parent-pointers/src/ZPublisher/BaseRequest.py
===================================================================
--- Zope/branches/elro-parent-pointers/src/ZPublisher/BaseRequest.py    
2011-10-31 21:12:18 UTC (rev 123205)
+++ Zope/branches/elro-parent-pointers/src/ZPublisher/BaseRequest.py    
2011-10-31 21:16:48 UTC (rev 123206)
@@ -41,23 +41,6 @@
     return urllib_quote(text, '/+@')
 
 try:
-    from ExtensionClass import Base
-    from ZPublisher.Converters import type_converters
-    class RequestContainer(Base):
-        __roles__=None
-        def __init__(self,**kw):
-            for k,v in kw.items(): self.__dict__[k]=v
-
-        def manage_property_types(self):
-            return type_converters.keys()
-
-except ImportError:
-    class RequestContainer:
-        __roles__=None
-        def __init__(self,**kw):
-            for k,v in kw.items(): self.__dict__[k]=v
-
-try:
     from AccessControl.ZopeSecurityPolicy import getRoles
 except ImportError:
     def getRoles(container, name, value, default):
@@ -411,10 +394,6 @@
             return response.forbiddenError(self['URL'])
 
         # Traverse the URL to find the object:
-        if hasattr(object, '__of__'):
-            # Try to bind the top-level object to the request
-            # This is how you get 'self.REQUEST'
-            object=object.__of__(RequestContainer(REQUEST=request))
         parents.append(object)
 
         steps=self.steps

Modified: Zope/branches/elro-parent-pointers/src/ZPublisher/Publish.py
===================================================================
--- Zope/branches/elro-parent-pointers/src/ZPublisher/Publish.py        
2011-10-31 21:12:18 UTC (rev 123205)
+++ Zope/branches/elro-parent-pointers/src/ZPublisher/Publish.py        
2011-10-31 21:16:48 UTC (rev 123206)
@@ -22,6 +22,7 @@
 from zope.publisher.interfaces.browser import IBrowserPage
 from zope.publisher.skinnable import setDefaultSkin
 from zope.security.management import newInteraction, endInteraction
+from zope.globalrequest import setRequest, clearRequest
 
 from .mapply import mapply
 from .maybe_lock import allocate_lock
@@ -237,13 +238,14 @@
 
             if request is None:
                 request=Request(stdin, environ, response)
-
+            
             # make sure that the request we hand over has the
             # default layer/skin set on it; subsequent code that
             # wants to look up views will likely depend on it
             if ISkinnable.providedBy(request):
                 setDefaultSkin(request)
 
+            setRequest(request)
             response = publish(request, module_name, after_list, debug=debug)
         except (SystemExit, ImportError):
             # XXX: Rendered ImportErrors were never caught here because they
@@ -271,6 +273,7 @@
         if after_list[0] is not None: after_list[0]()
 
     finally:
+        clearRequest()
         if request is not None: request.close()
 
     if must_die:

Modified: Zope/branches/elro-parent-pointers/versions.cfg
===================================================================
--- Zope/branches/elro-parent-pointers/versions.cfg     2011-10-31 21:12:18 UTC 
(rev 123205)
+++ Zope/branches/elro-parent-pointers/versions.cfg     2011-10-31 21:16:48 UTC 
(rev 123206)
@@ -40,4 +40,5 @@
 repoze.retry = 1.0
 repoze.tm2 = 1.0b1
 repoze.who = 2.0b1
+zope.globalrequest = 1.0
 zope.testbrowser = 3.11.1

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to