xmlclass/xsdschema.py
changeset 1775 b45f2768fab1
parent 1774 ac0fe8aabb5e
child 1776 81aa8aaccdd4
equal deleted inserted replaced
1774:ac0fe8aabb5e 1775:b45f2768fab1
   184                 raise ValueError("Base type can't be derivated by restriction!")
   184                 raise ValueError("Base type can't be derivated by restriction!")
   185 
   185 
   186         # Extract simple type facets
   186         # Extract simple type facets
   187         for facet in typeinfos.get("facets", []):
   187         for facet in typeinfos.get("facets", []):
   188             facettype = facet["type"]
   188             facettype = facet["type"]
   189             if not facettype in basetypeinfos["facets"]:
   189             if facettype not in basetypeinfos["facets"]:
   190                 raise ValueError("\"%s\" facet can't be defined for \"%s\" type!" % (facettype, type))
   190                 raise ValueError("\"%s\" facet can't be defined for \"%s\" type!" % (facettype, type))
   191             elif basetypeinfos["facets"][facettype][1]:
   191             elif basetypeinfos["facets"][facettype][1]:
   192                 raise ValueError("\"%s\" facet is fixed on base type!" % facettype)
   192                 raise ValueError("\"%s\" facet is fixed on base type!" % facettype)
   193             value = facet["value"]
   193             value = facet["value"]
   194             basevalue = basetypeinfos["facets"][facettype][0]
   194             basevalue = basetypeinfos["facets"][facettype][0]
   294                     raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!")
   294                     raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!")
   295             facets[facettype] = (value, facet.get("fixed", False))
   295             facets[facettype] = (value, facet.get("fixed", False))
   296 
   296 
   297         # Report not redefined facet from base type to new created type
   297         # Report not redefined facet from base type to new created type
   298         for facettype, facetvalue in basetypeinfos["facets"].items():
   298         for facettype, facetvalue in basetypeinfos["facets"].items():
   299             if not facettype in facets:
   299             if facettype not in facets:
   300                 facets[facettype] = facetvalue
   300                 facets[facettype] = facetvalue
   301 
   301 
   302         # Generate extract value for new created type
   302         # Generate extract value for new created type
   303         def ExtractSimpleTypeValue(attr, extract=True):
   303         def ExtractSimpleTypeValue(attr, extract=True):
   304             value = basetypeinfos["extract"](attr, extract)
   304             value = basetypeinfos["extract"](attr, extract)
   551     return restriction
   551     return restriction
   552 
   552 
   553 
   553 
   554 def ReduceExtension(factory, attributes, elements):
   554 def ReduceExtension(factory, attributes, elements):
   555     annotations, children = factory.ReduceElements(elements)
   555     annotations, children = factory.ReduceElements(elements)
   556     if not "base" in attributes:
   556     if "base" not in attributes:
   557         raise ValueError("No base type has been defined for extension!")
   557         raise ValueError("No base type has been defined for extension!")
   558     extension = {"type": "extension", "attributes": [], "elements": [], "base": attributes["base"], "doc": annotations}
   558     extension = {"type": "extension", "attributes": [], "elements": [], "base": attributes["base"], "doc": annotations}
   559     if len(children) > 0:
   559     if len(children) > 0:
   560         if children[0]["type"] in ["group", "all", CHOICE, "sequence"]:
   560         if children[0]["type"] in ["group", "all", CHOICE, "sequence"]:
   561             group = children.pop(0)
   561             group = children.pop(0)
   806             #raise ValueError("\"sequence\" in \"choice\" is not supported. Create instead a new complex type!")
   806             #raise ValueError("\"sequence\" in \"choice\" is not supported. Create instead a new complex type!")
   807         elif child["type"] == CHOICE:
   807         elif child["type"] == CHOICE:
   808             choices.extend(child["choices"])
   808             choices.extend(child["choices"])
   809         elif child["type"] == "group":
   809         elif child["type"] == "group":
   810             elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   810             elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   811             if not "choices" in elmtgroup:
   811             if "choices" not in elmtgroup:
   812                 raise ValueError("Only group composed of \"choice\" can be referenced in \"choice\" element!")
   812                 raise ValueError("Only group composed of \"choice\" can be referenced in \"choice\" element!")
   813             choices_tmp = []
   813             choices_tmp = []
   814             for choice in elmtgroup["choices"]:
   814             for choice in elmtgroup["choices"]:
   815                 if not isinstance(choice["elmt_type"], (UnicodeType, StringType)) and choice["elmt_type"]["type"] == COMPLEXTYPE:
   815                 if not isinstance(choice["elmt_type"], (UnicodeType, StringType)) and choice["elmt_type"]["type"] == COMPLEXTYPE:
   816                     elmt_type = "%s_%s" % (elmtgroup["name"], choice["name"])
   816                     elmt_type = "%s_%s" % (elmtgroup["name"], choice["name"])
   840             sequence.append(child)
   840             sequence.append(child)
   841         elif child["type"] == "sequence":
   841         elif child["type"] == "sequence":
   842             sequence.extend(child["elements"])
   842             sequence.extend(child["elements"])
   843         elif child["type"] == "group":
   843         elif child["type"] == "group":
   844             elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   844             elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
   845             if not "elements" in elmtgroup or not elmtgroup["order"]:
   845             if "elements" not in elmtgroup or not elmtgroup["order"]:
   846                 raise ValueError("Only group composed of \"sequence\" can be referenced in \"sequence\" element!")
   846                 raise ValueError("Only group composed of \"sequence\" can be referenced in \"sequence\" element!")
   847             elements_tmp = []
   847             elements_tmp = []
   848             for element in elmtgroup["elements"]:
   848             for element in elmtgroup["elements"]:
   849                 if not isinstance(element["elmt_type"], (UnicodeType, StringType)) and element["elmt_type"]["type"] == COMPLEXTYPE:
   849                 if not isinstance(element["elmt_type"], (UnicodeType, StringType)) and element["elmt_type"]["type"] == COMPLEXTYPE:
   850                     elmt_type = "%s_%s" % (elmtgroup["name"], element["name"])
   850                     elmt_type = "%s_%s" % (elmtgroup["name"], element["name"])