[Zope3-checkins] CVS: Packages/ZConfig - info.py:1.6 schema.py:1.5
Fred L. Drake, Jr.
fred@zope.com
Mon, 6 Jan 2003 17:30:55 -0500
Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv25601
Modified Files:
info.py schema.py
Log Message:
Implement sectiontype extension (for ZODB).
=== Packages/ZConfig/info.py 1.5 => 1.6 ===
--- Packages/ZConfig/info.py:1.5 Mon Jan 6 16:07:39 2003
+++ Packages/ZConfig/info.py Mon Jan 6 17:30:18 2003
@@ -396,3 +396,13 @@
self.registry, self._types)
self.addtype(t)
return t
+
+ def deriveSectionType(self, base, name, valuetype, datatype):
+ if isinstance(base, SchemaType):
+ raise ZConfig.SchemaError(
+ "cannot derive sectiontype from top-level schema")
+ t = self.createSectionType(name, base.keytype, valuetype, datatype)
+ t._attrmap.update(base._attrmap)
+ t._keymap.update(base._keymap)
+ t._children.extend(base._children)
+ return t
=== Packages/ZConfig/schema.py 1.4 => 1.5 ===
--- Packages/ZConfig/schema.py:1.4 Mon Jan 6 14:35:41 2003
+++ Packages/ZConfig/schema.py Mon Jan 6 17:30:18 2003
@@ -217,8 +217,20 @@
name = self.basic_key(name)
self.push_prefix(attrs)
keytype, valuetype, datatype = self.get_sect_typeinfo(attrs)
- sectinfo = self._schema.createSectionType(
- name, keytype, valuetype, datatype)
+ if attrs.has_key("extends"):
+ basename = self.basic_key(attrs["extends"])
+ if basename == name:
+ self.error("sectiontype cannot extend itself")
+ base = self._schema.gettype(basename)
+ if base.istypegroup():
+ self.error("sectiontype cannot extend an abstract type")
+ if attrs.has_key("keytype"):
+ self.error("derived sectiontype may not specify a keytype")
+ sectinfo = self._schema.deriveSectionType(
+ base, name, valuetype, datatype)
+ else:
+ sectinfo = self._schema.createSectionType(
+ name, keytype, valuetype, datatype)
if self._group is not None:
if attrs.has_key("group"):
self.error("sectiontype cannot specify group"