[Zope-Checkins] CVS: Packages/ZConfig - ApacheStyle.py:1.9.2.2 Context.py:1.15.10.3

Fred L. Drake, Jr. fred@zope.com
Tue, 10 Dec 2002 11:46:09 -0500


Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv5739

Modified Files:
      Tag: zconfig-schema-devel-branch
	ApacheStyle.py Context.py 
Log Message:
Refactor: move syntax support out of resource management even more.

=== Packages/ZConfig/ApacheStyle.py 1.9.2.1 => 1.9.2.2 ===
--- Packages/ZConfig/ApacheStyle.py:1.9.2.1	Tue Dec 10 10:57:19 2002
+++ Packages/ZConfig/ApacheStyle.py	Tue Dec 10 11:46:08 2002
@@ -3,11 +3,13 @@
 import urlparse
 
 from ZConfig import ConfigurationError, ConfigurationSyntaxError
+from ZConfig.Substitution import isname, substitute
 
 
 def Parse(resource, context, section):
     lineno = 0
     stack = []
+    defs = {}
     while 1:
         line = resource.file.readline()
         if not line:
@@ -85,14 +87,19 @@
                 context.includeConfiguration(section, newurl)
             elif name == "define":
                 parts = arg.split(None, 1)
-                defname = parts[0]
+                defname = parts[0].lower()
                 defvalue = ''
                 if len(parts) == 2:
                     defvalue = parts[1]
-                try:
-                    resource.define(defname, defvalue)
-                except ConfigurationError, e:
-                    raise ConfigurationSyntaxError(e[0], resource.url, lineno)
+                if defs.has_key(defname):
+                    raise ConfigurationSyntaxError(
+                        "cannot redefine " + `defname`,
+                        resource.url, lineno)
+                if not isname(defname):
+                    raise ConfigurationSyntaxError(
+                        "not a substitution legal name: " + `defname`,
+                        resource.url, lineno)
+                defs[defname] = defvalue
             else:
                 assert 0, "unexpected directive for " + `line`
             continue
@@ -106,7 +113,7 @@
         if not value:
             value = ''
         else:
-            value = resource.substitute(value)
+            value = substitute(value, defs)
         try:
             section.addValue(key, value)
         except ConfigurationError, e:


=== Packages/ZConfig/Context.py 1.15.10.2 => 1.15.10.3 ===
--- Packages/ZConfig/Context.py:1.15.10.2	Tue Dec 10 11:09:12 2002
+++ Packages/ZConfig/Context.py	Tue Dec 10 11:46:08 2002
@@ -7,7 +7,6 @@
 from ZConfig import loader
 
 from Config import Configuration
-from Substitution import isname, substitute
 
 
 class Context(loader.BaseLoader):
@@ -28,9 +27,6 @@
     def createToplevelSection(self, url):
         return Configuration(None, None, None, url)
 
-    def createResource(self, file, url):
-        return DefiningResource(file, url)
-
     def getDelegateType(self, type):
         # Applications must provide delegation typing information by
         # overriding the Context.getDelegateType() method.
@@ -150,23 +146,3 @@
             if sect.delegate is not None:
                 sect.finish()
         self._all_sections = None
-
-
-class DefiningResource(loader.Resource):
-    def __init__(self, file, url):
-        loader.Resource.__init__(self, file, url)
-        self._definitions = {}
-
-    def define(self, name, value):
-        key = name.lower()
-        if self._definitions.has_key(key):
-            raise ZConfig.ConfigurationError("cannot redefine " + `name`)
-        if not isname(name):
-            raise ZConfig.ConfigurationError(
-                "not a substitution legal name: " + `name`)
-        self._definitions[key] = value
-
-    def substitute(self, s):
-        # XXX  I don't really like calling this substitute(),
-        # XXX  but it will do for now.
-        return substitute(s, self._definitions)