[Zodb-checkins] CVS: Packages/ZConfig - matcher.py:1.1.2.17

Fred L. Drake, Jr. fred@zope.com
Fri, 13 Dec 2002 09:53:48 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	matcher.py 
Log Message:
Add __name__ and __type__ to the SectionValue, and give it a
reasonable __repr__().


=== Packages/ZConfig/matcher.py 1.1.2.16 => 1.1.2.17 ===
--- Packages/ZConfig/matcher.py:1.1.2.16	Thu Dec 12 17:50:48 2002
+++ Packages/ZConfig/matcher.py	Fri Dec 13 09:53:47 2002
@@ -129,7 +129,7 @@
                 values[i] = [dt.convert(s) for s in values[i]]
             else:
                 values[i] = dt.convert(values[i])
-        v = SectionValue(attrnames, values)
+        v = self.createValue(attrnames)
         # XXX  Really should delay this until after all the
         # XXX  sibling SectionValue instances have been created and
         # XXX  we're ready to construct the parent.
@@ -137,17 +137,21 @@
             v = self.info.handler(v)
         return v
 
+    def createValue(self, attrnames):
+        return SectionValue(attrnames, self._values, None, self.type)
+
 
 class SectionMatcher(BaseMatcher):
-    def __init__(self, info, name):
-        if name is not None:
+    def __init__(self, info, type, name):
+        if name or info.allowUnnamed():
             self.name = name
-        elif info.allowUnnamed():
-            self.name = None
         else:
             raise ZConfig.ConfigurationError(
-                `info.name` + " sections may not be unnamed")
-        BaseMatcher.__init__(self, info, info.sectiontype)
+                `type.name` + " sections may not be unnamed")
+        BaseMatcher.__init__(self, info, type)
+
+    def createValue(self, attrnames):
+        return SectionValue(attrnames, self._values, self.name, self.type)
 
 
 class SchemaMatcher(BaseMatcher):
@@ -164,9 +168,21 @@
 class SectionValue:
     """Generic 'bag-of-values' object for a section."""
 
-    def __init__(self, attrnames, values):
+    def __init__(self, attrnames, values, name, type):
         self._attrnames = attrnames
         self._values = values
+        self.__name__ = name
+        self.__type__ = type
+
+    def __repr__(self):
+        if self.__name__:
+            # probably unique for a given config file; more readable than id()
+            name = `self.__name__`
+        else:
+            # identify uniquely
+            name = "at %#x" % id(self)
+        clsname = self.__class__.__name__
+        return "<%s for %s %s>" % (clsname, self.__type__.name, name)
 
     def __len__(self):
         return len(self._values)