[Zope3-checkins] CVS: Zope/lib/python/ZConfig - matcher.py:1.7
Fred L. Drake, Jr.
fred@zope.com
Thu, 6 Feb 2003 11:46:08 -0500
Update of /cvs-repository/Zope/lib/python/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv22553
Modified Files:
matcher.py
Log Message:
Save the "matcher" object for a section, and provide APIs to get the matcher
and the section type information from a SectionValue.
=== Zope/lib/python/ZConfig/matcher.py 1.6 => 1.7 ===
--- Zope/lib/python/ZConfig/matcher.py:1.6 Wed Jan 15 10:25:14 2003
+++ Zope/lib/python/ZConfig/matcher.py Thu Feb 6 11:45:36 2003
@@ -120,6 +120,8 @@
object."""
length = len(self.type)
values = self._values
+ # XXX attrnames should be provided by the type, so it can be
+ # computed once per section type
attrnames = [None] * length
for i in range(length):
key, ci = self.type[i]
@@ -167,7 +169,7 @@
v = []
for s in values[i]:
if s is not None:
- v.append(s._type.datatype(s))
+ v.append(s.getSectionDefinition().datatype(s))
else:
v.append(None)
elif ci.name == '+':
@@ -178,7 +180,7 @@
v = [vi.convert(ci.datatype) for vi in values[i]]
elif ci.issection():
if values[i] is not None:
- v = values[i]._type.datatype(values[i])
+ v = values[i].getSectionDefinition().datatype(values[i])
else:
v = None
elif name == '+':
@@ -195,7 +197,7 @@
return self.createValue(attrnames)
def createValue(self, attrnames):
- return SectionValue(attrnames, self._values, None, self.type)
+ return SectionValue(attrnames, self._values, None, self)
class SectionMatcher(BaseMatcher):
@@ -208,7 +210,7 @@
BaseMatcher.__init__(self, info, type, handlers)
def createValue(self, attrnames):
- return SectionValue(attrnames, self._values, self.name, self.type)
+ return SectionValue(attrnames, self._values, self.name, self)
class SchemaMatcher(BaseMatcher):
@@ -232,12 +234,12 @@
before attempting to modify self.
"""
- def __init__(self, attrnames, values, name, type):
+ def __init__(self, attrnames, values, name, matcher):
d = self.__dict__
d['_attrnames'] = attrnames
d['_values'] = values
d['_name'] = name
- d['_type'] = type
+ d['_matcher'] = matcher
def __repr__(self):
if self._name:
@@ -247,7 +249,7 @@
# identify uniquely
name = "at %#x" % id(self)
clsname = self.__class__.__name__
- return "<%s for %s %s>" % (clsname, self._type.name, name)
+ return "<%s for %s %s>" % (clsname, self._matcher.type.name, name)
def __len__(self):
return len(self._values)
@@ -289,4 +291,10 @@
return self._name
def getSectionType(self):
- return self._type.name
+ return self._matcher.type.name
+
+ def getSectionDefinition(self):
+ return self._matcher.type
+
+ def getSectionMatcher(self):
+ return self._matcher