def parse_schema(ctx, elt): ctx.nsmap = nsmap = elt.nsmap ctx.prefmap = prefmap = dict([(v, k) for k, v in ctx.nsmap.items()]) ctx.schema = schema = _prot.from_element(XmlSchema10, elt) ctx.pending_types = {} ctx.pending_elements = {} ctx.tns = tns = schema.target_namespace if tns in ctx.retval: return ctx.retval[tns] = _Schema() ctx.debug0("1 %s processing includes", M(tns)) if schema.includes: for include in schema.includes: process_includes(ctx, include) if schema.elements: schema.elements = odict([(e.name, e) for e in schema.elements]) if schema.complex_types: schema.complex_types = odict([(c.name, c) for c in schema.complex_types]) if schema.simple_types: schema.simple_types = odict([(s.name, s) for s in schema.simple_types]) if schema.attributes: schema.attributes = odict([(a.name, a) for a in schema.attributes]) ctx.debug0("2 %s processing imports", R(tns)) if schema.imports: for imp in schema.imports: if not imp.namespace in ctx.retval: ctx.debug1("%s importing %s", tns, imp.namespace) file_name = ctx.files[imp.namespace] parse_schema_file(ctx.clone(2, dirname(file_name)), file_name) ctx.retval[tns].imports.add(imp.namespace) ctx.debug0("3 %s processing attributes", G(tns)) if schema.attributes: for s in schema.attributes.values(): n, t = process_attribute(ctx, s) ctx.retval[ctx.tns].types[n] = t ctx.debug0("4 %s processing simple_types", G(tns)) if schema.simple_types: for s in schema.simple_types.values(): st = process_simple_type(ctx, s) ctx.retval[ctx.tns].types[s.name] = st ctx.debug0("5 %s processing complex_types", B(tns)) if schema.complex_types: for c in schema.complex_types.values(): process_complex_type(ctx, c) ctx.debug0("6 %s processing elements", Y(tns)) if schema.elements: for e in schema.elements.values(): process_schema_element(ctx, e) process_pending(ctx) if ctx.parent is None: # for the top-most schema if ctx.children is not None: # if it uses <include> or <import> # This is needed for schemas with circular imports for c in chain([ctx], ctx.children): print_pending(c) ctx.debug0('') for c in chain([ctx], ctx.children): process_pending(c) for c in chain([ctx], ctx.children): process_pending(c) ctx.debug0('') for c in chain([ctx], ctx.children): print_pending(c, fail=True) return ctx.retval
def parse_schema(self, elt): self.nsmap = nsmap = elt.nsmap self.prefmap = prefmap = dict([(v, k) for k, v in self.nsmap.items()]) self.schema = schema = _prot.from_element(self, XmlSchema10, elt) self.pending_types = {} self.pending_elements = {} self.tns = tns = schema.target_namespace if self.tns is None: self.tns = tns = '__no_ns__' if tns in self.retval: return self.retval[tns] = _Schema() self.debug0("1 %s processing includes", M(tns)) if schema.includes: for include in schema.includes: self.process_includes(include) if schema.elements: schema.elements = odict([(e.name, e) for e in schema.elements]) if schema.complex_types: schema.complex_types = odict([(c.name, c) for c in schema.complex_types]) if schema.simple_types: schema.simple_types = odict([(s.name, s) for s in schema.simple_types]) if schema.attributes: schema.attributes = odict([(a.name, a) for a in schema.attributes]) self.debug0("2 %s processing imports", R(tns)) if schema.imports: for imp in schema.imports: if not imp.namespace in self.retval: self.debug1("%s importing %s", tns, imp.namespace) file_name = self.files[imp.namespace] self.clone(2, dirname(file_name)).parse_schema_file(file_name) self.retval[tns].imports.add(imp.namespace) self.debug0("3 %s processing attributes", G(tns)) if schema.attributes: for s in schema.attributes.values(): n, t = self.process_attribute(s) self.retval[self.tns].types[n] = t self.debug0("4 %s processing simple_types", G(tns)) if schema.simple_types: for s in schema.simple_types.values(): st = self.process_simple_type(s) self.retval[self.tns].types[s.name] = st self.debug0("5 %s processing complex_types", B(tns)) if schema.complex_types: for c in schema.complex_types.values(): self.process_complex_type(c) self.debug0("6 %s processing elements", Y(tns)) if schema.elements: for e in schema.elements.values(): self.process_schema_element(e) self.process_pending() if self.parent is None: # for the top-most schema if self.children is not None: # if it uses <include> or <import> # This is needed for schemas with circular imports for c in chain([self], self.children): c.print_pending() self.debug0('') # FIXME: This has no guarantee of working yet covers all the # schema files found in the wild so far. for c in chain([self], self.children): c.process_pending() for c in chain([self], self.children): c.process_pending() self.debug0('') for c in chain([self], self.children): c.print_pending(fail=True) return self.retval
def parse_schema(self, elt): self.nsmap = dict(elt.nsmap.items()) self.prefmap = dict([(v, k) for k, v in self.nsmap.items()]) self.schema = schema = _prot.from_element(self, XmlSchema10, elt) self.pending_types = {} self.pending_elements = {} self.tns = tns = schema.target_namespace if self.tns is None: self.tns = tns = '__no_ns__' if tns in self.retval: return self.retval[tns] = _Schema() self.debug0("1 %s processing includes", M(tns)) if schema.includes: for include in schema.includes: self.process_includes(include) if schema.elements: schema.elements = odict([(e.name, e) for e in schema.elements]) if schema.complex_types: schema.complex_types = odict([(c.name, c) for c in schema.complex_types]) if schema.simple_types: schema.simple_types = odict([(s.name, s) for s in schema.simple_types]) if schema.attributes: schema.attributes = odict([(a.name, a) for a in schema.attributes]) self.debug0("2 %s processing imports", R(tns)) if schema.imports: for imp in schema.imports: if not imp.namespace in self.retval: self.debug1("%s importing %s", tns, imp.namespace) fname = self.files[imp.namespace] self.clone(2, dirname(fname)).parse_schema_file(fname) self.retval[tns].imports.add(imp.namespace) self.debug0("3 %s processing simple_types", G(tns)) if schema.simple_types: for s in schema.simple_types.values(): self.process_simple_type(s) # no simple types should have been left behind. assert sum((len(v) for v in self.pending_simple_types.values())) == 0, \ self.pending_simple_types.values() self.debug0("4 %s processing attributes", G(tns)) if schema.attributes: for s in schema.attributes.values(): n, t = self.process_attribute(s) self.retval[self.tns].types[n] = t self.debug0("5 %s processing complex_types", B(tns)) if schema.complex_types: for c in schema.complex_types.values(): self.process_complex_type(c) self.debug0("6 %s processing elements", Y(tns)) if schema.elements: for e in schema.elements.values(): self.process_schema_element(e) self.process_pending() if self.parent is None: # for the top-most schema if self.children is not None: # if it uses <include> or <import> # This is needed for schemas with circular imports for c in chain([self], self.children): c.print_pending() self.debug0('') # FIXME: should put this in a while loop that loops until no # changes occur for c in chain([self], self.children): c.process_pending() for c in chain([self], self.children): c.process_pending() self.debug0('') for c in chain([self], self.children): c.print_pending(fail=(not self.skip_errors)) return self.retval