[Zodb-checkins] CVS: StandaloneZConfig/ZConfig - info.py:1.25
schema.py:1.36
Fred L. Drake, Jr.
fred at zope.com
Thu Apr 15 00:59:40 EDT 2004
Update of /cvs-repository/StandaloneZConfig/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv5005
Modified Files:
info.py schema.py
Log Message:
Fix two bugs related to keys and multikeys with name="+" with default
values:
- When specifying defaults, the relevant keytype was not applied to
the keys at all.
- When a schema defines a key or multikey with name="+" and default
values, there are some weird results of allowing a derived
sectiontype to change the keytype.
The original keys need to be re-converted in the new context to
allow the new keytype to apply; this can only be done using the
original values of the key= attribute, since the result of the
initial keytype conversion may not be legal input for the new
keytype.
=== StandaloneZConfig/ZConfig/info.py 1.24 => 1.25 ===
--- StandaloneZConfig/ZConfig/info.py:1.24 Thu Apr 15 00:04:01 2004
+++ StandaloneZConfig/ZConfig/info.py Thu Apr 15 00:59:09 2004
@@ -101,6 +101,8 @@
class BaseKeyInfo(BaseInfo):
+ _rawdefaults = None
+
def __init__(self, name, datatype, minOccurs, maxOccurs, handler,
attribute):
assert minOccurs is not None
@@ -140,6 +142,12 @@
raise NotImplementedError(
"add_valueinfo() must be implemented by subclasses of BaseKeyInfo")
+ def prepare_raw_defaults(self):
+ assert self.name == "+"
+ if self._rawdefaults is None:
+ self._rawdefaults = self._default
+ self._default = {}
+
class KeyInfo(BaseKeyInfo):
@@ -165,6 +173,12 @@
else:
self._default = vi
+ def computedefault(self, keytype):
+ self.prepare_raw_defaults()
+ for k, vi in self._rawdefaults.iteritems():
+ key = ValueInfo(k, vi.position).convert(keytype)
+ self.add_valueinfo(vi, key)
+
def getdefault(self):
# Use copy.copy() to make sure we don't allow polution of
# our internal data without having to worry about both the
@@ -193,6 +207,13 @@
else:
self._default.append(vi)
+ def computedefault(self, keytype):
+ self.prepare_raw_defaults()
+ for k, vlist in self._rawdefaults.iteritems():
+ key = ValueInfo(k, vlist[0].position).convert(keytype)
+ for vi in vlist:
+ self.add_valueinfo(vi, key)
+
def getdefault(self):
return copy.copy(self._default)
@@ -462,6 +483,14 @@
t._attrmap.update(base._attrmap)
t._keymap.update(base._keymap)
t._children.extend(base._children)
+ for i in range(len(t._children)):
+ key, info = t._children[i]
+ if isinstance(info, BaseKeyInfo) and info.name == "+":
+ # need to create a new info object and recompute the
+ # default mapping based on the new keytype
+ info = copy.copy(info)
+ info.computedefault(t.keytype)
+ t._children[i] = (key, info)
return t
def addComponent(self, name):
=== StandaloneZConfig/ZConfig/schema.py 1.35 => 1.36 ===
--- StandaloneZConfig/ZConfig/schema.py:1.35 Wed Apr 14 23:49:12 2004
+++ StandaloneZConfig/ZConfig/schema.py Thu Apr 15 00:59:09 2004
@@ -409,6 +409,7 @@
def end_key(self):
key = self._stack.pop()
if key.name == "+":
+ key.computedefault(self._stack[-1].keytype)
key.finish()
def start_multikey(self, attrs):
@@ -423,7 +424,10 @@
self._stack.append(key)
def end_multikey(self):
- self._stack.pop().finish()
+ multikey = self._stack.pop()
+ if multikey.name == "+":
+ multikey.computedefault(self._stack[-1].keytype)
+ multikey.finish()
# datatype conversion wrappers
More information about the Zodb-checkins
mailing list