[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser - meta.zcml:1.6 viewmeta.py:1.6
Jim Fulton
jim@zope.com
Tue, 31 Dec 2002 13:27:29 -0500
Update of /cvs-repository/Zope3/src/zope/app/publisher/browser
In directory cvs.zope.org:/tmp/cvs-serv1916/src/zope/app/publisher/browser
Modified Files:
meta.zcml viewmeta.py
Log Message:
Hold on to your butts! :)
In an effort to make zcml view definitions even easier to understand
(see
http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/ZCMLBrowserViewDirectiveSimplification
)
I've finished a long-overdue refactoring of the configuration
directives for defining views. The logic is now a good bit less
complicated.
I also simplified the way security assertions on views were
handled. To make this work right, I had to fix a bug in the
publication machinery. Now, as objects are traversed, the results of
traversal are put in security proxies. This is really necessary to
treat URLs as "untrusted code", which they are.
I updated the meta-configuration directives for views and ran the zcml
documentation utility, so there is now documentation for the (new)
view directives. See the files 'page', 'pages', and 'view', in
'doc/zcml/namespaces.zope.org/browser'.
I feel these changes are highly desireable for the alpha, but they are
significant enough that the chance of breakage is a lot higher than
I'd like just before the alpha. I'd appreciate it if folks would let
me know if I've broken anything.
=== Zope3/src/zope/app/publisher/browser/meta.zcml 1.5 => 1.6 === (690/790 lines abridged)
--- Zope3/src/zope/app/publisher/browser/meta.zcml:1.5 Mon Dec 30 18:33:46 2002
+++ Zope3/src/zope/app/publisher/browser/meta.zcml Tue Dec 31 13:26:58 2002
@@ -2,13 +2,20 @@
<directives namespace="http://namespaces.zope.org/browser">
- <directive name="page"
- handler="zope.app.publisher.browser.viewmeta.page"
- >
+ <directive name="page" handler=".viewmeta.page">
+
+ <description>
+ The page directive is used to create views that provide a
+ single url or page.
+
+ The page directive creates a new view class from a given
+ template and/or class and registers it.
+ </description>
+
<attribute name="name" required="yes">
<description>
- The name of the view defined by the page.
+ The name of the page (view).
The name shows up in URLs/paths. For example 'foo' or
'foo.html'. This attribute is required unless you use the
@@ -18,7 +25,7 @@
provide a view name, you shouldn't use
extensions.
</description>
- </attribute>
+ </attribute>
<attribute name="for" required="yes">
<description>
@@ -30,41 +37,34 @@
"zope.interface.Interface". To provide a page for all
objects, use "*".
</description>
- </attribute>
+ </attribute>
<attribute name="permission" required="yes">
<description>
The permission needed to use the view.
-
- This attribute is required.
-
</description>
[-=- -=- -=- 690 lines omitted -=- -=- -=-]
@@ -459,7 +682,7 @@
This is, effectively, an id.
</description>
- </attribute>
+ </attribute>
<attribute
@@ -505,7 +728,7 @@
The url is relative to the object the menu is being
displayed for.
</description>
- </attribute>
+ </attribute>
<attribute
name="title"
@@ -520,7 +743,7 @@
A UI may display this with the item or display it when the
user requests more assistance.
</description>
- </attribute>
+ </attribute>
<attribute name="permission" required="no">
<description>
@@ -532,7 +755,7 @@
determine whether the url is accessable to the current
user. This can be avoided if the permission is given explicitly.
</description>
- </attribute>
+ </attribute>
<attribute name="filter" required="no">
<description>
@@ -550,9 +773,9 @@
The menu item will not be displayed if there is a filter
and the filter evaluates to a false value.
</description>
- </attribute>
- </subdirective>
- </directive>
+ </attribute>
+ </subdirective>
+ </directive>
<directive name="menuItem"
handler="
=== Zope3/src/zope/app/publisher/browser/viewmeta.py 1.5 => 1.6 === (580/680 lines abridged)
--- Zope3/src/zope/app/publisher/browser/viewmeta.py:1.5 Mon Dec 30 21:52:01 2002
+++ Zope3/src/zope/app/publisher/browser/viewmeta.py Tue Dec 31 13:26:58 2002
@@ -16,7 +16,9 @@
$Id$
"""
-# XXX this will need to be refactored soon. :)
+import os
+
+from zope.exceptions import NotFoundError
from zope.security.proxy import Proxy
from zope.security.checker import CheckerPublic, NamesChecker, Checker
@@ -95,89 +97,45 @@
# page
-def _handle_permission(_context, permission, actions):
- if permission == 'zope.Public':
- permission = CheckerPublic
- else:
- actions.append(Action(discriminator = None, callable = checkPermission,
- args = (None, permission)))
-
- return permission
-
-def _handle_allowed_interface(_context, allowed_interface, permission,
- required, actions):
- # Allow access for all names defined by named interfaces
- if allowed_interface.strip():
- for i in allowed_interface.strip().split():
- i = _context.resolve(i)
- actions .append(
- Action(discriminator = None, callable = handler,
- args = ('Interfaces', 'provideInterface', None, i)
- ))
- for name in i:
- required[name] = permission
-
-def _handle_allowed_attributes(_context, allowed_attributes, permission,
- required):
- # Allow access for all named attributes
- if allowed_attributes.strip():
- for name in allowed_attributes.strip().split():
- required[name] = permission
-
-def _handle_for(_context, for_, actions):
- if for_ == '*':
- for_ = None
-
[-=- -=- -=- 580 lines omitted -=- -=- -=-]
+ for i in allowed_interface.strip().split():
+ i = _context.resolve(i)
+ actions .append(
+ Action(discriminator = None, callable = handler,
+ args = ('Interfaces', 'provideInterface', None, i)
+ ))
+ for name in i:
+ required[name] = permission
+
+def _handle_allowed_attributes(_context, allowed_attributes, permission,
+ required):
+ # Allow access for all named attributes
+ if allowed_attributes.strip():
+ for name in allowed_attributes.strip().split():
+ required[name] = permission
+
+def _handle_for(_context, for_, actions):
+ if for_ == '*':
+ for_ = None
+
+ if for_ is not None:
+ for_ = _context.resolve(for_)
+
+ actions .append(
+ Action(discriminator = None, callable = handler,
+ args = ('Interfaces', 'provideInterface', None, for_)
+ ))
+
+ return for_
+
+class simple(BrowserView):
+
+ __implements__ = IBrowserPublisher, BrowserView.__implements__
+
+ def publishTraverse(self, request, name):
+ raise NotFoundError(self, name, request)
+
+ def __call__(self, *a, **k):
+ # If a class doesn't provide it's own call, then get the attribute
+ # given by the browser default.
+
+ attr = self.__page_attribute__
+ if attr == '__call__':
+ raise AttributeError("__call__")
+
+ meth = getattr(self, attr)
+ return meth(*a, **k)
+
+
+