Example #1
0
 def __init__(self, name, sectiontype, minOccurs, maxOccurs, handler,
              attribute):
     # name        - name of the section; one of '*', '+', or name1
     # sectiontype - SectionType instance
     # minOccurs   - minimum number of occurances of the section
     # maxOccurs   - maximum number of occurances; if > 1, name
     #               must be '*' or '+'
     # handler     - handler name called when value(s) must take effect,
     #               or None
     # attribute   - name of the attribute on the SectionValue object
     if maxOccurs > 1:
         if name not in ('*', '+'):
             raise ZConfig.SchemaError(
                 "sections which can occur more than once must"
                 " use a name of '*' or '+'")
         if not attribute:
             raise ZConfig.SchemaError(
                 "sections which can occur more than once must"
                 " specify a target attribute name")
     if sectiontype.isabstract():
         datatype = None
     else:
         datatype = sectiontype.datatype
     BaseInfo.__init__(self, name, datatype, minOccurs, maxOccurs, handler,
                       attribute)
     self.sectiontype = sectiontype
Example #2
0
 def adddefault(self, value, position, key=None):
     if self._finished:
         raise ZConfig.SchemaError(
             "cannot add default values to finished KeyInfo")
     # Check that the name/keyed relationship is right:
     if self.name == "+" and key is None:
         raise ZConfig.SchemaError(
             "default values must be keyed for name='+'")
     elif self.name != "+" and key is not None:
         raise ZConfig.SchemaError("unexpected key for default value")
     self.add_valueinfo(ValueInfo(value, position), key)
Example #3
0
 def add_valueinfo(self, vi, key):
     if self.name == "+":
         if key in self._default:
             # not ideal: we're presenting the unconverted
             # version of the key
             raise ZConfig.SchemaError(
                 "duplicate default value for key %s" % repr(key))
         self._default[key] = vi
     elif self._default is not None:
         raise ZConfig.SchemaError(
             "cannot set more than one default to key with maxOccurs == 1")
     else:
         self._default = vi
Example #4
0
 def _add_child(self, key, info):
     # check naming constraints
     assert key or info.attribute
     if key and key in self._keymap:
         raise ZConfig.SchemaError("child name %s already used" % key)
     if info.attribute and info.attribute in self._attrmap:
         raise ZConfig.SchemaError("child attribute name %s already used" %
                                   info.attribute)
     # a-ok, add the item to the appropriate maps
     if info.attribute:
         self._attrmap[info.attribute] = info
     if key:
         self._keymap[key] = info
     self._children.append((key, info))
Example #5
0
 def __init__(self, name, datatype, minOccurs, maxOccurs, handler,
              attribute):
     if maxOccurs is not None and maxOccurs < 1:
         if maxOccurs < 1:
             raise ZConfig.SchemaError("maxOccurs must be at least 1")
         if minOccurs is not None and minOccurs < maxOccurs:
             raise ZConfig.SchemaError(
                 "minOccurs must be at least maxOccurs")
     self.name = name
     self.datatype = datatype
     self.minOccurs = minOccurs
     self.maxOccurs = maxOccurs
     self.handler = handler
     self.attribute = attribute
Example #6
0
    def __init__(self, name, datatype, minOccurs, maxOccurs, handler,
                 attribute):
        assert maxOccurs is not None, "Use Unbounded for an upper bound, not None"
        assert minOccurs is not None, "Use 0 for a lower bound, not None"

        if maxOccurs < 1:
            raise ZConfig.SchemaError("maxOccurs must be at least 1")
        if minOccurs > maxOccurs:
            raise ZConfig.SchemaError(
                "minOccurs cannot be more than maxOccurs")
        self.name = name
        self.datatype = datatype
        self.minOccurs = minOccurs
        self.maxOccurs = maxOccurs
        self.handler = handler
        self.attribute = attribute
Example #7
0
 def __init__(self, schema):
     if schema.isabstract():
         raise ZConfig.SchemaError(
             "cannot check a configuration an abstract type")
     BaseLoader.__init__(self)
     self.schema = schema
     self._private_schema = False
Example #8
0
 def schemaComponentSource(self, package, filename):
     parts = package.split(".")
     if not parts:  # pragma: no cover
         raise ZConfig.SchemaError("illegal schema component name: " +
                                   repr(package))
     if "" in parts:
         # '' somewhere in the package spec; still illegal
         raise ZConfig.SchemaError("illegal schema component name: " +
                                   repr(package))
     filename = filename or "component.xml"
     try:
         __import__(package)
     except ImportError as e:
         raise ZConfig.SchemaResourceError("could not load package %s: %s" %
                                           (package, str(e)),
                                           filename=filename,
                                           package=package)
     pkg = sys.modules[package]
     if not hasattr(pkg, "__path__"):
         raise ZConfig.SchemaResourceError(
             "import name does not refer to a package",
             filename=filename,
             package=package)
     return "package:%s:%s" % (package, filename)
Example #9
0
 def deriveSectionType(self, base, name, keytype, valuetype, datatype):
     if isinstance(base, SchemaType):
         raise ZConfig.SchemaError(
             "cannot derive sectiontype from top-level schema")
     t = self.createSectionType(name, keytype, valuetype, datatype)
     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
Example #10
0
 def addComponent(self, name):
     if name in self._components:
         raise ZConfig.SchemaError("already have component %s" % name)
     self._components[name] = name
Example #11
0
 def addtype(self, typeinfo):
     n = typeinfo.name
     if n in self._types:
         raise ZConfig.SchemaError("type name cannot be redefined: " +
                                   repr(typeinfo.name))
     self._types[n] = typeinfo
Example #12
0
 def gettype(self, name):
     n = name.lower()
     try:
         return self._types[n]
     except KeyError:
         raise ZConfig.SchemaError("unknown type name: " + repr(name))
Example #13
0
 def finish(self):
     if self._finished:
         raise ZConfig.SchemaError("cannot finish KeyInfo more than once")
     self._finished = True
Example #14
0
 def error(self, message):
     raise_with_same_tb(self.initerror(ZConfig.SchemaError(message)))
Example #15
0
 def error(self, message):
     raise self.initerror(ZConfig.SchemaError(message))
Example #16
0
 def getsubtype(self, name):
     try:
         return self._subtypes[name]
     except KeyError:
         raise ZConfig.SchemaError("no sectiontype %s in abstracttype %s" %
                                   (repr(name), repr(self.name)))
Example #17
0
 def addComponent(self, name):
     if self._components.has_key(name):
         raise ZConfig.SchemaError("already have component %s" % name)
     self._components[name] = name