[Zope-Checkins] CVS: Zope/lib/python/ZPublisher - BaseRequest.py:1.54

Jim Fulton cvs-admin at zope.org
Fri Nov 28 11:46:48 EST 2003


Update of /cvs-repository/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv5513/lib/python/ZPublisher

Modified Files:
	BaseRequest.py 
Log Message:
Reimplemented to use new api for getting roles, rather than using the
__roles__ attribute directly.  This further links the publisher to the
Zope application. :(

Perhsps in Zope 2.9, we can switch to using the Zope 3 publisher.


=== Zope/lib/python/ZPublisher/BaseRequest.py 1.53 => 1.54 ===
--- Zope/lib/python/ZPublisher/BaseRequest.py:1.53	Tue Nov 18 08:17:17 2003
+++ Zope/lib/python/ZPublisher/BaseRequest.py	Fri Nov 28 11:46:47 2003
@@ -31,12 +31,19 @@
         def manage_property_types(self):
             return type_converters.keys()
 
-except:
+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):
+        return getattr(value, '__roles__', default)
+
+
 _marker=[]
 class BaseRequest:
     """Provide basic ZPublisher request management
@@ -219,14 +226,14 @@
         object=parents[-1]
         del parents[:]
 
-        roles = getattr(object, '__roles__', UNSPECIFIED_ROLES)
+        roles = getRoles(None, None, object, UNSPECIFIED_ROLES)
 
         # if the top object has a __bobo_traverse__ method, then use it
         # to possibly traverse to an alternate top-level object.
         if hasattr(object,'__bobo_traverse__'):
             try:
                 object=object.__bobo_traverse__(request)
-                roles =getattr(object, '__roles__', UNSPECIFIED_ROLES)
+                roles = getRoles(None, None, object, UNSPECIFIED_ROLES)
             except: pass
 
         if not path and not method:
@@ -281,9 +288,9 @@
                     entry_name = method
                     method = 'index_html'
                 else:
-                    if (hasattr(object, '__call__') and
-                        hasattr(object.__call__,'__roles__')):
-                        roles=object.__call__.__roles__
+                    if (hasattr(object, '__call__')):
+                        roles = getRoles(object, '__call__', object.__call__,
+                                         roles)
                     if request._hacked_path:
                         i=URL.rfind('/')
                         if i > 0: response.setBase(URL[:i])
@@ -358,13 +365,9 @@
                         "The object at %s is not publishable." % URL
                         )
 
-                r = getattr(subobject, '__roles__', UNSPECIFIED_ROLES)
-                if r is not UNSPECIFIED_ROLES:
-                    roles = r
-                elif not got:
-                    # We got the subobject as an attribute, not an item,
-                    # so we should check "next to it" for __roles__.
-                    roles = getattr(object, entry_name+'__roles__', roles)
+                roles = getRoles(
+                    object, (not got) and entry_name or None, subobject,
+                    roles)
 
                 # Promote subobject to object
                 object=subobject




More information about the Zope-Checkins mailing list