[Zope3-checkins] CVS: Packages/ZConfig - schema.py:1.7
Fred L. Drake, Jr.
fred@zope.com
Tue, 7 Jan 2003 12:11:50 -0500
Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv27141
Modified Files:
schema.py
Log Message:
Start some refactoring to make schema components easier to develop.
Components and extensions will need to be slightly different document
types (for the top level only), and have slightly different processing
to affect the final schema instance.
=== Packages/ZConfig/schema.py 1.6 => 1.7 ===
--- Packages/ZConfig/schema.py:1.6 Tue Jan 7 01:27:08 2003
+++ Packages/ZConfig/schema.py Tue Jan 7 12:11:44 2003
@@ -44,10 +44,10 @@
return parser._schema
-class SchemaParser(xml.sax.ContentHandler):
+class BaseParser(xml.sax.ContentHandler):
_cdata_tags = "description", "metadefault", "example", "default"
- _handled_tags = ("schema", "import", "sectiongroup", "sectiontype",
+ _handled_tags = ("import", "sectiongroup", "sectiontype",
"key", "multikey", "section", "multisection")
def __init__(self, registry, loader, url):
@@ -103,11 +103,7 @@
else:
data = ''.join(self._cdata).strip()
self._cdata = None
- if name == "default":
- # value for a key
- self._stack[-1].adddefault(data, self._position)
- else:
- setattr(self._stack[-1], name, data)
+ getattr(self, "characters_" + name)(data)
def endDocument(self):
if self._schema is None:
@@ -115,6 +111,18 @@
# schema loading logic
+ def characters_default(self, data):
+ self._stack[-1].adddefault(data, self._position)
+
+ def characters_description(self, data):
+ self._stack[-1].description = data
+
+ def characters_example(self, data):
+ self._stack[-1].example = data
+
+ def characters_metadefault(self, data):
+ self._stack[-1].metadefault = data
+
def start_import(self, attrs):
src = attrs.get("src", "").strip()
pkg = attrs.get("package", "").strip()
@@ -144,7 +152,7 @@
if self._locator:
return (self._locator.getLineNumber(),
self._locator.getColumnNumber(),
- self._url)
+ (self._locator.getSystemId() or self._url))
else:
return None, None, self._url
@@ -193,24 +201,6 @@
datatype = self.get_datatype(attrs, "datatype", "null")
return keytype, valuetype, datatype
- def start_schema(self, attrs):
- self.push_prefix(attrs)
- handler = self.get_handler(attrs)
- keytype, valuetype, datatype = self.get_sect_typeinfo(attrs)
- name = attrs.get("type")
- if name is not None:
- name = self.basic_key(name)
- self._schema = info.SchemaType(name, keytype, valuetype, datatype,
- handler, self._url, self._registry)
- if name is not None:
- # XXX circular reference
- self._schema.addtype(self._schema)
- self._stack = [self._schema]
-
- def end_schema(self):
- del self._prefixes[-1]
- assert not self._prefixes
-
def start_sectiontype(self, attrs):
name = attrs.get("type")
if not name:
@@ -415,3 +405,29 @@
def error(self, message):
raise self.initerror(ZConfig.SchemaError(message))
+
+
+class SchemaParser(BaseParser):
+
+ # needed by startElement() and endElement()
+ _handled_tags = BaseParser._handled_tags + ("schema",)
+
+ def start_schema(self, attrs):
+ self.push_prefix(attrs)
+ handler = self.get_handler(attrs)
+ keytype, valuetype, datatype = self.get_sect_typeinfo(attrs)
+ name = attrs.get("type")
+ if name is not None:
+ name = self.basic_key(name)
+ self._schema = info.SchemaType(name, keytype, valuetype, datatype,
+ handler, self._url, self._registry)
+ if name is not None:
+ # XXX circular reference
+ self._schema.addtype(self._schema)
+ self._stack = [self._schema]
+
+ def end_schema(self):
+ del self._stack[-1]
+ assert not self._stack
+ del self._prefixes[-1]
+ assert not self._prefixes