[Zope3-checkins] CVS: Zope3/src/zope/configuration - meta.py:1.3 xmlconfig.py:1.4
Jim Fulton
jim@zope.com
Fri, 27 Dec 2002 19:02:30 -0500
Update of /cvs-repository/Zope3/src/zope/configuration
In directory cvs.zope.org:/tmp/cvs-serv18711
Modified Files:
meta.py xmlconfig.py
Log Message:
Change the configuration machinery so that:
- The root element, zopeConfigure can be in any namespace.
- The standard include directive works in any namespace, unless a
namespace provides it's own include.
These changes allow zcml files for which all directives other than
zopeConfigure and include are from some single namespace to avoid use
of namespace prefixes and to require only a single namespace
declaration, as in::
<zopeConfigure xmlns="http://namespaces.zope.org/browser">
<view factory = ".permissionwidget.SinglePermissionWidget"
for = "zope.app.interfaces.security.IPermissionField"
name = "edit"
/>
<view factory = ".permissionwidget.DisplayWidget"
for = "zope.app.interfaces.security.IPermissionField"
name = "display"
/>
<include package=".grants" />
</zopeConfigure>
=== Zope3/src/zope/configuration/meta.py 1.2 => 1.3 ===
--- Zope3/src/zope/configuration/meta.py:1.2 Wed Dec 25 09:13:33 2002
+++ Zope3/src/zope/configuration/meta.py Fri Dec 27 19:02:29 2002
@@ -202,7 +202,16 @@
try:
callable, subs = _directives[_name]
except KeyError:
- raise InvalidDirective(_name)
+ # Maybe the directive is a multi-namespace directive
+ # (like include)
+ try:
+ if _custom_directives:
+ callable, subs = _custom_directives[('*', _name[1])]
+ else:
+ raise InvalidDirective(_name)
+
+ except KeyError:
+ raise InvalidDirective(_name)
return _exe(callable, subs, _context, kw)
=== Zope3/src/zope/configuration/xmlconfig.py 1.3 => 1.4 ===
--- Zope3/src/zope/configuration/xmlconfig.py:1.3 Fri Dec 27 18:25:18 2002
+++ Zope3/src/zope/configuration/xmlconfig.py Fri Dec 27 19:02:29 2002
@@ -74,7 +74,7 @@
class ConfigurationHandler(ContentHandler):
- __top_name = 'http://namespaces.zope.org/zope', 'zopeConfigure'
+ __top_name = 'zopeConfigure'
def __init__(self, actions, context, directives=None, testing=0):
self.__stack = []
@@ -96,7 +96,7 @@
def startElementNS(self, name, qname, attrs):
stack = self.__stack
if not stack:
- if name != self.__top_name:
+ if name[1] != self.__top_name:
raise ZopeXMLConfigurationError(
self.__locator, "Invalid top element: %s %s" % name)
@@ -281,7 +281,7 @@
self._actions = []
- self._directives = {('http://namespaces.zope.org/zope', 'include'):
+ self._directives = {('*', 'include'):
(self.include, {})}
f = open(file_name)