[Zope3-checkins] CVS: Packages/ZConfig - Context.py:1.15.10.6 cfgparser.py:1.1.2.3 loader.py:1.1.2.5

Fred L. Drake, Jr. fred@zope.com
Tue, 10 Dec 2002 16:33:40 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	Context.py cfgparser.py loader.py 
Log Message:
Change the interface between the parser and the context so that the context
is invoked for both section start and end.


=== Packages/ZConfig/Context.py 1.15.10.5 => 1.15.10.6 ===
--- Packages/ZConfig/Context.py:1.15.10.5	Tue Dec 10 14:50:03 2002
+++ Packages/ZConfig/Context.py	Tue Dec 10 16:33:39 2002
@@ -19,9 +19,7 @@
     # subclass-support API
 
     def createNestedSection(self, section, type, name, delegatename):
-        if name:
-            name = name.lower()
-        return Configuration(section, type.lower(), name, section.url)
+        return Configuration(section, type, name, section.url)
 
     def createToplevelSection(self, url):
         return Configuration(None, None, None, url)
@@ -52,10 +50,7 @@
         finally:
             r.close()
 
-    def nestSection(self, section, type, name, delegatename):
-        if name:
-            name = name.lower()
-        type = type.lower()
+    def startSection(self, section, type, name, delegatename):
         if name and self._named_sections.has_key(name):
             # Make sure sections of the same name are not defined
             # twice in the same resource, and that once a name has
@@ -82,6 +77,9 @@
         if name:
             self._named_sections[name] = newsect
         return newsect
+
+    def endSection(self, parent, type, name, delegatename, section):
+        section.finish()
 
     # internal helpers
 


=== Packages/ZConfig/cfgparser.py 1.1.2.2 => 1.1.2.3 ===
--- Packages/ZConfig/cfgparser.py:1.1.2.2	Tue Dec 10 14:17:55 2002
+++ Packages/ZConfig/cfgparser.py	Tue Dec 10 16:33:39 2002
@@ -17,7 +17,7 @@
         self.file = resource.file
         self.url = resource.url
         self.lineno = 0
-        self.stack = []
+        self.stack = []   # [(type, name, delegatename, prevmatcher), ...]
         self.defs = {}
 
     def nextline(self):
@@ -69,13 +69,16 @@
         if not m:
             self.error("malformed section header")
         type, name, delegatename = m.group('type', 'name', 'delegatename')
+        type = type.lower()
+        if name:
+            name = name.lower()
         try:
-            newsect = self.context.nestSection(section, type, name,
-                                               delegatename)
+            newsect = self.context.startSection(section, type, name,
+                                                delegatename)
         except ConfigurationError, e:
             self.error(e[0])
         if not isempty:
-            self.stack.append(section)
+            self.stack.append((type, name, delegatename, section))
             return newsect
         else:
             return section
@@ -84,13 +87,15 @@
         if not self.stack:
             self.error("unexpected section end")
         type = rest.rstrip().lower()
-        if type != section.type:
+        opentype, name, delegatename, prevsection = self.stack.pop()
+        if type != opentype:
             self.error("unbalanced section end")
         try:
-            section.finish()
+            self.context.endSection(
+                prevsection, type, name, delegatename, section)
         except ConfigurationError, e:
             self.error(e[0])
-        return self.stack.pop()
+        return prevsection
 
     def handle_key_value(self, section, rest):
         m = _keyvalue_rx.match(rest)


=== Packages/ZConfig/loader.py 1.1.2.4 => 1.1.2.5 ===
--- Packages/ZConfig/loader.py:1.1.2.4	Tue Dec 10 15:33:11 2002
+++ Packages/ZConfig/loader.py	Tue Dec 10 16:33:39 2002
@@ -79,9 +79,13 @@
         self._parse_resource(sm, resource)
         return sm.finish()
 
-    def nestSection(self, section, type, name, delegatename):
+    def startSection(self, parent, type, name, delegatename):
         if delegatename:
             raise NotImpementedError("section delegation is not yet supported")
+
+    def endSection(self, parent, type, name, delegatename, matcher):
+        assert not delegatename
+        sectvalue = matcher.finish()
 
     def includeConfiguration(self, section, url):
         r = self.openResource(url)