77 ALL_FACETS = ["pattern", "whiteSpace", "enumeration", "maxInclusive", |
77 ALL_FACETS = ["pattern", "whiteSpace", "enumeration", "maxInclusive", |
78 "maxExclusive", "minInclusive", "minExclusive", "totalDigits", |
78 "maxExclusive", "minInclusive", "minExclusive", "totalDigits", |
79 "fractionDigits", "length", "minLength", "maxLength"] |
79 "fractionDigits", "length", "minLength", "maxLength"] |
80 |
80 |
81 |
81 |
82 #------------------------------------------------------------------------------- |
82 # ------------------------------------------------------------------------------- |
83 # Structure reducing functions |
83 # Structure reducing functions |
84 #------------------------------------------------------------------------------- |
84 # ------------------------------------------------------------------------------- |
85 |
85 |
86 |
86 |
87 # Documentation elements |
87 # Documentation elements |
88 |
88 |
89 def ReduceAppInfo(factory, attributes, elements): |
89 def ReduceAppInfo(factory, attributes, elements): |
801 if child["type"] in [ELEMENT, ANY, TAG]: |
801 if child["type"] in [ELEMENT, ANY, TAG]: |
802 choices.append(child) |
802 choices.append(child) |
803 elif child["type"] == "sequence": |
803 elif child["type"] == "sequence": |
804 child["minOccurs"] = child["maxOccurs"] = 1 |
804 child["minOccurs"] = child["maxOccurs"] = 1 |
805 choices.append(child) |
805 choices.append(child) |
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 "choices" not in elmtgroup: |
811 if "choices" not in elmtgroup: |
1006 return False |
1006 return False |
1007 else: |
1007 else: |
1008 return True |
1008 return True |
1009 return schema == reference |
1009 return schema == reference |
1010 |
1010 |
1011 #------------------------------------------------------------------------------- |
1011 |
|
1012 # ------------------------------------------------------------------------------- |
1012 # Base class for XSD schema extraction |
1013 # Base class for XSD schema extraction |
1013 #------------------------------------------------------------------------------- |
1014 # ------------------------------------------------------------------------------- |
1014 |
1015 |
1015 |
1016 |
1016 class XSDClassFactory(ClassFactory): |
1017 class XSDClassFactory(ClassFactory): |
1017 |
1018 |
1018 def __init__(self, document, filepath=None, debug=False): |
1019 def __init__(self, document, filepath=None, debug=False): |
1131 This function generate a xml from the xsd given as a string |
1132 This function generate a xml from the xsd given as a string |
1132 """ |
1133 """ |
1133 return GenerateParser(XSDClassFactory(minidom.parseString(xsdstring)), xsdstring) |
1134 return GenerateParser(XSDClassFactory(minidom.parseString(xsdstring)), xsdstring) |
1134 |
1135 |
1135 |
1136 |
1136 #------------------------------------------------------------------------------- |
1137 # ------------------------------------------------------------------------------- |
1137 # XSD schema syntax elements |
1138 # XSD schema syntax elements |
1138 #------------------------------------------------------------------------------- |
1139 # ------------------------------------------------------------------------------- |
|
1140 |
1139 |
1141 |
1140 XSD_NAMESPACE = { |
1142 XSD_NAMESPACE = { |
1141 |
1143 |
1142 #------------------------------------------------------------------------------- |
1144 # ------------------------------------------------------------------------------- |
1143 # Syntax elements definition |
1145 # Syntax elements definition |
1144 #------------------------------------------------------------------------------- |
1146 # ------------------------------------------------------------------------------- |
1145 |
1147 |
1146 "all": { |
1148 "all": { |
1147 "struct": """ |
1149 "struct": """ |
1148 <all |
1150 <all |
1149 id = ID |
1151 id = ID |
1915 "whiteSpace", ["fixed", "id", "value"], ONLY_ANNOTATION) |
1917 "whiteSpace", ["fixed", "id", "value"], ONLY_ANNOTATION) |
1916 }, |
1918 }, |
1917 "reduce": GenerateFacetReducing("whiteSpace", True) |
1919 "reduce": GenerateFacetReducing("whiteSpace", True) |
1918 }, |
1920 }, |
1919 |
1921 |
1920 #------------------------------------------------------------------------------- |
1922 # ------------------------------------------------------------------------------- |
1921 # Syntax attributes definition |
1923 # Syntax attributes definition |
1922 #------------------------------------------------------------------------------- |
1924 # ------------------------------------------------------------------------------- |
1923 |
1925 |
1924 "abstract": { |
1926 "abstract": { |
1925 "type": SYNTAXATTRIBUTE, |
1927 "type": SYNTAXATTRIBUTE, |
1926 "extract": { |
1928 "extract": { |
1927 "default": GetBoolean |
1929 "default": GetBoolean |
2197 # "default": NotSupportedYet("xpath") |
2199 # "default": NotSupportedYet("xpath") |
2198 "default": GetAttributeValue |
2200 "default": GetAttributeValue |
2199 } |
2201 } |
2200 }, |
2202 }, |
2201 |
2203 |
2202 #------------------------------------------------------------------------------- |
2204 # ------------------------------------------------------------------------------- |
2203 # Simple types definition |
2205 # Simple types definition |
2204 #------------------------------------------------------------------------------- |
2206 # ------------------------------------------------------------------------------- |
2205 |
2207 |
2206 "string": { |
2208 "string": { |
2207 "type": SIMPLETYPE, |
2209 "type": SIMPLETYPE, |
2208 "basename": "string", |
2210 "basename": "string", |
2209 "extract": GetAttributeValue, |
2211 "extract": GetAttributeValue, |