def start_import(self, attrs): src = attrs.get("src", "").strip() pkg = attrs.get("package", "").strip() file = attrs.get("file", "").strip() if not (src or pkg): self.error("import must specify either src or package") if src and pkg: self.error("import may only specify one of src or package") if src: if file: self.error("import may not specify file and src") src = url.urljoin(self._url, src) src, fragment = url.urldefrag(src) if fragment: self.error("import src many not include" " a fragment identifier") schema = self._loader.loadURL(src) for n in schema.gettypenames(): self._schema.addtype(schema.gettype(n)) else: if os.path.dirname(file): self.error("file may not include a directory part") pkg = self.get_classname(pkg) src = self._loader.schemaComponentSource(pkg, file) if not self._schema.hasComponent(src): self._schema.addComponent(src) self.loadComponent(src)
def start_import(self, attrs): src = attrs.get("src", "").strip() pkg = attrs.get("package", "").strip() filename = attrs.get("file", "").strip() if not (src or pkg): self.error("import must specify either src or package") if src and pkg: self.error("import may only specify one of src or package") if src: if filename: self.error("import may not specify file and src") src = url.urljoin(self._url, src) src, fragment = url.urldefrag(src) if fragment: self.error("import src may not include" " a fragment identifier") schema = self._loader.loadURL(src) for n in schema.gettypenames(): self._schema.addtype(schema.gettype(n)) else: if os.path.dirname(filename): self.error("file may not include a directory part") pkg = self.get_classname(pkg) src = self._loader.schemaComponentSource(pkg, filename) if not self._schema.hasComponent(src): self._schema.addComponent(src) self.loadComponent(src)
def start_schema(self, attrs): self.push_prefix(attrs) handler = self.get_handler(attrs) keytype, valuetype, datatype = self.get_sect_typeinfo(attrs) if self._extending_parser is None: # We're not being inherited, so we need to create the schema self._schema = info.SchemaType(keytype, valuetype, datatype, handler, self._url, self._registry) else: # Parse into the extending ("subclass") parser's schema self._schema = self._extending_parser._schema self._stack = [self._schema] if attrs.has_key("extends"): sources = attrs["extends"].split() sources.reverse() for src in sources: src = url.urljoin(self._url, src) src, fragment = url.urldefrag(src) if fragment: self.error("schema extends many not include" " a fragment identifier") self.extendSchema(src) # Inherit keytype from bases, if unspecified and not conflicting if self._base_keytypes and not attrs.has_key("keytype"): keytype = self._base_keytypes[0] for kt in self._base_keytypes[1:]: if kt is not keytype: self.error("base schemas have conflicting keytypes," " but no keytype was specified in the" " extending schema") # Inherit datatype from bases, if unspecified and not conflicting if self._base_datatypes and not attrs.has_key("datatype"): datatype = self._base_datatypes[0] for dt in self._base_datatypes[1:]: if dt is not datatype: self.error("base schemas have conflicting datatypes," " but no datatype was specified in the" " extending schema") # Reset the schema types to our own, while we parse the schema body self._schema.keytype = keytype self._schema.valuetype = valuetype self._schema.datatype = datatype # Update base key/datatypes for the "extending" parser if self._extending_parser is not None: self._extending_parser._base_keytypes.append(keytype) self._extending_parser._base_datatypes.append(datatype)
def start_schema(self, attrs): self.push_prefix(attrs) handler = self.get_handler(attrs) keytype, valuetype, datatype = self.get_sect_typeinfo(attrs) if self._extending_parser is None: # We're not being inherited, so we need to create the schema self._schema = info.SchemaType(keytype, valuetype, datatype, handler, self._url, self._registry) else: # Parse into the extending ("subclass") parser's schema self._schema = self._extending_parser._schema self._stack = [self._schema] if "extends" in attrs: sources = attrs["extends"].split() sources.reverse() for src in sources: src = url.urljoin(self._url, src) src, fragment = url.urldefrag(src) if fragment: self.error("schema extends many not include" " a fragment identifier") self.extendSchema(src) # Inherit keytype from bases, if unspecified and not conflicting if self._base_keytypes and "keytype" not in attrs: keytype = self._base_keytypes[0] for kt in self._base_keytypes[1:]: if kt is not keytype: self.error("base schemas have conflicting keytypes," " but no keytype was specified in the" " extending schema") # Inherit datatype from bases, if unspecified and not conflicting if self._base_datatypes and "datatype" not in attrs: datatype = self._base_datatypes[0] for dt in self._base_datatypes[1:]: if dt is not datatype: self.error("base schemas have conflicting datatypes," " but no datatype was specified in the" " extending schema") # Reset the schema types to our own, while we parse the schema body self._schema.keytype = keytype self._schema.valuetype = valuetype self._schema.datatype = datatype # Update base key/datatypes for the "extending" parser if self._extending_parser is not None: self._extending_parser._base_keytypes.append(keytype) self._extending_parser._base_datatypes.append(datatype)
def load_config(self, schema, conf_url, num_handlers=0): conf_url = urljoin(CONFIG_BASE, conf_url) loader = self.create_config_loader(schema) self.conf, self.handlers = loader.loadURL(conf_url) self.assertEqual(len(self.handlers), num_handlers) return self.conf
def load_schema(self, relurl): self.url = urljoin(CONFIG_BASE, relurl) self.schema = ZConfig.loadSchema(self.url) self.assert_(self.schema.issection()) return self.schema