[Zodb-checkins] CVS: ZODB3/ZConfig - schema.py:1.15

Fred L. Drake, Jr. fred@zope.com
Thu, 16 Jan 2003 12:16:59 -0500


Update of /cvs-repository/ZODB3/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv22321

Modified Files:
	schema.py 
Log Message:
Minor refactoring: don't repeat a test and error in four places; move
it to a helper method.


=== ZODB3/ZConfig/schema.py 1.14 => 1.15 ===
--- ZODB3/ZConfig/schema.py:1.14	Wed Jan 15 10:25:14 2003
+++ ZODB3/ZConfig/schema.py	Thu Jan 16 12:16:55 2003
@@ -454,31 +454,25 @@
             self._stack[-1].description = data
 
     def start_key(self, attrs):
-        if not self._stack:
-            self.error(
-                "cannot define top-level keys in a schema " + self._top_level)
+        self._check_not_toplevel("key")
         BaseParser.start_key(self, attrs)
 
     def start_multikey(self, attrs):
-        if not self._stack:
-            self.error(
-                "cannot define top-level multikeys in a schema "
-                + self._top_level)
+        self._check_not_toplevel("multikey")
         BaseParser.start_multikey(self, attrs)
 
     def start_section(self, attrs):
-        if not self._stack:
-            self.error(
-                "cannot define top-level sections in a schema "
-                + self._top_level)
+        self._check_not_toplevel("section")
         BaseParser.start_section(self, attrs)
 
     def start_multisection(self, attrs):
-        if not self._stack:
-            self.error(
-                "cannot define top-level multisections in a schema "
-                + self._top_level)
+        self._check_not_toplevel("multisection")
         BaseParser.start_multisection(self, attrs)
+
+    def _check_not_toplevel(self, what):
+        if not self._stack:
+            self.error("cannot define top-level %s in a schema %s"
+                       % (what, self._top_level))
 
 
 class ComponentParser(BaseComponentParser):