It is often favorable to have a set of site wide defines
that can occasionally be redefined for special purposes.

The attached patch adds a "%redefine" directive to ZConfig's
"cfgparser". "%redefine" behaves exactly like "define" but
does not check whether the name is already defined.

-- 
Dieter
--- :cfgparser.py	2003-12-22 07:27:36.000000000 +0100
+++ cfgparser.py	2004-01-16 15:41:40.000000000 +0100
@@ -138,7 +138,7 @@
         if not m:
             self.error("missing or unrecognized directive")
         name, arg = m.group('key', 'value')
-        if name not in ("define", "import", "include"):
+        if name not in ("define", "import", "include", "redefine"):
             self.error("unknown directive: " + `name`)
         if not arg:
             self.error("missing argument to %%%s directive" % name)
@@ -146,6 +146,8 @@
             self.handle_include(section, arg)
         elif name == "define":
             self.handle_define(section, arg)
+        elif name == "redefine":
+            self.handle_define(section, arg, False)
         elif name == "import":
             self.handle_import(section, arg)
         else:
@@ -160,13 +162,13 @@
         newurl = ZConfig.url.urljoin(self.url, rest)
         self.context.includeConfiguration(section, newurl, self.defs)
 
-    def handle_define(self, section, rest):
+    def handle_define(self, section, rest, preventOverride=True):
         parts = rest.split(None, 1)
         defname = parts[0].lower()
         defvalue = ''
         if len(parts) == 2:
             defvalue = parts[1]
-        if self.defs.has_key(defname):
+        if preventOverride and self.defs.has_key(defname):
             self.error("cannot redefine " + `defname`)
         if not isname(defname):
             self.error("not a substitution legal name: " + `defname`)
_______________________________________________
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to