55 if decimal is not None else str) |
55 if decimal is not None else str) |
56 |
56 |
57 def generateXMLTextMethod(value, name=None, indent=0): |
57 def generateXMLTextMethod(value, name=None, indent=0): |
58 text = "" |
58 text = "" |
59 if name is not None: |
59 if name is not None: |
60 ind1, ind2 = getIndent(indent, name) |
60 ind1, _ind2 = getIndent(indent, name) |
61 text += ind1 + "<%s>" % name |
61 text += ind1 + "<%s>" % name |
62 if isinstance(value, IntType): |
62 if isinstance(value, IntType): |
63 text += str(value) |
63 text += str(value) |
64 elif value in extra_values or value % 1 != 0: |
64 elif value in extra_values or value % 1 != 0: |
65 text += float_format(value) |
65 text += float_format(value) |
97 return {"type": "documentation", "source": attributes.get("source", None), |
97 return {"type": "documentation", "source": attributes.get("source", None), |
98 "language": attributes.get("lang", "any"), "content": "\n".join(elements)} |
98 "language": attributes.get("lang", "any"), "content": "\n".join(elements)} |
99 |
99 |
100 |
100 |
101 def ReduceAnnotation(factory, attributes, elements): |
101 def ReduceAnnotation(factory, attributes, elements): |
102 annotations, children = factory.ReduceElements(elements) |
102 _annotations, children = factory.ReduceElements(elements) |
103 annotation = {"type": "annotation", "appinfo": [], "documentation": {}} |
103 annotation = {"type": "annotation", "appinfo": [], "documentation": {}} |
104 for child in children: |
104 for child in children: |
105 if child["type"] == "appinfo": |
105 if child["type"] == "appinfo": |
106 annotation["appinfo"].append((child["source"], child["content"])) |
106 annotation["appinfo"].append((child["source"], child["content"])) |
107 elif child["type"] == "documentation": |
107 elif child["type"] == "documentation": |
118 # Simple type elements |
118 # Simple type elements |
119 |
119 |
120 |
120 |
121 def GenerateFacetReducing(facetname, canbefixed): |
121 def GenerateFacetReducing(facetname, canbefixed): |
122 def ReduceFacet(factory, attributes, elements): |
122 def ReduceFacet(factory, attributes, elements): |
123 annotations, children = factory.ReduceElements(elements) |
123 annotations, _children = factory.ReduceElements(elements) |
124 if "value" in attributes: |
124 if "value" in attributes: |
125 facet = {"type": facetname, "value": attributes["value"], "doc": annotations} |
125 facet = {"type": facetname, "value": attributes["value"], "doc": annotations} |
126 if canbefixed: |
126 if canbefixed: |
127 facet["fixed"] = attributes.get("fixed", False) |
127 facet["fixed"] = attributes.get("fixed", False) |
128 return facet |
128 return facet |
302 facets[facettype] = facetvalue |
302 facets[facettype] = facetvalue |
303 |
303 |
304 # Generate extract value for new created type |
304 # Generate extract value for new created type |
305 def ExtractSimpleTypeValue(attr, extract=True): |
305 def ExtractSimpleTypeValue(attr, extract=True): |
306 value = basetypeinfos["extract"](attr, extract) |
306 value = basetypeinfos["extract"](attr, extract) |
307 for facetname, (facetvalue, facetfixed) in facets.items(): |
307 for facetname, (facetvalue, _facetfixed) in facets.items(): |
308 if facetvalue is not None: |
308 if facetvalue is not None: |
309 if facetname == "enumeration" and value not in facetvalue: |
309 if facetname == "enumeration" and value not in facetvalue: |
310 raise ValueError("\"%s\" not in enumerated values" % value) |
310 raise ValueError("\"%s\" not in enumerated values" % value) |
311 elif facetname == "length" and len(value) != facetvalue: |
311 elif facetname == "length" and len(value) != facetvalue: |
312 raise ValueError("value must have a length of %d" % facetvalue) |
312 raise ValueError("value must have a length of %d" % facetvalue) |
876 |
876 |
877 # Constraint elements |
877 # Constraint elements |
878 |
878 |
879 |
879 |
880 def ReduceUnique(factory, attributes, elements): |
880 def ReduceUnique(factory, attributes, elements): |
881 annotations, children = factory.ReduceElements(elements) |
881 _annotations, children = factory.ReduceElements(elements) |
882 |
882 |
883 unique = {"type": CONSTRAINT, "const_type": "unique", "selector": children[0], "fields": children[1:]} |
883 unique = {"type": CONSTRAINT, "const_type": "unique", "selector": children[0], "fields": children[1:]} |
884 unique.update(attributes) |
884 unique.update(attributes) |
885 return unique |
885 return unique |
886 |
886 |
887 |
887 |
888 def ReduceKey(factory, attributes, elements): |
888 def ReduceKey(factory, attributes, elements): |
889 annotations, children = factory.ReduceElements(elements) |
889 _annotations, children = factory.ReduceElements(elements) |
890 |
890 |
891 key = {"type": CONSTRAINT, "const_type": "key", "selector": children[0], "fields": children[1:]} |
891 key = {"type": CONSTRAINT, "const_type": "key", "selector": children[0], "fields": children[1:]} |
892 key.update(attributes) |
892 key.update(attributes) |
893 return key |
893 return key |
894 |
894 |
895 |
895 |
896 def ReduceKeyRef(factory, attributes, elements): |
896 def ReduceKeyRef(factory, attributes, elements): |
897 annotations, children = factory.ReduceElements(elements) |
897 _annotations, children = factory.ReduceElements(elements) |
898 |
898 |
899 keyref = {"type": CONSTRAINT, "const_type": "keyref", "selector": children[0], "fields": children[1:]} |
899 keyref = {"type": CONSTRAINT, "const_type": "keyref", "selector": children[0], "fields": children[1:]} |
900 keyref.update(attributes) |
900 keyref.update(attributes) |
901 return keyref |
901 return keyref |
902 |
902 |
903 |
903 |
904 def ReduceSelector(factory, attributes, elements): |
904 def ReduceSelector(factory, attributes, elements): |
905 annotations, children = factory.ReduceElements(elements) |
905 factory.ReduceElements(elements) |
906 |
906 |
907 selector = {"type": CONSTRAINT, "const_type": "selector"} |
907 selector = {"type": CONSTRAINT, "const_type": "selector"} |
908 selector.update(attributes) |
908 selector.update(attributes) |
909 return selector |
909 return selector |
910 |
910 |
911 |
911 |
912 def ReduceField(factory, attributes, elements): |
912 def ReduceField(factory, attributes, elements): |
913 annotations, children = factory.ReduceElements(elements) |
913 factory.ReduceElements(elements) |
914 |
914 |
915 field = {"type": CONSTRAINT, "const_type": "field"} |
915 field = {"type": CONSTRAINT, "const_type": "field"} |
916 field.update(attributes) |
916 field.update(attributes) |
917 return field |
917 return field |
918 |
918 |
919 |
919 |
920 # Inclusion elements |
920 # Inclusion elements |
921 |
921 |
922 def ReduceImport(factory, attributes, elements): |
922 def ReduceImport(factory, attributes, elements): |
923 annotations, children = factory.ReduceElements(elements) |
923 factory.ReduceElements(elements) |
924 raise ValueError("\"import\" element isn't supported yet!") |
924 raise ValueError("\"import\" element isn't supported yet!") |
925 |
925 |
926 |
926 |
927 def ReduceInclude(factory, attributes, elements): |
927 def ReduceInclude(factory, attributes, elements): |
928 annotations, children = factory.ReduceElements(elements) |
928 factory.ReduceElements(elements) |
929 |
929 |
930 if factory.FileName is None: |
930 if factory.FileName is None: |
931 raise ValueError("Include in XSD string not yet supported") |
931 raise ValueError("Include in XSD string not yet supported") |
932 filepath = attributes["schemaLocation"] |
932 filepath = attributes["schemaLocation"] |
933 if filepath is not None and not os.path.exists(filepath): |
933 if filepath is not None and not os.path.exists(filepath): |
966 factory.TargetNamespace = factory.DefinedNamespaces.get(targetNamespace, None) |
966 factory.TargetNamespace = factory.DefinedNamespaces.get(targetNamespace, None) |
967 if factory.TargetNamespace is not None: |
967 if factory.TargetNamespace is not None: |
968 factory.etreeNamespaceFormat = "{%s}%%s" % targetNamespace |
968 factory.etreeNamespaceFormat = "{%s}%%s" % targetNamespace |
969 factory.Namespaces[factory.TargetNamespace] = {} |
969 factory.Namespaces[factory.TargetNamespace] = {} |
970 |
970 |
971 annotations, children = factory.ReduceElements(elements, True) |
971 _annotations, children = factory.ReduceElements(elements, True) |
972 |
972 |
973 for child in children: |
973 for child in children: |
974 if "name" in child: |
974 if "name" in child: |
975 infos = factory.GetQualifiedNameInfos(child["name"], factory.TargetNamespace, True) |
975 infos = factory.GetQualifiedNameInfos(child["name"], factory.TargetNamespace, True) |
976 if infos is None: |
976 if infos is None: |
1087 raise ValueError("\"%s\" isn't of the expected type!" % element_name) |
1087 raise ValueError("\"%s\" isn't of the expected type!" % element_name) |
1088 return element |
1088 return element |
1089 |
1089 |
1090 def CreateSchemaElement(self, element_name, element_type): |
1090 def CreateSchemaElement(self, element_name, element_type): |
1091 for type, attributes, elements in self.Schema[2]: |
1091 for type, attributes, elements in self.Schema[2]: |
1092 namespace, name = DecomposeQualifiedName(type) |
1092 _namespace, name = DecomposeQualifiedName(type) |
1093 if attributes.get("name", None) == element_name: |
1093 if attributes.get("name", None) == element_name: |
1094 element_infos = None |
1094 element_infos = None |
1095 if element_type in (ATTRIBUTE, None) and name == "attribute": |
1095 if element_type in (ATTRIBUTE, None) and name == "attribute": |
1096 element_infos = ReduceAttribute(self, attributes, elements) |
1096 element_infos = ReduceAttribute(self, attributes, elements) |
1097 elif element_type in (ELEMENT, None) and name == "element": |
1097 elif element_type in (ELEMENT, None) and name == "element": |