[Zope3-checkins] CVS: Packages/ZConfig - matcher.py:1.1.2.8
Fred L. Drake, Jr.
fred@zope.com
Wed, 11 Dec 2002 16:25:20 -0500
Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv31131
Modified Files:
Tag: zconfig-schema-devel-branch
matcher.py
Log Message:
More tests, some cleanup.
=== Packages/ZConfig/matcher.py 1.1.2.7 => 1.1.2.8 ===
--- Packages/ZConfig/matcher.py:1.1.2.7 Wed Dec 11 16:07:51 2002
+++ Packages/ZConfig/matcher.py Wed Dec 11 16:25:19 2002
@@ -84,19 +84,23 @@
"""Check the constraints of the section and convert to an application
object."""
length = len(self.info)
- values = [None] * length
- keys = [None] * length
+ values = self._values
+ attrnames = [None] * length
for i in range(length):
key, ci = self.info[i]
- keys[i] = ci.attribute
- v = self._values[i]
+ attrnames[i] = ci.attribute
+ v = values[i]
if v is None and ci.minOccurs:
- if key:
- s = `key`
+ default = ci.getdefault()
+ if default is None:
+ if key:
+ s = `key`
+ else:
+ s = "section type " + `ci.typename`
+ raise ZConfig.ConfigurationError(
+ "no values for %s; %s required" % (s, ci.minOccurs))
else:
- s = "section type " + `ci.typename`
- raise ZConfig.ConfigurationError(
- "no values for %s; %s required" % (s, ci.minOccurs))
+ v = values[i] = default[:]
if ci.ismulti() and len(v) < ci.minOccurs:
raise ZConfig.ConfigurationError(
"not enough values for %s; %d found, %d required"
@@ -106,19 +110,19 @@
v = ci.getdefault()[:]
else:
v = ci.getdefault()
- self._values[i] = v
- return self.constuct(keys, values)
+ values[i] = v
+ return self.constuct(attrnames)
- def constuct(self, keys, values):
- length = len(self.info)
- for i in range(length):
+ def constuct(self, attrnames):
+ values = self._values
+ for i in range(len(values)):
name, ci = self.info[i]
dt = ci.datatype
if ci.ismulti():
- values[i] = [dt.convert(s) for s in self._values[i]]
+ values[i] = [dt.convert(s) for s in values[i]]
else:
- values[i] = dt.convert(self._values[i])
- v = SectionValue(keys, values)
+ values[i] = dt.convert(values[i])
+ v = SectionValue(attrnames, values)
# 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.
@@ -135,12 +139,12 @@
class SectionValue:
"""Generic 'bag-of-values' object for a section."""
- def __init__(self, keys, values):
- self._keys = keys
+ def __init__(self, attrnames, values):
+ self._attrnames = attrnames
self._values = values
def __len__(self):
- return len(self._keys)
+ return len(self._values)
def __getitem__(self, index):
if isinstance(index, types.SliceType):
@@ -149,7 +153,7 @@
def __getattr__(self, name):
try:
- i = self._keys.index(name)
+ i = self._attrnames.index(name)
except ValueError:
raise AttributeError, name
return self._values[i]