author | laurent |
Tue, 27 Mar 2012 23:50:19 +0200 | |
changeset 658 | 89d20745b061 |
parent 592 | 89ff2738ef20 |
child 674 | bbffe4110141 |
permissions | -rw-r--r-- |
565 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
25 |
import os, re |
565 | 26 |
import datetime |
27 |
from xml.dom import minidom |
|
28 |
from types import * |
|
29 |
||
30 |
from xmlclass import * |
|
31 |
||
32 |
def GenerateDictFacets(facets): |
|
33 |
return dict([(name, (None, False)) for name in facets]) |
|
34 |
||
35 |
def GenerateSimpleTypeXMLText(function): |
|
36 |
def generateXMLTextMethod(value, name=None, indent=0): |
|
37 |
text = "" |
|
38 |
if name is not None: |
|
39 |
ind1, ind2 = getIndent(indent, name) |
|
40 |
text += ind1 + "<%s>" % name |
|
41 |
text += function(value) |
|
42 |
if name is not None: |
|
43 |
text += "</%s>\n" % name |
|
44 |
return text |
|
45 |
return generateXMLTextMethod |
|
46 |
||
47 |
def GenerateFloatXMLText(extra_values=[]): |
|
48 |
def generateXMLTextMethod(value, name=None, indent=0): |
|
49 |
text = "" |
|
50 |
if name is not None: |
|
51 |
ind1, ind2 = getIndent(indent, name) |
|
52 |
text += ind1 + "<%s>" % name |
|
53 |
if value in extra_values or value % 1 != 0 or isinstance(value, IntType): |
|
54 |
text += str(value) |
|
55 |
else: |
|
56 |
text += "%.0f" % value |
|
57 |
if name is not None: |
|
58 |
text += "</%s>\n" % name |
|
59 |
return text |
|
60 |
return generateXMLTextMethod |
|
61 |
||
62 |
DEFAULT_FACETS = GenerateDictFacets(["pattern", "whiteSpace", "enumeration"]) |
|
63 |
NUMBER_FACETS = GenerateDictFacets(DEFAULT_FACETS.keys() + ["maxInclusive", "maxExclusive", "minInclusive", "minExclusive"]) |
|
64 |
DECIMAL_FACETS = GenerateDictFacets(NUMBER_FACETS.keys() + ["totalDigits", "fractionDigits"]) |
|
65 |
STRING_FACETS = GenerateDictFacets(DEFAULT_FACETS.keys() + ["length", "minLength", "maxLength"]) |
|
66 |
||
67 |
ALL_FACETS = ["pattern", "whiteSpace", "enumeration", "maxInclusive", |
|
68 |
"maxExclusive", "minInclusive", "minExclusive", "totalDigits", |
|
69 |
"fractionDigits", "length", "minLength", "maxLength"] |
|
70 |
||
71 |
||
72 |
#------------------------------------------------------------------------------- |
|
73 |
# Structure reducing functions |
|
74 |
#------------------------------------------------------------------------------- |
|
75 |
||
76 |
||
77 |
# Documentation elements |
|
78 |
||
79 |
def ReduceAppInfo(factory, attributes, elements): |
|
80 |
return {"type": "appinfo", "source": attributes.get("source", None), |
|
81 |
"content": "\n".join(elements)} |
|
82 |
||
83 |
||
84 |
def ReduceDocumentation(factory, attributes, elements): |
|
85 |
return {"type": "documentation", "source": attributes.get("source", None), |
|
86 |
"language": attributes.get("lang", "any"), "content": "\n".join(elements)} |
|
87 |
||
88 |
||
89 |
def ReduceAnnotation(factory, attributes, elements): |
|
90 |
annotations, children = factory.ReduceElements(elements) |
|
91 |
annotation = {"type": "annotation", "appinfo": [], "documentation": {}} |
|
92 |
for child in children: |
|
93 |
if child["type"] == "appinfo": |
|
94 |
annotation["appinfo"].append((child["source"], child["content"])) |
|
95 |
elif child["type"] == "documentation": |
|
96 |
if child["source"] is not None: |
|
97 |
text = "(source: %(source)s):\n%(content)s\n\n"%child |
|
98 |
else: |
|
99 |
text = child["content"] + "\n\n" |
|
100 |
if not annotation["documentation"].has_key(child["language"]): |
|
101 |
annotation["documentation"] = text |
|
102 |
else: |
|
103 |
annotation["documentation"] += text |
|
104 |
return annotation |
|
105 |
||
106 |
# Simple type elements |
|
107 |
||
108 |
def GenerateFacetReducing(facetname, canbefixed): |
|
109 |
def ReduceFacet(factory, attributes, elements): |
|
110 |
annotations, children = factory.ReduceElements(elements) |
|
111 |
if attributes.has_key("value"): |
|
112 |
facet = {"type": facetname, "value": attributes["value"], "doc": annotations} |
|
113 |
if canbefixed: |
|
114 |
facet["fixed"] = attributes.get("fixed", False) |
|
115 |
return facet |
|
116 |
raise ValueError("A value must be defined for the \"%s\" facet!" % facetname) |
|
117 |
return ReduceFacet |
|
118 |
||
119 |
||
120 |
def ReduceList(factory, attributes, elements): |
|
121 |
annotations, children = factory.ReduceElements(elements) |
|
122 |
list = {"type": "list", "itemType": attributes.get("itemType", None), "doc": annotations} |
|
123 |
||
124 |
if len(children) > 0 and children[0]["type"] == SIMPLETYPE: |
|
125 |
if list["itemType"] is None: |
|
126 |
list["itemType"] = children[0] |
|
127 |
else: |
|
128 |
raise ValueError("Only one base type can be defined for restriction!") |
|
129 |
if list["itemType"] is None: |
|
130 |
raise ValueError("No base type has been defined for list!") |
|
131 |
return list |
|
132 |
||
133 |
||
134 |
def ReduceUnion(factory, attributes, elements): |
|
135 |
annotations, children = factory.ReduceElements(elements) |
|
136 |
union = {"type": "union", "memberTypes": attributes.get("memberTypes", []), "doc": annotations} |
|
137 |
||
138 |
for child in children: |
|
139 |
if child["type"] == SIMPLETYPE: |
|
140 |
union["memberTypes"].appendchild |
|
141 |
if len(union["memberTypes"]) == 0: |
|
142 |
raise ValueError("No base type has been defined for union!") |
|
143 |
return union |
|
144 |
||
145 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
146 |
def CreateSimpleType(factory, attributes, typeinfos): |
565 | 147 |
# Initialize type informations |
148 |
facets = {} |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
149 |
simpleType = {"type": SIMPLETYPE, "final": attributes.get("final", [])} |
565 | 150 |
if attributes.has_key("name"): |
151 |
simpleType["name"] = attributes["name"] |
|
152 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
153 |
if typeinfos["type"] in ["restriction", "extension"]: |
565 | 154 |
# Search for base type definition |
155 |
if isinstance(typeinfos["base"], (StringType, UnicodeType)): |
|
156 |
basetypeinfos = factory.FindSchemaElement(typeinfos["base"], SIMPLETYPE) |
|
157 |
if basetypeinfos is None: |
|
158 |
raise "\"%s\" isn't defined!" % typeinfos["base"] |
|
159 |
else: |
|
160 |
basetypeinfos = typeinfos["base"] |
|
161 |
||
162 |
# Check that base type is a simple type |
|
163 |
if basetypeinfos["type"] != SIMPLETYPE: |
|
164 |
raise ValueError("Base type given isn't a simpleType!") |
|
165 |
||
166 |
simpleType["basename"] = basetypeinfos["basename"] |
|
167 |
||
168 |
# Check that derivation is allowed |
|
169 |
if basetypeinfos.has_key("final"): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
170 |
if "#all" in basetypeinfos["final"]: |
565 | 171 |
raise ValueError("Base type can't be derivated!") |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
172 |
if "restriction" in basetypeinfos["final"] and typeinfos["type"] == "restriction": |
565 | 173 |
raise ValueError("Base type can't be derivated by restriction!") |
174 |
||
175 |
# Extract simple type facets |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
176 |
for facet in typeinfos.get("facets", []): |
565 | 177 |
facettype = facet["type"] |
178 |
if not basetypeinfos["facets"].has_key(facettype): |
|
179 |
raise ValueError("\"%s\" facet can't be defined for \"%s\" type!" % (facettype, type)) |
|
180 |
elif basetypeinfos["facets"][facettype][1]: |
|
181 |
raise ValueError("\"%s\" facet is fixed on base type!" % facettype) |
|
182 |
value = facet["value"] |
|
183 |
basevalue = basetypeinfos["facets"][facettype][0] |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
184 |
if facettype in ["enumeration", "pattern"]: |
565 | 185 |
value = basetypeinfos["extract"](value, False) |
186 |
if len(facets) == 0: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
187 |
facets[facettype] = ([value], False) |
565 | 188 |
continue |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
189 |
elif facets.keys() == [facettype]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
190 |
facets[facettype][0].append(value) |
565 | 191 |
continue |
192 |
else: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
193 |
raise ValueError("\"%s\" facet can't be defined with another facet type!" % facettype) |
565 | 194 |
elif facets.has_key("enumeration"): |
195 |
raise ValueError("\"enumeration\" facet can't be defined with another facet type!") |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
196 |
elif facets.has_key("pattern"): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
197 |
raise ValueError("\"pattern\" facet can't be defined with another facet type!") |
565 | 198 |
elif facets.has_key(facettype): |
199 |
raise ValueError("\"%s\" facet can't be defined two times!" % facettype) |
|
200 |
elif facettype == "length": |
|
201 |
if facets.has_key("minLength"): |
|
202 |
raise ValueError("\"length\" and \"minLength\" facets can't be defined at the same time!") |
|
203 |
if facets.has_key("maxLength"): |
|
204 |
raise ValueError("\"length\" and \"maxLength\" facets can't be defined at the same time!") |
|
205 |
try: |
|
206 |
value = int(value) |
|
207 |
except: |
|
208 |
raise ValueError("\"length\" must be an integer!") |
|
209 |
if value < 0: |
|
210 |
raise ValueError("\"length\" can't be negative!") |
|
211 |
elif basevalue is not None and basevalue != value: |
|
212 |
raise ValueError("\"length\" can't be different from \"length\" defined in base type!") |
|
213 |
elif facettype == "minLength": |
|
214 |
if facets.has_key("length"): |
|
215 |
raise ValueError("\"length\" and \"minLength\" facets can't be defined at the same time!") |
|
216 |
try: |
|
217 |
value = int(value) |
|
218 |
except: |
|
219 |
raise ValueError("\"minLength\" must be an integer!") |
|
220 |
if value < 0: |
|
221 |
raise ValueError("\"minLength\" can't be negative!") |
|
222 |
elif facets.has_key("maxLength") and value > facets["maxLength"]: |
|
223 |
raise ValueError("\"minLength\" must be lesser than or equal to \"maxLength\"!") |
|
224 |
elif basevalue is not None and basevalue < value: |
|
225 |
raise ValueError("\"minLength\" can't be lesser than \"minLength\" defined in base type!") |
|
226 |
elif facettype == "maxLength": |
|
227 |
if facets.has_key("length"): |
|
228 |
raise ValueError("\"length\" and \"maxLength\" facets can't be defined at the same time!") |
|
229 |
try: |
|
230 |
value = int(value) |
|
231 |
except: |
|
232 |
raise ValueError("\"maxLength\" must be an integer!") |
|
233 |
if value < 0: |
|
234 |
raise ValueError("\"maxLength\" can't be negative!") |
|
235 |
elif facets.has_key("minLength") and value < facets["minLength"]: |
|
236 |
raise ValueError("\"minLength\" must be lesser than or equal to \"maxLength\"!") |
|
237 |
elif basevalue is not None and basevalue > value: |
|
238 |
raise ValueError("\"maxLength\" can't be greater than \"maxLength\" defined in base type!") |
|
239 |
elif facettype == "minInclusive": |
|
240 |
if facets.has_key("minExclusive"): |
|
241 |
raise ValueError("\"minExclusive\" and \"minInclusive\" facets can't be defined at the same time!") |
|
242 |
value = basetypeinfos["extract"](facet["value"], False) |
|
243 |
if facets.has_key("maxInclusive") and value > facets["maxInclusive"][0]: |
|
244 |
raise ValueError("\"minInclusive\" must be lesser than or equal to \"maxInclusive\"!") |
|
245 |
elif facets.has_key("maxExclusive") and value >= facets["maxExclusive"][0]: |
|
246 |
raise ValueError("\"minInclusive\" must be lesser than \"maxExclusive\"!") |
|
247 |
elif facettype == "minExclusive": |
|
248 |
if facets.has_key("minInclusive"): |
|
249 |
raise ValueError("\"minExclusive\" and \"minInclusive\" facets can't be defined at the same time!") |
|
250 |
value = basetypeinfos["extract"](facet["value"], False) |
|
251 |
if facets.has_key("maxInclusive") and value >= facets["maxInclusive"][0]: |
|
252 |
raise ValueError("\"minExclusive\" must be lesser than \"maxInclusive\"!") |
|
253 |
elif facets.has_key("maxExclusive") and value >= facets["maxExclusive"][0]: |
|
254 |
raise ValueError("\"minExclusive\" must be lesser than \"maxExclusive\"!") |
|
255 |
elif facettype == "maxInclusive": |
|
256 |
if facets.has_key("maxExclusive"): |
|
257 |
raise ValueError("\"maxExclusive\" and \"maxInclusive\" facets can't be defined at the same time!") |
|
258 |
value = basetypeinfos["extract"](facet["value"], False) |
|
259 |
if facets.has_key("minInclusive") and value < facets["minInclusive"][0]: |
|
260 |
raise ValueError("\"minInclusive\" must be lesser than or equal to \"maxInclusive\"!") |
|
261 |
elif facets.has_key("minExclusive") and value <= facets["minExclusive"][0]: |
|
262 |
raise ValueError("\"minExclusive\" must be lesser than \"maxInclusive\"!") |
|
263 |
elif facettype == "maxExclusive": |
|
264 |
if facets.has_key("maxInclusive"): |
|
265 |
raise ValueError("\"maxExclusive\" and \"maxInclusive\" facets can't be defined at the same time!") |
|
266 |
value = basetypeinfos["extract"](facet["value"], False) |
|
267 |
if facets.has_key("minInclusive") and value <= facets["minInclusive"][0]: |
|
268 |
raise ValueError("\"minInclusive\" must be lesser than \"maxExclusive\"!") |
|
269 |
elif facets.has_key("minExclusive") and value <= facets["minExclusive"][0]: |
|
270 |
raise ValueError("\"minExclusive\" must be lesser than \"maxExclusive\"!") |
|
271 |
elif facettype == "whiteSpace": |
|
272 |
if basevalue == "collapse" and value in ["preserve", "replace"] or basevalue == "replace" and value == "preserve": |
|
273 |
raise ValueError("\"whiteSpace\" is incompatible with \"whiteSpace\" defined in base type!") |
|
274 |
elif facettype == "totalDigits": |
|
275 |
if facets.has_key("fractionDigits") and value <= facets["fractionDigits"][0]: |
|
276 |
raise ValueError("\"fractionDigits\" must be lesser than or equal to \"totalDigits\"!") |
|
277 |
elif basevalue is not None and value > basevalue: |
|
278 |
raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!") |
|
279 |
elif facettype == "fractionDigits": |
|
280 |
if facets.has_key("totalDigits") and value <= facets["totalDigits"][0]: |
|
281 |
raise ValueError("\"fractionDigits\" must be lesser than or equal to \"totalDigits\"!") |
|
282 |
elif basevalue is not None and value > basevalue: |
|
283 |
raise ValueError("\"totalDigits\" can't be greater than \"totalDigits\" defined in base type!") |
|
284 |
facets[facettype] = (value, facet.get("fixed", False)) |
|
285 |
||
286 |
# Report not redefined facet from base type to new created type |
|
287 |
for facettype, facetvalue in basetypeinfos["facets"].items(): |
|
288 |
if not facets.has_key(facettype): |
|
289 |
facets[facettype] = facetvalue |
|
290 |
||
291 |
# Generate extract value for new created type |
|
292 |
def ExtractSimpleTypeValue(attr, extract=True): |
|
293 |
value = basetypeinfos["extract"](attr, extract) |
|
294 |
for facetname, (facetvalue, facetfixed) in facets.items(): |
|
295 |
if facetvalue is not None: |
|
296 |
if facetname == "enumeration" and value not in facetvalue: |
|
297 |
raise ValueError("\"%s\" not in enumerated values" % value) |
|
298 |
elif facetname == "length" and len(value) != facetvalue: |
|
299 |
raise ValueError("value must have a length of %d" % facetvalue) |
|
300 |
elif facetname == "minLength" and len(value) < facetvalue: |
|
301 |
raise ValueError("value must have a length of %d at least" % facetvalue) |
|
302 |
elif facetname == "maxLength" and len(value) > facetvalue: |
|
303 |
raise ValueError("value must have a length of %d at most" % facetvalue) |
|
304 |
elif facetname == "minInclusive" and value < facetvalue: |
|
305 |
raise ValueError("value must be greater than or equal to %s" % str(facetvalue)) |
|
306 |
elif facetname == "minExclusive" and value <= facetvalue: |
|
307 |
raise ValueError("value must be greater than %s" % str(facetvalue)) |
|
308 |
elif facetname == "maxInclusive" and value > facetvalue: |
|
309 |
raise ValueError("value must be lesser than or equal to %s" % str(facetvalue)) |
|
310 |
elif facetname == "maxExclusive" and value >= facetvalue: |
|
311 |
raise ValueError("value must be lesser than %s" % str(facetvalue)) |
|
312 |
elif facetname == "pattern": |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
313 |
model = re.compile("(?:%s)?$" % "|".join(map(lambda x: "(?:%s)" % x, facetvalue))) |
565 | 314 |
result = model.match(value) |
315 |
if result is None: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
316 |
if len(facetvalue) > 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
317 |
raise ValueError("value doesn't follow any of the patterns %s" % ",".join(facetvalue)) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
318 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
319 |
raise ValueError("value doesn't follow the pattern %s" % facetvalue[0]) |
565 | 320 |
elif facetname == "whiteSpace": |
321 |
if facetvalue == "replace": |
|
322 |
value = GetNormalizedString(value, False) |
|
323 |
elif facetvalue == "collapse": |
|
324 |
value = GetToken(value, False) |
|
325 |
return value |
|
326 |
||
327 |
def CheckSimpleTypeValue(value): |
|
328 |
for facetname, (facetvalue, facetfixed) in facets.items(): |
|
329 |
if facetvalue is not None: |
|
330 |
if facetname == "enumeration" and value not in facetvalue: |
|
331 |
return False |
|
332 |
elif facetname == "length" and len(value) != facetvalue: |
|
333 |
return False |
|
334 |
elif facetname == "minLength" and len(value) < facetvalue: |
|
335 |
return False |
|
336 |
elif facetname == "maxLength" and len(value) > facetvalue: |
|
337 |
return False |
|
338 |
elif facetname == "minInclusive" and value < facetvalue: |
|
339 |
return False |
|
340 |
elif facetname == "minExclusive" and value <= facetvalue: |
|
341 |
return False |
|
342 |
elif facetname == "maxInclusive" and value > facetvalue: |
|
343 |
return False |
|
344 |
elif facetname == "maxExclusive" and value >= facetvalue: |
|
345 |
return False |
|
346 |
elif facetname == "pattern": |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
347 |
model = re.compile("(?:%s)?$" % "|".join(map(lambda x: "(?:%s)" % x, facetvalue))) |
565 | 348 |
result = model.match(value) |
349 |
if result is None: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
350 |
if len(facetvalue) > 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
351 |
raise ValueError("value doesn't follow any of the patterns %s" % ",".join(facetvalue)) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
352 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
353 |
raise ValueError("value doesn't follow the pattern %s" % facetvalue[0]) |
565 | 354 |
return True |
355 |
||
356 |
def SimpleTypeInitialValue(): |
|
357 |
for facetname, (facetvalue, facetfixed) in facets.items(): |
|
358 |
if facetvalue is not None: |
|
359 |
if facetname == "enumeration": |
|
360 |
return facetvalue[0] |
|
361 |
elif facetname == "length": |
|
362 |
return " "*facetvalue |
|
363 |
elif facetname == "minLength": |
|
364 |
return " "*minLength |
|
365 |
elif facetname == "minInclusive" and facetvalue > 0: |
|
366 |
return facetvalue |
|
367 |
elif facetname == "minExclusive" and facetvalue >= 0: |
|
368 |
return facetvalue + 1 |
|
369 |
elif facetname == "maxInclusive" and facetvalue < 0: |
|
370 |
return facetvalue |
|
371 |
elif facetname == "maxExclusive" and facetvalue <= 0: |
|
372 |
return facetvalue - 1 |
|
373 |
return basetypeinfos["initial"]() |
|
374 |
||
375 |
GenerateSimpleType = basetypeinfos["generate"] |
|
376 |
||
377 |
elif typeinfos["type"] == "list": |
|
378 |
# Search for item type definition |
|
379 |
if isinstance(typeinfos["itemType"], (StringType, UnicodeType)): |
|
380 |
itemtypeinfos = factory.FindSchemaElement(typeinfos["itemType"], SIMPLETYPE) |
|
381 |
if itemtypeinfos is None: |
|
382 |
raise "\"%s\" isn't defined!" % typeinfos["itemType"] |
|
383 |
else: |
|
384 |
itemtypeinfos = typeinfos["itemType"] |
|
385 |
||
386 |
# Check that item type is a simple type |
|
387 |
if itemtypeinfos["type"] != SIMPLETYPE: |
|
388 |
raise ValueError, "Item type given isn't a simpleType!" |
|
389 |
||
390 |
simpleType["basename"] = "list" |
|
391 |
||
392 |
# Check that derivation is allowed |
|
393 |
if itemtypeinfos.has_key("final"): |
|
394 |
if itemtypeinfos["final"].has_key("#all"): |
|
395 |
raise ValueError("Item type can't be derivated!") |
|
396 |
if itemtypeinfos["final"].has_key("list"): |
|
397 |
raise ValueError("Item type can't be derivated by list!") |
|
398 |
||
399 |
# Generate extract value for new created type |
|
400 |
def ExtractSimpleTypeValue(attr, extract = True): |
|
401 |
values = [] |
|
402 |
for value in GetToken(attr, extract).split(" "): |
|
403 |
values.append(itemtypeinfos["extract"](value, False)) |
|
404 |
return values |
|
405 |
||
406 |
def CheckSimpleTypeValue(value): |
|
407 |
for item in value: |
|
408 |
result = itemtypeinfos["check"](item) |
|
409 |
if not result: |
|
410 |
return result |
|
411 |
return True |
|
412 |
||
413 |
SimpleTypeInitialValue = lambda: [] |
|
414 |
||
415 |
GenerateSimpleType = GenerateSimpleTypeXMLText(lambda x: " ".join(map(itemtypeinfos["generate"], x))) |
|
416 |
||
417 |
facets = GenerateDictFacets(["length", "maxLength", "minLength", "enumeration", "pattern"]) |
|
418 |
facets["whiteSpace"] = ("collapse", False) |
|
419 |
||
420 |
elif typeinfos["type"] == "union": |
|
421 |
# Search for member types definition |
|
422 |
membertypesinfos = [] |
|
423 |
for membertype in typeinfos["memberTypes"]: |
|
424 |
if isinstance(membertype, (StringType, UnicodeType)): |
|
425 |
infos = factory.FindSchemaElement(membertype, SIMPLETYPE) |
|
426 |
if infos is None: |
|
427 |
raise ValueError("\"%s\" isn't defined!" % membertype) |
|
428 |
else: |
|
429 |
infos = membertype |
|
430 |
||
431 |
# Check that member type is a simple type |
|
432 |
if infos["type"] != SIMPLETYPE: |
|
433 |
raise ValueError("Member type given isn't a simpleType!") |
|
434 |
||
435 |
# Check that derivation is allowed |
|
436 |
if infos.has_key("final"): |
|
437 |
if infos["final"].has_key("#all"): |
|
438 |
raise ValueError("Item type can't be derivated!") |
|
439 |
if infos["final"].has_key("union"): |
|
440 |
raise ValueError("Member type can't be derivated by union!") |
|
441 |
||
442 |
membertypesinfos.append(infos) |
|
443 |
||
444 |
simpleType["basename"] = "union" |
|
445 |
||
446 |
# Generate extract value for new created type |
|
447 |
def ExtractSimpleTypeValue(attr, extract = True): |
|
448 |
if extract: |
|
449 |
value = GetAttributeValue(attr) |
|
450 |
else: |
|
451 |
value = attr |
|
452 |
for infos in membertypesinfos: |
|
453 |
try: |
|
454 |
return infos["extract"](attr, False) |
|
455 |
except: |
|
456 |
pass |
|
457 |
raise ValueError("\"%s\" isn't valid for type defined for union!") |
|
458 |
||
459 |
def CheckSimpleTypeValue(value): |
|
460 |
for infos in membertypesinfos: |
|
461 |
result = infos["check"](value) |
|
462 |
if result: |
|
463 |
return result |
|
464 |
return False |
|
465 |
||
466 |
SimpleTypeInitialValue = membertypesinfos[0]["initial"] |
|
467 |
||
468 |
def GenerateSimpleTypeFunction(value): |
|
469 |
if isinstance(value, BooleanType): |
|
470 |
return {True: "true", False: "false"}[value] |
|
471 |
else: |
|
472 |
return str(value) |
|
473 |
GenerateSimpleType = GenerateSimpleTypeXMLText(GenerateSimpleTypeFunction) |
|
474 |
||
475 |
facets = GenerateDictFacets(["pattern", "enumeration"]) |
|
476 |
||
477 |
simpleType["facets"] = facets |
|
478 |
simpleType["extract"] = ExtractSimpleTypeValue |
|
479 |
simpleType["initial"] = SimpleTypeInitialValue |
|
480 |
simpleType["check"] = CheckSimpleTypeValue |
|
481 |
simpleType["generate"] = GenerateSimpleType |
|
482 |
return simpleType |
|
483 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
484 |
def ReduceSimpleType(factory, attributes, elements): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
485 |
# Reduce all the simple type children |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
486 |
annotations, children = factory.ReduceElements(elements) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
487 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
488 |
simpleType = CreateSimpleType(factory, attributes, children[0]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
489 |
simpleType["doc"] = annotations |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
490 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
491 |
return simpleType |
565 | 492 |
|
493 |
# Complex type |
|
494 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
495 |
def ExtractAttributes(factory, elements, base=None): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
496 |
attrs = [] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
497 |
attrnames = {} |
565 | 498 |
if base is not None: |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
499 |
basetypeinfos = factory.FindSchemaElement(base) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
500 |
if not isinstance(basetypeinfos, (UnicodeType, StringType)) and basetypeinfos["type"] == COMPLEXTYPE: |
565 | 501 |
attrnames = dict(map(lambda x:(x["name"], True), basetypeinfos["attributes"])) |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
502 |
|
565 | 503 |
for element in elements: |
504 |
if element["type"] == ATTRIBUTE: |
|
505 |
if attrnames.get(element["name"], False): |
|
506 |
raise ValueError("\"%s\" attribute has been defined two times!" % element["name"]) |
|
507 |
else: |
|
508 |
attrnames[element["name"]] = True |
|
509 |
attrs.append(element) |
|
510 |
elif element["type"] == "attributeGroup": |
|
511 |
attrgroup = factory.FindSchemaElement(element["ref"], ATTRIBUTESGROUP) |
|
512 |
for attr in attrgroup["attributes"]: |
|
513 |
if attrnames.get(attr["name"], False): |
|
514 |
raise ValueError("\"%s\" attribute has been defined two times!" % attr["name"]) |
|
515 |
else: |
|
516 |
attrnames[attr["name"]] = True |
|
517 |
attrs.append(attr) |
|
518 |
elif element["type"] == "anyAttribute": |
|
519 |
raise ValueError("\"anyAttribute\" element isn't supported yet!") |
|
520 |
return attrs |
|
521 |
||
522 |
||
523 |
def ReduceRestriction(factory, attributes, elements): |
|
524 |
annotations, children = factory.ReduceElements(elements) |
|
525 |
restriction = {"type": "restriction", "base": attributes.get("base", None), "facets": [], "doc": annotations} |
|
526 |
if len(children) > 0 and children[0]["type"] == SIMPLETYPE: |
|
527 |
if restriction["base"] is None: |
|
528 |
restriction["base"] = children.pop(0) |
|
529 |
else: |
|
530 |
raise ValueError("Only one base type can be defined for restriction!") |
|
531 |
if restriction["base"] is None: |
|
532 |
raise ValueError("No base type has been defined for restriction!") |
|
533 |
||
534 |
while len(children) > 0 and children[0]["type"] in ALL_FACETS: |
|
535 |
restriction["facets"].append(children.pop(0)) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
536 |
restriction["attributes"] = ExtractAttributes(factory, children, restriction["base"]) |
565 | 537 |
return restriction |
538 |
||
539 |
||
540 |
def ReduceExtension(factory, attributes, elements): |
|
541 |
annotations, children = factory.ReduceElements(elements) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
542 |
if not attributes.has_key("base"): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
543 |
raise ValueError("No base type has been defined for extension!") |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
544 |
extension = {"type": "extension", "attributes": [], "elements": [], "base": attributes["base"], "doc": annotations} |
565 | 545 |
if len(children) > 0: |
546 |
if children[0]["type"] in ["group", "all", CHOICE, "sequence"]: |
|
547 |
group = children.pop(0) |
|
548 |
if group["type"] in ["all", "sequence"]: |
|
549 |
extension["elements"] = group["elements"] |
|
550 |
extension["order"] = group["order"] |
|
551 |
elif group["type"] == CHOICE: |
|
552 |
content = group.copy() |
|
553 |
content["name"] = "content" |
|
554 |
extension["elements"].append(content) |
|
555 |
elif group["type"] == "group": |
|
556 |
elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP) |
|
557 |
if elmtgroup.has_key("elements"): |
|
558 |
extension["elements"] = elmtgroup["elements"] |
|
559 |
extension["order"] = elmtgroup["order"] |
|
560 |
else: |
|
561 |
content = elmtgroup.copy() |
|
562 |
content["name"] = "content" |
|
563 |
extension["elements"].append(content) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
564 |
extension["attributes"] = ExtractAttributes(factory, children) |
565 | 565 |
return extension |
566 |
||
567 |
||
568 |
def ReduceSimpleContent(factory, attributes, elements): |
|
569 |
annotations, children = factory.ReduceElements(elements) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
570 |
|
565 | 571 |
simpleContent = children[0].copy() |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
572 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
573 |
basetypeinfos = factory.FindSchemaElement(simpleContent["base"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
574 |
if basetypeinfos["type"] == SIMPLETYPE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
575 |
contenttypeinfos = simpleContent.copy() |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
576 |
simpleContent.pop("base") |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
577 |
elif basetypeinfos["type"] == COMPLEXTYPE and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
578 |
len(basetypeinfos["elements"]) == 1 and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
579 |
basetypeinfos["elements"][0]["name"] == "content" and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
580 |
basetypeinfos["elements"][0].has_key("elmt_type") and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
581 |
basetypeinfos["elements"][0]["elmt_type"]["type"] == SIMPLETYPE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
582 |
contenttypeinfos = simpleContent.copy() |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
583 |
contenttypeinfos["base"] = basetypeinfos["elements"][0]["elmt_type"] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
584 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
585 |
raise ValueError("No compatible base type defined for simpleContent!") |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
586 |
contenttypeinfos = CreateSimpleType(factory, attributes, contenttypeinfos) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
587 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
588 |
simpleContent["elements"] = [{"name": "content", "type": ELEMENT, |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
589 |
"elmt_type": contenttypeinfos, "doc": annotations, |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
590 |
"minOccurs": 1, "maxOccurs": 1}] |
565 | 591 |
simpleContent["type"] = "simpleContent" |
592 |
return simpleContent |
|
593 |
||
594 |
||
595 |
def ReduceComplexContent(factory, attributes, elements): |
|
596 |
annotations, children = factory.ReduceElements(elements) |
|
597 |
complexContent = children[0].copy() |
|
598 |
complexContent["type"] = "complexContent" |
|
599 |
return complexContent |
|
600 |
||
601 |
||
602 |
def ReduceComplexType(factory, attributes, elements): |
|
603 |
annotations, children = factory.ReduceElements(elements) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
604 |
|
565 | 605 |
if len(children) > 0: |
606 |
if children[0]["type"] in ["simpleContent", "complexContent"]: |
|
607 |
complexType = children[0].copy() |
|
608 |
complexType.update(attributes) |
|
609 |
complexType["type"] = COMPLEXTYPE |
|
610 |
return complexType |
|
611 |
elif children[0]["type"] in ["group", "all", CHOICE, "sequence"]: |
|
612 |
complexType = {"type": COMPLEXTYPE, "elements": [], "order": True, "doc": annotations} |
|
613 |
complexType.update(attributes) |
|
614 |
group = children.pop(0) |
|
615 |
if group["type"] in ["all", "sequence"]: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
616 |
choice_number = 0 |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
617 |
for element in group["elements"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
618 |
if element["type"] == CHOICE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
619 |
choice_number += 1 |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
620 |
if (group["minOccurs"] == 0 or group["maxOccurs"] != 1) and len(group["elements"]) > 1 or choice_number > 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
621 |
content = {"type": CHOICE, "name": "content", "choices": [group], "minOccurs": 1, "maxOccurs": 1} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
622 |
complexType["elements"].append(content) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
623 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
624 |
if len(group["elements"]) == 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
625 |
if group["minOccurs"] == 0: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
626 |
group["elements"][0]["minOccurs"] = group["minOccurs"] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
627 |
if group["maxOccurs"] != 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
628 |
group["elements"][0]["maxOccurs"] = group["maxOccurs"] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
629 |
for element in group["elements"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
630 |
if element["type"] == CHOICE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
631 |
element["name"] = "content" |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
632 |
complexType["elements"] = group["elements"] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
633 |
complexType["order"] = group["order"] |
565 | 634 |
elif group["type"] == CHOICE: |
635 |
content = group.copy() |
|
636 |
content["name"] = "content" |
|
637 |
complexType["elements"].append(content) |
|
638 |
elif group["type"] == "group": |
|
639 |
elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP) |
|
640 |
if elmtgroup.has_key("elements"): |
|
641 |
complexType["elements"] = elmtgroup["elements"] |
|
642 |
complexType["order"] = elmtgroup["order"] |
|
643 |
else: |
|
644 |
content = elmtgroup.copy() |
|
645 |
content["name"] = "content" |
|
646 |
complexType["elements"].append(content) |
|
647 |
else: |
|
648 |
complexType = {"elements": [], "order": True, "doc": annotations} |
|
649 |
complexType.update(attributes) |
|
650 |
complexType["type"] = COMPLEXTYPE |
|
651 |
complexType["attributes"] = ExtractAttributes(factory, children) |
|
652 |
return complexType |
|
653 |
else: |
|
654 |
raise ValueError("\"ComplexType\" can't be empty!") |
|
655 |
||
656 |
||
657 |
# Attribute elements |
|
658 |
||
659 |
def ReduceAnyAttribute(factory, attributes, elements): |
|
660 |
return {"type" : "anyAttribute"} |
|
661 |
||
662 |
||
663 |
def ReduceAttribute(factory, attributes, elements): |
|
664 |
annotations, children = factory.ReduceElements(elements) |
|
665 |
||
666 |
if attributes.has_key("default"): |
|
667 |
if attributes.has_key("fixed"): |
|
668 |
raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!") |
|
669 |
elif attributes.get("use", "optional") != "optional": |
|
670 |
raise ValueError("if \"default\" present, \"use\" can only have the value \"optional\"!") |
|
671 |
||
672 |
attribute = {"type": ATTRIBUTE, "attr_type": attributes.get("type", None), "doc": annotations} |
|
673 |
if len(children) > 0: |
|
674 |
if attribute["attr_type"] is None: |
|
675 |
attribute["attr_type"] = children[0] |
|
676 |
else: |
|
677 |
raise ValueError("Only one type can be defined for attribute!") |
|
678 |
||
679 |
if attributes.has_key("ref"): |
|
680 |
if attributes.has_key("name"): |
|
681 |
raise ValueError("\"ref\" and \"name\" can't be defined at the same time!") |
|
682 |
elif attributes.has_key("form"): |
|
683 |
raise ValueError("\"ref\" and \"form\" can't be defined at the same time!") |
|
684 |
elif attribute["attr_type"] is not None: |
|
685 |
raise ValueError("if \"ref\" is present, no type can be defined!") |
|
686 |
elif attribute["attr_type"] is None: |
|
687 |
raise ValueError("No type has been defined for attribute \"%s\"!" % attributes["name"]) |
|
688 |
||
689 |
if attributes.has_key("type"): |
|
690 |
tmp_attrs = attributes.copy() |
|
691 |
tmp_attrs.pop("type") |
|
692 |
attribute.update(tmp_attrs) |
|
693 |
else: |
|
694 |
attribute.update(attributes) |
|
695 |
return attribute |
|
696 |
||
697 |
||
698 |
def ReduceAttributeGroup(factory, attributes, elements): |
|
699 |
annotations, children = factory.ReduceElements(elements) |
|
700 |
if attributes.has_key("ref"): |
|
701 |
return {"type": "attributeGroup", "ref": attributes["ref"], "doc": annotations} |
|
702 |
else: |
|
703 |
return {"type": ATTRIBUTESGROUP, "attributes": ExtractAttributes(factory, children), "doc": annotations} |
|
704 |
||
705 |
||
706 |
# Elements groups |
|
707 |
||
708 |
def ReduceAny(factory, attributes, elements): |
|
709 |
annotations, children = factory.ReduceElements(elements) |
|
710 |
||
711 |
any = {"type": ANY, "doc": annotations} |
|
712 |
any.update(attributes) |
|
713 |
return any |
|
714 |
||
715 |
def ReduceElement(factory, attributes, elements): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
716 |
annotations, children = factory.ReduceElements(elements) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
717 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
718 |
types = [] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
719 |
constraints = [] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
720 |
for child in children: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
721 |
if child["type"] == CONSTRAINT: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
722 |
constraints.append(child) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
723 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
724 |
types.append(child) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
725 |
|
565 | 726 |
if attributes.has_key("default") and attributes.has_key("fixed"): |
727 |
raise ValueError("\"default\" and \"fixed\" can't be defined at the same time!") |
|
728 |
||
729 |
if attributes.has_key("ref"): |
|
730 |
for attr in ["name", "default", "fixed", "form", "block", "type"]: |
|
731 |
if attributes.has_key(attr): |
|
732 |
raise ValueError("\"ref\" and \"%s\" can't be defined at the same time!" % attr) |
|
733 |
if attributes.has_key("nillable"): |
|
734 |
raise ValueError("\"ref\" and \"nillable\" can't be defined at the same time!") |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
735 |
if len(types) > 0: |
565 | 736 |
raise ValueError("No type and no constraints can be defined where \"ref\" is defined!") |
737 |
||
738 |
infos = factory.FindSchemaElement(attributes["ref"], ELEMENT) |
|
739 |
if infos is not None: |
|
740 |
element = infos.copy() |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
741 |
element["constraints"] = constraints |
565 | 742 |
element["minOccurs"] = attributes["minOccurs"] |
743 |
element["maxOccurs"] = attributes["maxOccurs"] |
|
744 |
return element |
|
745 |
else: |
|
746 |
raise ValueError("\"%s\" base type isn't defined or circular referenced!" % name) |
|
747 |
||
748 |
elif attributes.has_key("name"): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
749 |
element = {"type": ELEMENT, "elmt_type": attributes.get("type", None), "constraints": constraints, "doc": annotations} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
750 |
if len(types) > 0: |
565 | 751 |
if element["elmt_type"] is None: |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
752 |
element["elmt_type"] = types[0] |
565 | 753 |
else: |
754 |
raise ValueError("Only one type can be defined for attribute!") |
|
755 |
elif element["elmt_type"] is None: |
|
756 |
element["elmt_type"] = "tag" |
|
757 |
element["type"] = TAG |
|
758 |
||
759 |
if attributes.has_key("type"): |
|
760 |
tmp_attrs = attributes.copy() |
|
761 |
tmp_attrs.pop("type") |
|
762 |
element.update(tmp_attrs) |
|
763 |
else: |
|
764 |
element.update(attributes) |
|
765 |
return element |
|
766 |
else: |
|
767 |
raise ValueError("\"Element\" must have at least a \"ref\" or a \"name\" defined!") |
|
768 |
||
769 |
def ReduceAll(factory, attributes, elements): |
|
770 |
annotations, children = factory.ReduceElements(elements) |
|
771 |
||
772 |
for child in children: |
|
773 |
if children["maxOccurs"] == "unbounded" or children["maxOccurs"] > 1: |
|
774 |
raise ValueError("\"all\" item can't have \"maxOccurs\" attribute greater than 1!") |
|
775 |
||
776 |
return {"type": "all", "elements": children, "minOccurs": attributes["minOccurs"], |
|
777 |
"maxOccurs": attributes["maxOccurs"], "order": False, "doc": annotations} |
|
778 |
||
779 |
||
780 |
def ReduceChoice(factory, attributes, elements): |
|
781 |
annotations, children = factory.ReduceElements(elements) |
|
782 |
||
783 |
choices = [] |
|
784 |
for child in children: |
|
785 |
if child["type"] in [ELEMENT, ANY, TAG]: |
|
786 |
choices.append(child) |
|
787 |
elif child["type"] == "sequence": |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
788 |
child["minOccurs"] = child["maxOccurs"] = 1 |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
789 |
choices.append(child) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
790 |
#raise ValueError("\"sequence\" in \"choice\" is not supported. Create instead a new complex type!") |
565 | 791 |
elif child["type"] == CHOICE: |
792 |
choices.extend(child["choices"]) |
|
793 |
elif child["type"] == "group": |
|
794 |
elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP) |
|
795 |
if not elmtgroup.has_key("choices"): |
|
796 |
raise ValueError("Only group composed of \"choice\" can be referenced in \"choice\" element!") |
|
797 |
choices_tmp = [] |
|
798 |
for choice in elmtgroup["choices"]: |
|
799 |
if not isinstance(choice["elmt_type"], (UnicodeType, StringType)) and choice["elmt_type"]["type"] == COMPLEXTYPE: |
|
800 |
elmt_type = "%s_%s" % (elmtgroup["name"], choice["name"]) |
|
801 |
if factory.TargetNamespace is not None: |
|
802 |
elmt_type = "%s:%s" % (factory.TargetNamespace, elmt_type) |
|
803 |
new_choice = choice.copy() |
|
804 |
new_choice["elmt_type"] = elmt_type |
|
805 |
choices_tmp.append(new_choice) |
|
806 |
else: |
|
807 |
choices_tmp.append(choice) |
|
808 |
choices.extend(choices_tmp) |
|
809 |
||
810 |
return {"type": CHOICE, "choices": choices, "minOccurs": attributes["minOccurs"], |
|
811 |
"maxOccurs": attributes["maxOccurs"], "doc": annotations} |
|
812 |
||
813 |
||
814 |
def ReduceSequence(factory, attributes, elements): |
|
815 |
annotations, children = factory.ReduceElements(elements) |
|
816 |
||
817 |
sequence = [] |
|
818 |
for child in children: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
819 |
if child["type"] in [ELEMENT, ANY, TAG, CHOICE]: |
565 | 820 |
sequence.append(child) |
821 |
elif child["type"] == "sequence": |
|
822 |
sequence.extend(child["elements"]) |
|
823 |
elif child["type"] == "group": |
|
824 |
elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP) |
|
825 |
if not elmtgroup.has_key("elements") or not elmtgroup["order"]: |
|
826 |
raise ValueError("Only group composed of \"sequence\" can be referenced in \"sequence\" element!") |
|
827 |
elements_tmp = [] |
|
828 |
for element in elmtgroup["elements"]: |
|
829 |
if not isinstance(element["elmt_type"], (UnicodeType, StringType)) and element["elmt_type"]["type"] == COMPLEXTYPE: |
|
830 |
elmt_type = "%s_%s"%(elmtgroup["name"], element["name"]) |
|
831 |
if factory.TargetNamespace is not None: |
|
832 |
elmt_type = "%s:%s" % (factory.TargetNamespace, elmt_type) |
|
833 |
new_element = element.copy() |
|
834 |
new_element["elmt_type"] = elmt_type |
|
835 |
elements_tmp.append(new_element) |
|
836 |
else: |
|
837 |
elements_tmp.append(element) |
|
838 |
sequence.extend(elements_tmp) |
|
839 |
||
840 |
return {"type": "sequence", "elements": sequence, "minOccurs": attributes["minOccurs"], |
|
841 |
"maxOccurs": attributes["maxOccurs"], "order": True, "doc": annotations} |
|
842 |
||
843 |
||
844 |
def ReduceGroup(factory, attributes, elements): |
|
845 |
annotations, children = factory.ReduceElements(elements) |
|
846 |
||
847 |
if attributes.has_key("ref"): |
|
848 |
return {"type": "group", "ref": attributes["ref"], "doc": annotations} |
|
849 |
else: |
|
850 |
element = children[0] |
|
851 |
group = {"type": ELEMENTSGROUP, "doc": annotations} |
|
852 |
if element["type"] == CHOICE: |
|
853 |
group["choices"] = element["choices"] |
|
854 |
else: |
|
855 |
group.update({"elements": element["elements"], "order": group["order"]}) |
|
856 |
group.update(attributes) |
|
857 |
return group |
|
858 |
||
859 |
# Constraint elements |
|
860 |
||
861 |
def ReduceUnique(factory, attributes, elements): |
|
862 |
annotations, children = factory.ReduceElements(elements) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
863 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
864 |
unique = {"type": CONSTRAINT, "const_type": "unique", "selector": children[0], "fields": children[1:]} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
865 |
unique.update(attributes) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
866 |
return unique |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
867 |
|
565 | 868 |
def ReduceKey(factory, attributes, elements): |
869 |
annotations, children = factory.ReduceElements(elements) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
870 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
871 |
key = {"type": CONSTRAINT, "const_type": "key", "selector": children[0], "fields": children[1:]} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
872 |
key.update(attributes) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
873 |
return key |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
874 |
|
565 | 875 |
def ReduceKeyRef(factory, attributes, elements): |
876 |
annotations, children = factory.ReduceElements(elements) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
877 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
878 |
keyref = {"type": CONSTRAINT, "const_type": "keyref", "selector": children[0], "fields": children[1:]} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
879 |
keyref.update(attributes) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
880 |
return keyref |
565 | 881 |
|
882 |
def ReduceSelector(factory, attributes, elements): |
|
883 |
annotations, children = factory.ReduceElements(elements) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
884 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
885 |
selector = {"type": CONSTRAINT, "const_type": "selector"} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
886 |
selector.update(attributes) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
887 |
return selector |
565 | 888 |
|
889 |
def ReduceField(factory, attributes, elements): |
|
890 |
annotations, children = factory.ReduceElements(elements) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
891 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
892 |
field = {"type": CONSTRAINT, "const_type": "field"} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
893 |
field.update(attributes) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
894 |
return field |
565 | 895 |
|
896 |
||
897 |
# Inclusion elements |
|
898 |
||
899 |
def ReduceImport(factory, attributes, elements): |
|
900 |
annotations, children = factory.ReduceElements(elements) |
|
901 |
raise ValueError("\"import\" element isn't supported yet!") |
|
902 |
||
903 |
def ReduceInclude(factory, attributes, elements): |
|
904 |
annotations, children = factory.ReduceElements(elements) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
905 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
906 |
if factory.FileName is None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
907 |
raise ValueError("Include in XSD string not yet supported") |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
908 |
filepath = attributes["schemaLocation"] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
909 |
if filepath is not None and not os.path.exists(filepath): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
910 |
filepath = os.path.join(factory.BaseFolder, filepath) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
911 |
if not os.path.exists(filepath): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
912 |
raise ValueError("No file '%s' found for include" % attributes["schemaLocation"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
913 |
xsdfile = open(filepath, 'r') |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
914 |
include_factory = XSDClassFactory(minidom.parse(xsdfile), filepath) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
915 |
xsdfile.close() |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
916 |
include_factory.CreateClasses() |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
917 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
918 |
if factory.TargetNamespace == include_factory.TargetNamespace: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
919 |
factory.Namespaces[factory.TargetNamespace].update(include_factory.Namespaces[include_factory.TargetNamespace]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
920 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
921 |
factory.Namespaces[include_factory.TargetNamespace] = include_factory.Namespaces[include_factory.TargetNamespace] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
922 |
factory.ComputedClasses.update(include_factory.ComputedClasses) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
923 |
return None |
565 | 924 |
|
925 |
def ReduceRedefine(factory, attributes, elements): |
|
926 |
annotations, children = factory.ReduceElements(elements) |
|
927 |
raise ValueError("\"redefine\" element isn't supported yet!") |
|
928 |
||
929 |
||
930 |
# Schema element |
|
931 |
||
932 |
def ReduceSchema(factory, attributes, elements): |
|
933 |
factory.AttributeFormDefault = attributes["attributeFormDefault"] |
|
934 |
factory.ElementFormDefault = attributes["elementFormDefault"] |
|
935 |
factory.BlockDefault = attributes["blockDefault"] |
|
936 |
factory.FinalDefault = attributes["finalDefault"] |
|
937 |
||
938 |
if attributes.has_key("targetNamespace"): |
|
939 |
factory.TargetNamespace = factory.DefinedNamespaces.get(attributes["targetNamespace"], None) |
|
940 |
factory.Namespaces[factory.TargetNamespace] = {} |
|
941 |
||
942 |
annotations, children = factory.ReduceElements(elements, True) |
|
943 |
||
944 |
for child in children: |
|
945 |
if child.has_key("name"): |
|
946 |
infos = factory.GetQualifiedNameInfos(child["name"], factory.TargetNamespace, True) |
|
947 |
if infos is None: |
|
948 |
factory.Namespaces[factory.TargetNamespace][child["name"]] = child |
|
949 |
elif not CompareSchema(infos, child): |
|
950 |
raise ValueError("\"%s\" is defined twice in targetNamespace!" % child["name"]) |
|
951 |
||
952 |
def CompareSchema(schema, reference): |
|
953 |
if isinstance(schema, ListType): |
|
954 |
if not isinstance(reference, ListType) or len(schema) != len(reference): |
|
955 |
return False |
|
956 |
for i, value in enumerate(schema): |
|
957 |
result = CompareSchema(value, reference[i]) |
|
958 |
if not result: |
|
959 |
return result |
|
960 |
return True |
|
961 |
elif isinstance(schema, DictType): |
|
962 |
if not isinstance(reference, DictType) or len(schema) != len(reference): |
|
963 |
return False |
|
964 |
for name, value in schema.items(): |
|
965 |
ref_value = reference.get(name, None) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
966 |
if ref_value is None and value != None: |
565 | 967 |
return False |
968 |
result = CompareSchema(value, ref_value) |
|
969 |
if not result: |
|
970 |
return result |
|
971 |
return True |
|
972 |
elif isinstance(schema, FunctionType): |
|
973 |
if not isinstance(reference, FunctionType) or schema.__name__ != reference.__name__: |
|
974 |
return False |
|
975 |
else: |
|
976 |
return True |
|
977 |
return schema == reference |
|
978 |
||
979 |
#------------------------------------------------------------------------------- |
|
980 |
# Base class for XSD schema extraction |
|
981 |
#------------------------------------------------------------------------------- |
|
982 |
||
983 |
||
984 |
class XSDClassFactory(ClassFactory): |
|
985 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
986 |
def __init__(self, document, filepath=None, debug=False): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
987 |
ClassFactory.__init__(self, document, filepath, debug) |
565 | 988 |
self.Namespaces["xml"] = { |
989 |
"lang": { |
|
990 |
"type": SYNTAXATTRIBUTE, |
|
991 |
"extract": { |
|
992 |
"default": GenerateModelNameExtraction("lang", LANGUAGE_model) |
|
993 |
} |
|
994 |
} |
|
995 |
} |
|
996 |
self.Namespaces["xsi"] = { |
|
997 |
"noNamespaceSchemaLocation": { |
|
998 |
"type": SYNTAXATTRIBUTE, |
|
999 |
"extract": { |
|
1000 |
"default": NotSupportedYet("noNamespaceSchemaLocation") |
|
1001 |
} |
|
1002 |
}, |
|
1003 |
"nil": { |
|
1004 |
"type": SYNTAXATTRIBUTE, |
|
1005 |
"extract": { |
|
1006 |
"default": NotSupportedYet("nil") |
|
1007 |
} |
|
1008 |
}, |
|
1009 |
"schemaLocation": { |
|
1010 |
"type": SYNTAXATTRIBUTE, |
|
1011 |
"extract": { |
|
1012 |
"default": NotSupportedYet("schemaLocation") |
|
1013 |
} |
|
1014 |
}, |
|
1015 |
"type": { |
|
1016 |
"type": SYNTAXATTRIBUTE, |
|
1017 |
"extract": { |
|
1018 |
"default": NotSupportedYet("type") |
|
1019 |
} |
|
1020 |
} |
|
1021 |
} |
|
1022 |
||
1023 |
def ParseSchema(self): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1024 |
for child in self.Document.childNodes: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1025 |
if child.nodeType == self.Document.ELEMENT_NODE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1026 |
schema = child |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1027 |
break |
565 | 1028 |
for qualified_name, attr in schema._attrs.items(): |
1029 |
value = GetAttributeValue(attr) |
|
1030 |
if value == "http://www.w3.org/2001/XMLSchema": |
|
1031 |
namespace, name = DecomposeQualifiedName(qualified_name) |
|
1032 |
if namespace == "xmlns": |
|
1033 |
self.DefinedNamespaces["http://www.w3.org/2001/XMLSchema"] = name |
|
1034 |
self.SchemaNamespace = name |
|
1035 |
else: |
|
1036 |
self.DefinedNamespaces["http://www.w3.org/2001/XMLSchema"] = self.SchemaNamespace |
|
1037 |
self.Namespaces[self.SchemaNamespace] = XSD_NAMESPACE |
|
1038 |
self.Schema = XSD_NAMESPACE["schema"]["extract"]["default"](self, schema) |
|
1039 |
ReduceSchema(self, self.Schema[1], self.Schema[2]) |
|
1040 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1041 |
def FindSchemaElement(self, element_name, element_type=None): |
565 | 1042 |
namespace, name = DecomposeQualifiedName(element_name) |
1043 |
element = self.GetQualifiedNameInfos(name, namespace, True) |
|
1044 |
if element is None and namespace == self.TargetNamespace and name not in self.CurrentCompilations: |
|
1045 |
self.CurrentCompilations.append(name) |
|
1046 |
element = self.CreateSchemaElement(name, element_type) |
|
1047 |
self.CurrentCompilations.pop(-1) |
|
1048 |
if element is not None: |
|
1049 |
self.Namespaces[self.TargetNamespace][name] = element |
|
1050 |
if element is None: |
|
1051 |
if name in self.CurrentCompilations: |
|
1052 |
if self.Debug: |
|
1053 |
print "Warning : \"%s\" is circular referenced!" % element_name |
|
1054 |
else: |
|
1055 |
raise ValueError("\"%s\" isn't defined!" % element_name) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1056 |
if element_type is not None and element["type"] != element_type: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1057 |
raise ValueError("\"%s\" isn't of the expected type!" % element_name) |
565 | 1058 |
return element |
1059 |
||
1060 |
def CreateSchemaElement(self, element_name, element_type): |
|
1061 |
for type, attributes, elements in self.Schema[2]: |
|
1062 |
namespace, name = DecomposeQualifiedName(type) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1063 |
if attributes.get("name", None) == element_name: |
565 | 1064 |
element_infos = None |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1065 |
if element_type in (ATTRIBUTE, None) and name == "attribute": |
565 | 1066 |
element_infos = ReduceAttribute(self, attributes, elements) |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1067 |
elif element_type in (ELEMENT, None) and name == "element": |
565 | 1068 |
element_infos = ReduceElement(self, attributes, elements) |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1069 |
elif element_type in (ATTRIBUTESGROUP, None) and name == "attributeGroup": |
565 | 1070 |
element_infos = ReduceAttributeGroup(self, attributes, elements) |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1071 |
elif element_type in (ELEMENTSGROUP, None) and name == "group": |
565 | 1072 |
element_infos = ReduceGroup(self, attributes, elements) |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1073 |
elif element_type in (SIMPLETYPE, None) and name == "simpleType": |
565 | 1074 |
element_infos = ReduceSimpleType(self, attributes, elements) |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1075 |
elif element_type in (COMPLEXTYPE, None) and name == "complexType": |
565 | 1076 |
element_infos = ReduceComplexType(self, attributes, elements) |
1077 |
if element_infos is not None: |
|
1078 |
self.Namespaces[self.TargetNamespace][element_name] = element_infos |
|
1079 |
return element_infos |
|
1080 |
return None |
|
1081 |
||
1082 |
""" |
|
1083 |
This function opens the xsd file and generate the classes from the xml tree |
|
1084 |
""" |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1085 |
def GenerateClassesFromXSD(filepath, declare=False): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1086 |
xsdfile = open(filepath, 'r') |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1087 |
factory = XSDClassFactory(minidom.parse(xsdfile), filepath) |
565 | 1088 |
xsdfile.close() |
1089 |
return GenerateClasses(factory, declare) |
|
1090 |
||
1091 |
""" |
|
1092 |
This function generate the classes from the xsd given as a string |
|
1093 |
""" |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1094 |
def GenerateClassesFromXSDstring(xsdstring, declare=False): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1095 |
return GenerateClasses(XSDClassFactory(minidom.parseString(xsdstring)), declare) |
565 | 1096 |
|
1097 |
||
1098 |
#------------------------------------------------------------------------------- |
|
1099 |
# XSD schema syntax elements |
|
1100 |
#------------------------------------------------------------------------------- |
|
1101 |
||
1102 |
XSD_NAMESPACE = { |
|
1103 |
||
1104 |
#------------------------------------------------------------------------------- |
|
1105 |
# Syntax elements definition |
|
1106 |
#------------------------------------------------------------------------------- |
|
1107 |
||
1108 |
"all": {"struct": """ |
|
1109 |
<all |
|
1110 |
id = ID |
|
1111 |
maxOccurs = 1 : 1 |
|
1112 |
minOccurs = (0 | 1) : 1 |
|
1113 |
{any attributes with non-schema namespace . . .}> |
|
1114 |
Content: (annotation?, element*) |
|
1115 |
</all>""", |
|
1116 |
"type": SYNTAXELEMENT, |
|
1117 |
"extract": { |
|
1118 |
"default": GenerateElement("all", ["id", "maxOccurs", "minOccurs"], |
|
1119 |
re.compile("((?:annotation )?(?:element )*)")) |
|
1120 |
}, |
|
1121 |
"reduce": ReduceAll |
|
1122 |
}, |
|
1123 |
||
1124 |
"annotation": {"struct": """ |
|
1125 |
<annotation |
|
1126 |
id = ID |
|
1127 |
{any attributes with non-schema namespace . . .}> |
|
1128 |
Content: (appinfo | documentation)* |
|
1129 |
</annotation>""", |
|
1130 |
"type": SYNTAXELEMENT, |
|
1131 |
"extract": { |
|
1132 |
"default": GenerateElement("annotation", ["id"], |
|
1133 |
re.compile("((?:app_info |documentation )*)")) |
|
1134 |
}, |
|
1135 |
"reduce": ReduceAnnotation |
|
1136 |
}, |
|
1137 |
||
1138 |
"any": {"struct": """ |
|
1139 |
<any |
|
1140 |
id = ID |
|
1141 |
maxOccurs = (nonNegativeInteger | unbounded) : 1 |
|
1142 |
minOccurs = nonNegativeInteger : 1 |
|
1143 |
namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any |
|
1144 |
processContents = (lax | skip | strict) : strict |
|
1145 |
{any attributes with non-schema namespace . . .}> |
|
1146 |
Content: (annotation?) |
|
1147 |
</any>""", |
|
1148 |
"type": SYNTAXELEMENT, |
|
1149 |
"extract": { |
|
1150 |
"default": GenerateElement("any", |
|
1151 |
["id", "maxOccurs", "minOccurs", "namespace", "processContents"], |
|
1152 |
re.compile("((?:annotation )?(?:simpleType )*)")) |
|
1153 |
}, |
|
1154 |
"reduce": ReduceAny |
|
1155 |
}, |
|
1156 |
||
1157 |
"anyAttribute": {"struct": """ |
|
1158 |
<anyAttribute |
|
1159 |
id = ID |
|
1160 |
namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any |
|
1161 |
processContents = (lax | skip | strict) : strict |
|
1162 |
{any attributes with non-schema namespace . . .}> |
|
1163 |
Content: (annotation?) |
|
1164 |
</anyAttribute>""", |
|
1165 |
"type": SYNTAXELEMENT, |
|
1166 |
"extract": { |
|
1167 |
"default": GenerateElement("anyAttribute", |
|
1168 |
["id", "namespace", "processContents"], ONLY_ANNOTATION) |
|
1169 |
}, |
|
1170 |
"reduce": ReduceAnyAttribute |
|
1171 |
}, |
|
1172 |
||
1173 |
"appinfo": {"struct": """ |
|
1174 |
<appinfo |
|
1175 |
source = anyURI |
|
1176 |
{any attributes with non-schema namespace . . .}> |
|
1177 |
Content: ({any})* |
|
1178 |
</appinfo>""", |
|
1179 |
"type": SYNTAXELEMENT, |
|
1180 |
"extract": { |
|
1181 |
"default": GenerateElement("appinfo", ["source"], re.compile("(.*)"), True) |
|
1182 |
}, |
|
1183 |
"reduce": ReduceAppInfo |
|
1184 |
}, |
|
1185 |
||
1186 |
"attribute": {"struct": """ |
|
1187 |
<attribute |
|
1188 |
default = string |
|
1189 |
fixed = string |
|
1190 |
form = (qualified | unqualified) |
|
1191 |
id = ID |
|
1192 |
name = NCName |
|
1193 |
ref = QName |
|
1194 |
type = QName |
|
1195 |
use = (optional | prohibited | required) : optional |
|
1196 |
{any attributes with non-schema namespace . . .}> |
|
1197 |
Content: (annotation?, simpleType?) |
|
1198 |
</attribute>""", |
|
1199 |
"type": SYNTAXELEMENT, |
|
1200 |
"extract": { |
|
1201 |
"default": GenerateElement("attribute", |
|
1202 |
["default", "fixed", "form", "id", "name", "ref", "type", "use"], |
|
1203 |
re.compile("((?:annotation )?(?:simpleType )?)")), |
|
1204 |
"schema": GenerateElement("attribute", |
|
1205 |
["default", "fixed", "form", "id", "name", "type"], |
|
1206 |
re.compile("((?:annotation )?(?:simpleType )?)")) |
|
1207 |
}, |
|
1208 |
"reduce": ReduceAttribute |
|
1209 |
}, |
|
1210 |
||
1211 |
"attributeGroup": {"struct": """ |
|
1212 |
<attributeGroup |
|
1213 |
id = ID |
|
1214 |
name = NCName |
|
1215 |
ref = QName |
|
1216 |
{any attributes with non-schema namespace . . .}> |
|
1217 |
Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?)) |
|
1218 |
</attributeGroup>""", |
|
1219 |
"type": SYNTAXELEMENT, |
|
1220 |
"extract": { |
|
1221 |
"default": GenerateElement("attributeGroup", |
|
1222 |
["id", "ref"], ONLY_ANNOTATION), |
|
1223 |
"schema": GenerateElement("attributeGroup", |
|
1224 |
["id", "name"], |
|
1225 |
re.compile("((?:annotation )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))")) |
|
1226 |
}, |
|
1227 |
"reduce": ReduceAttributeGroup |
|
1228 |
}, |
|
1229 |
||
1230 |
"choice": {"struct": """ |
|
1231 |
<choice |
|
1232 |
id = ID |
|
1233 |
maxOccurs = (nonNegativeInteger | unbounded) : 1 |
|
1234 |
minOccurs = nonNegativeInteger : 1 |
|
1235 |
{any attributes with non-schema namespace . . .}> |
|
1236 |
Content: (annotation?, (element | group | choice | sequence | any)*) |
|
1237 |
</choice>""", |
|
1238 |
"type": SYNTAXELEMENT, |
|
1239 |
"extract": { |
|
1240 |
"default": GenerateElement("choice", ["id", "maxOccurs", "minOccurs"], |
|
1241 |
re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)")) |
|
1242 |
}, |
|
1243 |
"reduce": ReduceChoice |
|
1244 |
}, |
|
1245 |
||
1246 |
"complexContent": {"struct": """ |
|
1247 |
<complexContent |
|
1248 |
id = ID |
|
1249 |
mixed = boolean |
|
1250 |
{any attributes with non-schema namespace . . .}> |
|
1251 |
Content: (annotation?, (restriction | extension)) |
|
1252 |
</complexContent>""", |
|
1253 |
"type": SYNTAXELEMENT, |
|
1254 |
"extract": { |
|
1255 |
"default": GenerateElement("complexContent", ["id", "mixed"], |
|
1256 |
re.compile("((?:annotation )?(?:restriction |extension ))")) |
|
1257 |
}, |
|
1258 |
"reduce": ReduceComplexContent |
|
1259 |
}, |
|
1260 |
||
1261 |
"complexType": {"struct": """ |
|
1262 |
<complexType |
|
1263 |
abstract = boolean : false |
|
1264 |
block = (#all | List of (extension | restriction)) |
|
1265 |
final = (#all | List of (extension | restriction)) |
|
1266 |
id = ID |
|
1267 |
mixed = boolean : false |
|
1268 |
name = NCName |
|
1269 |
{any attributes with non-schema namespace . . .}> |
|
1270 |
Content: (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))) |
|
1271 |
</complexType>""", |
|
1272 |
"type": SYNTAXELEMENT, |
|
1273 |
"extract": { |
|
1274 |
"default": GenerateElement("complexType", |
|
1275 |
["abstract", "block", "final", "id", "mixed", "name"], |
|
1276 |
re.compile("((?:annotation )?(?:simpleContent |complexContent |(?:(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))))")) |
|
1277 |
}, |
|
1278 |
"reduce": ReduceComplexType |
|
1279 |
}, |
|
1280 |
||
1281 |
"documentation": {"struct" : """ |
|
1282 |
<documentation |
|
1283 |
source = anyURI |
|
1284 |
xml:lang = language |
|
1285 |
{any attributes with non-schema namespace . . .}> |
|
1286 |
Content: ({any})* |
|
1287 |
</documentation>""", |
|
1288 |
"type": SYNTAXELEMENT, |
|
1289 |
"extract": { |
|
1290 |
"default": GenerateElement("documentation", |
|
1291 |
["source", "lang"], re.compile("(.*)"), True) |
|
1292 |
}, |
|
1293 |
"reduce": ReduceDocumentation |
|
1294 |
}, |
|
1295 |
||
1296 |
"element": {"struct": """ |
|
1297 |
<element |
|
1298 |
abstract = boolean : false |
|
1299 |
block = (#all | List of (extension | restriction | substitution)) |
|
1300 |
default = string |
|
1301 |
final = (#all | List of (extension | restriction)) |
|
1302 |
fixed = string |
|
1303 |
form = (qualified | unqualified) |
|
1304 |
id = ID |
|
1305 |
maxOccurs = (nonNegativeInteger | unbounded) : 1 |
|
1306 |
minOccurs = nonNegativeInteger : 1 |
|
1307 |
name = NCName |
|
1308 |
nillable = boolean : false |
|
1309 |
ref = QName |
|
1310 |
substitutionGroup = QName |
|
1311 |
type = QName |
|
1312 |
{any attributes with non-schema namespace . . .}> |
|
1313 |
Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*)) |
|
1314 |
</element>""", |
|
1315 |
"type": SYNTAXELEMENT, |
|
1316 |
"extract": { |
|
1317 |
"default": GenerateElement("element", |
|
1318 |
["abstract", "block", "default", "final", "fixed", "form", "id", "maxOccurs", "minOccurs", "name", "nillable", "ref", "substitutionGroup", "type"], |
|
1319 |
re.compile("((?:annotation )?(?:simpleType |complexType )?(?:unique |key |keyref )*)")), |
|
1320 |
"schema": GenerateElement("element", |
|
1321 |
["abstract", "block", "default", "final", "fixed", "form", "id", "name", "nillable", "substitutionGroup", "type"], |
|
1322 |
re.compile("((?:annotation )?(?:simpleType |complexType )?(?:unique |key |keyref )*)")) |
|
1323 |
}, |
|
1324 |
"reduce": ReduceElement |
|
1325 |
}, |
|
1326 |
||
1327 |
"enumeration": {"struct": """ |
|
1328 |
<enumeration |
|
1329 |
id = ID |
|
1330 |
value = anySimpleType |
|
1331 |
{any attributes with non-schema namespace . . .}> |
|
1332 |
Content: (annotation?) |
|
1333 |
</enumeration>""", |
|
1334 |
"type": SYNTAXELEMENT, |
|
1335 |
"extract": { |
|
1336 |
"default": GenerateElement("enumeration", ["id", "value"], ONLY_ANNOTATION) |
|
1337 |
}, |
|
1338 |
"reduce": GenerateFacetReducing("enumeration", False) |
|
1339 |
}, |
|
1340 |
||
1341 |
"extension": {"struct": """ |
|
1342 |
<extension |
|
1343 |
base = QName |
|
1344 |
id = ID |
|
1345 |
{any attributes with non-schema namespace . . .}> |
|
1346 |
Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))) |
|
1347 |
</extension>""", |
|
1348 |
"type": SYNTAXELEMENT, |
|
1349 |
"extract": { |
|
1350 |
"default": GenerateElement("extension", ["base", "id"], |
|
1351 |
re.compile("((?:annotation )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))")), |
|
1352 |
"complexContent": GenerateElement("extension", ["base", "id"], |
|
1353 |
re.compile("((?:annotation )?(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?))")) |
|
1354 |
}, |
|
1355 |
"reduce": ReduceExtension |
|
1356 |
}, |
|
1357 |
||
1358 |
"field": {"struct": """ |
|
1359 |
<field |
|
1360 |
id = ID |
|
1361 |
xpath = a subset of XPath expression, see below |
|
1362 |
{any attributes with non-schema namespace . . .}> |
|
1363 |
Content: (annotation?) |
|
1364 |
</field>""", |
|
1365 |
"type": SYNTAXELEMENT, |
|
1366 |
"extract": { |
|
1367 |
"default": GenerateElement("field", ["id", "xpath"], ONLY_ANNOTATION) |
|
1368 |
}, |
|
1369 |
"reduce": ReduceField |
|
1370 |
}, |
|
1371 |
||
1372 |
"fractionDigits": {"struct": """ |
|
1373 |
<fractionDigits |
|
1374 |
fixed = boolean : false |
|
1375 |
id = ID |
|
1376 |
value = nonNegativeInteger |
|
1377 |
{any attributes with non-schema namespace . . .}> |
|
1378 |
Content: (annotation?) |
|
1379 |
</fractionDigits>""", |
|
1380 |
"type": SYNTAXELEMENT, |
|
1381 |
"extract": { |
|
1382 |
"default": GenerateElement("fractionDigits", |
|
1383 |
["fixed", "id", "value"], ONLY_ANNOTATION) |
|
1384 |
}, |
|
1385 |
"reduce": GenerateFacetReducing("fractionDigits", True) |
|
1386 |
}, |
|
1387 |
||
1388 |
"group": {"struct": """ |
|
1389 |
<group |
|
1390 |
id = ID |
|
1391 |
maxOccurs = (nonNegativeInteger | unbounded) : 1 |
|
1392 |
minOccurs = nonNegativeInteger : 1 |
|
1393 |
name = NCName |
|
1394 |
ref = QName |
|
1395 |
{any attributes with non-schema namespace . . .}> |
|
1396 |
Content: (annotation?, (all | choice | sequence)?) |
|
1397 |
</group>""", |
|
1398 |
"type": SYNTAXELEMENT, |
|
1399 |
"extract": { |
|
1400 |
"default": GenerateElement("group", |
|
1401 |
["id", "maxOccurs", "minOccurs", "ref"], |
|
1402 |
re.compile("((?:annotation )?(?:all |choice |sequence )?)")), |
|
1403 |
"schema": GenerateElement("group", |
|
1404 |
["id", "name"], |
|
1405 |
re.compile("((?:annotation )?(?:all |choice |sequence )?)")) |
|
1406 |
}, |
|
1407 |
"reduce": ReduceGroup |
|
1408 |
}, |
|
1409 |
||
1410 |
"import": {"struct": """ |
|
1411 |
<import |
|
1412 |
id = ID |
|
1413 |
namespace = anyURI |
|
1414 |
schemaLocation = anyURI |
|
1415 |
{any attributes with non-schema namespace . . .}> |
|
1416 |
Content: (annotation?) |
|
1417 |
</import>""", |
|
1418 |
"type": SYNTAXELEMENT, |
|
1419 |
"extract": { |
|
1420 |
"default": GenerateElement("import", |
|
1421 |
["id", "namespace", "schemaLocation"], ONLY_ANNOTATION) |
|
1422 |
}, |
|
1423 |
"reduce": ReduceImport |
|
1424 |
}, |
|
1425 |
||
1426 |
"include": {"struct": """ |
|
1427 |
<include |
|
1428 |
id = ID |
|
1429 |
schemaLocation = anyURI |
|
1430 |
{any attributes with non-schema namespace . . .}> |
|
1431 |
Content: (annotation?) |
|
1432 |
</include>""", |
|
1433 |
"type": SYNTAXELEMENT, |
|
1434 |
"extract": { |
|
1435 |
"default": GenerateElement("include", |
|
1436 |
["id", "schemaLocation"], ONLY_ANNOTATION) |
|
1437 |
}, |
|
1438 |
"reduce": ReduceInclude |
|
1439 |
}, |
|
1440 |
||
1441 |
"key": {"struct": """ |
|
1442 |
<key |
|
1443 |
id = ID |
|
1444 |
name = NCName |
|
1445 |
{any attributes with non-schema namespace . . .}> |
|
1446 |
Content: (annotation?, (selector, field+)) |
|
1447 |
</key>""", |
|
1448 |
"type": SYNTAXELEMENT, |
|
1449 |
"extract": { |
|
1450 |
"default": GenerateElement("key", ["id", "name"], |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1451 |
re.compile("((?:annotation )?(?:selector (?:field )+))")) |
565 | 1452 |
}, |
1453 |
"reduce": ReduceKey |
|
1454 |
}, |
|
1455 |
||
1456 |
"keyref": {"struct": """ |
|
1457 |
<keyref |
|
1458 |
id = ID |
|
1459 |
name = NCName |
|
1460 |
refer = QName |
|
1461 |
{any attributes with non-schema namespace . . .}> |
|
1462 |
Content: (annotation?, (selector, field+)) |
|
1463 |
</keyref>""", |
|
1464 |
"type": SYNTAXELEMENT, |
|
1465 |
"extract": { |
|
1466 |
"default": GenerateElement("keyref", ["id", "name", "refer"], |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1467 |
re.compile("((?:annotation )?(?:selector (?:field )+))")) |
565 | 1468 |
}, |
1469 |
"reduce": ReduceKeyRef |
|
1470 |
}, |
|
1471 |
||
1472 |
"length": {"struct" : """ |
|
1473 |
<length |
|
1474 |
fixed = boolean : false |
|
1475 |
id = ID |
|
1476 |
value = nonNegativeInteger |
|
1477 |
{any attributes with non-schema namespace . . .}> |
|
1478 |
Content: (annotation?) |
|
1479 |
</length>""", |
|
1480 |
"type": SYNTAXELEMENT, |
|
1481 |
"extract": { |
|
1482 |
"default": GenerateElement("length", |
|
1483 |
["fixed", "id", "value"], ONLY_ANNOTATION) |
|
1484 |
}, |
|
1485 |
"reduce": GenerateFacetReducing("length", True) |
|
1486 |
}, |
|
1487 |
||
1488 |
"list": {"struct": """ |
|
1489 |
<list |
|
1490 |
id = ID |
|
1491 |
itemType = QName |
|
1492 |
{any attributes with non-schema namespace . . .}> |
|
1493 |
Content: (annotation?, simpleType?) |
|
1494 |
</list>""", |
|
1495 |
"type": SYNTAXELEMENT, |
|
1496 |
"extract": { |
|
1497 |
"default": GenerateElement("list", ["id", "itemType"], |
|
1498 |
re.compile("((?:annotation )?(?:simpleType )?)$")) |
|
1499 |
}, |
|
1500 |
"reduce": ReduceList |
|
1501 |
}, |
|
1502 |
||
1503 |
"maxExclusive": {"struct": """ |
|
1504 |
<maxInclusive |
|
1505 |
fixed = boolean : false |
|
1506 |
id = ID |
|
1507 |
value = anySimpleType |
|
1508 |
{any attributes with non-schema namespace . . .}> |
|
1509 |
Content: (annotation?) |
|
1510 |
</maxInclusive>""", |
|
1511 |
"type": SYNTAXELEMENT, |
|
1512 |
"extract": { |
|
1513 |
"default": GenerateElement("maxExclusive", |
|
1514 |
["fixed", "id", "value"], ONLY_ANNOTATION) |
|
1515 |
}, |
|
1516 |
"reduce": GenerateFacetReducing("maxExclusive", True) |
|
1517 |
}, |
|
1518 |
||
1519 |
"maxInclusive": {"struct": """ |
|
1520 |
<maxExclusive |
|
1521 |
fixed = boolean : false |
|
1522 |
id = ID |
|
1523 |
value = anySimpleType |
|
1524 |
{any attributes with non-schema namespace . . .}> |
|
1525 |
Content: (annotation?) |
|
1526 |
</maxExclusive>""", |
|
1527 |
"type": SYNTAXELEMENT, |
|
1528 |
"extract": { |
|
1529 |
"default": GenerateElement("maxInclusive", |
|
1530 |
["fixed", "id", "value"], ONLY_ANNOTATION) |
|
1531 |
}, |
|
1532 |
"reduce": GenerateFacetReducing("maxInclusive", True) |
|
1533 |
}, |
|
1534 |
||
1535 |
"maxLength": {"struct": """ |
|
1536 |
<maxLength |
|
1537 |
fixed = boolean : false |
|
1538 |
id = ID |
|
1539 |
value = nonNegativeInteger |
|
1540 |
{any attributes with non-schema namespace . . .}> |
|
1541 |
Content: (annotation?) |
|
1542 |
</maxLength>""", |
|
1543 |
"type": SYNTAXELEMENT, |
|
1544 |
"extract": { |
|
1545 |
"default": GenerateElement("maxLength", |
|
1546 |
["fixed", "id", "value"], ONLY_ANNOTATION) |
|
1547 |
}, |
|
1548 |
"reduce": GenerateFacetReducing("maxLength", True) |
|
1549 |
}, |
|
1550 |
||
1551 |
"minExclusive": {"struct": """ |
|
1552 |
<minExclusive |
|
1553 |
fixed = boolean : false |
|
1554 |
id = ID |
|
1555 |
value = anySimpleType |
|
1556 |
{any attributes with non-schema namespace . . .}> |
|
1557 |
Content: (annotation?) |
|
1558 |
</minExclusive>""", |
|
1559 |
"type": SYNTAXELEMENT, |
|
1560 |
"extract": { |
|
1561 |
"default": GenerateElement("minExclusive", |
|
1562 |
["fixed", "id", "value"], ONLY_ANNOTATION) |
|
1563 |
}, |
|
1564 |
"reduce": GenerateFacetReducing("minExclusive", True) |
|
1565 |
}, |
|
1566 |
||
1567 |
"minInclusive": {"struct": """ |
|
1568 |
<minInclusive |
|
1569 |
fixed = boolean : false |
|
1570 |
id = ID |
|
1571 |
value = anySimpleType |
|
1572 |
{any attributes with non-schema namespace . . .}> |
|
1573 |
Content: (annotation?) |
|
1574 |
</minInclusive>""", |
|
1575 |
"type": SYNTAXELEMENT, |
|
1576 |
"extract": { |
|
1577 |
"default": GenerateElement("minInclusive", |
|
1578 |
["fixed", "id", "value"], ONLY_ANNOTATION) |
|
1579 |
}, |
|
1580 |
"reduce": GenerateFacetReducing("minInclusive", True) |
|
1581 |
}, |
|
1582 |
||
1583 |
"minLength": {"struct": """ |
|
1584 |
<minLength |
|
1585 |
fixed = boolean : false |
|
1586 |
id = ID |
|
1587 |
value = nonNegativeInteger |
|
1588 |
{any attributes with non-schema namespace . . .}> |
|
1589 |
Content: (annotation?) |
|
1590 |
</minLength>""", |
|
1591 |
"type": SYNTAXELEMENT, |
|
1592 |
"extract": { |
|
1593 |
"default": GenerateElement("minLength", |
|
1594 |
["fixed", "id", "value"], ONLY_ANNOTATION) |
|
1595 |
}, |
|
1596 |
"reduce": GenerateFacetReducing("minLength", True) |
|
1597 |
}, |
|
1598 |
||
1599 |
"pattern": {"struct": """ |
|
1600 |
<pattern |
|
1601 |
id = ID |
|
1602 |
value = string |
|
1603 |
{any attributes with non-schema namespace . . .}> |
|
1604 |
Content: (annotation?) |
|
1605 |
</pattern>""", |
|
1606 |
"type": SYNTAXELEMENT, |
|
1607 |
"extract": { |
|
1608 |
"default": GenerateElement("pattern", ["id", "value"], ONLY_ANNOTATION) |
|
1609 |
}, |
|
1610 |
"reduce": GenerateFacetReducing("pattern", False) |
|
1611 |
}, |
|
1612 |
||
1613 |
"redefine": {"struct": """ |
|
1614 |
<redefine |
|
1615 |
id = ID |
|
1616 |
schemaLocation = anyURI |
|
1617 |
{any attributes with non-schema namespace . . .}> |
|
1618 |
Content: (annotation | (simpleType | complexType | group | attributeGroup))* |
|
1619 |
</redefine>""", |
|
1620 |
"type": SYNTAXELEMENT, |
|
1621 |
"extract": { |
|
1622 |
"default": GenerateElement("refine", ["id", "schemaLocation"], |
|
1623 |
re.compile("((?:annotation |(?:simpleType |complexType |group |attributeGroup ))*)")) |
|
1624 |
}, |
|
1625 |
"reduce": ReduceRedefine |
|
1626 |
}, |
|
1627 |
||
1628 |
"restriction": {"struct": """ |
|
1629 |
<restriction |
|
1630 |
base = QName |
|
1631 |
id = ID |
|
1632 |
{any attributes with non-schema namespace . . .}> |
|
1633 |
Content: (annotation?, (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)) |
|
1634 |
</restriction>""", |
|
1635 |
"type": SYNTAXELEMENT, |
|
1636 |
"extract": { |
|
1637 |
"default": GenerateElement("restriction", ["base", "id"], |
|
1638 |
re.compile("((?:annotation )?(?:(?:simpleType )?(?:(?:minExclusive |minInclusive |maxExclusive |maxInclusive |totalDigits |fractionDigits |length |minLength |maxLength |enumeration |whiteSpace |pattern )*)))")), |
|
1639 |
"simpleContent": GenerateElement("restriction", ["base", "id"], |
|
1640 |
re.compile("((?:annotation )?(?:(?:simpleType )?(?:(?:minExclusive |minInclusive |maxExclusive |maxInclusive |totalDigits |fractionDigits |length |minLength |maxLength |enumeration |whiteSpace |pattern )*)?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?)))")), |
|
1641 |
"complexContent": GenerateElement("restriction", ["base", "id"], |
|
1642 |
re.compile("((?:annotation )?(?:(?:simpleType )?(?:group |all |choice |sequence )?(?:(?:attribute |attributeGroup )*(?:anyAttribute )?)))")), |
|
1643 |
}, |
|
1644 |
"reduce": ReduceRestriction |
|
1645 |
}, |
|
1646 |
||
1647 |
"schema": {"struct": """ |
|
1648 |
<schema |
|
1649 |
attributeFormDefault = (qualified | unqualified) : unqualified |
|
1650 |
blockDefault = (#all | List of (extension | restriction | substitution)) : '' |
|
1651 |
elementFormDefault = (qualified | unqualified) : unqualified |
|
1652 |
finalDefault = (#all | List of (extension | restriction | list | union)) : '' |
|
1653 |
id = ID |
|
1654 |
targetNamespace = anyURI |
|
1655 |
version = token |
|
1656 |
xml:lang = language |
|
1657 |
{any attributes with non-schema namespace . . .}> |
|
1658 |
Content: ((include | import | redefine | annotation)*, (((simpleType | complexType | group | attributeGroup) | element | attribute | notation), annotation*)*) |
|
1659 |
</schema>""", |
|
1660 |
"type": SYNTAXELEMENT, |
|
1661 |
"extract": { |
|
1662 |
"default": GenerateElement("schema", |
|
1663 |
["attributeFormDefault", "blockDefault", "elementFormDefault", "finalDefault", "id", "targetNamespace", "version", "lang"], |
|
1664 |
re.compile("((?:include |import |redefine |annotation )*(?:(?:(?:simpleType |complexType |group |attributeGroup )|element |attribute |annotation )(?:annotation )*)*)")) |
|
1665 |
} |
|
1666 |
}, |
|
1667 |
||
1668 |
"selector": {"struct": """ |
|
1669 |
<selector |
|
1670 |
id = ID |
|
1671 |
xpath = a subset of XPath expression, see below |
|
1672 |
{any attributes with non-schema namespace . . .}> |
|
1673 |
Content: (annotation?) |
|
1674 |
</selector>""", |
|
1675 |
"type": SYNTAXELEMENT, |
|
1676 |
"extract": { |
|
1677 |
"default": GenerateElement("selector", ["id", "xpath"], ONLY_ANNOTATION) |
|
1678 |
}, |
|
1679 |
"reduce": ReduceSelector |
|
1680 |
}, |
|
1681 |
||
1682 |
"sequence": {"struct": """ |
|
1683 |
<sequence |
|
1684 |
id = ID |
|
1685 |
maxOccurs = (nonNegativeInteger | unbounded) : 1 |
|
1686 |
minOccurs = nonNegativeInteger : 1 |
|
1687 |
{any attributes with non-schema namespace . . .}> |
|
1688 |
Content: (annotation?, (element | group | choice | sequence | any)*) |
|
1689 |
</sequence>""", |
|
1690 |
"type": SYNTAXELEMENT, |
|
1691 |
"extract": { |
|
1692 |
"default": GenerateElement("sequence", ["id", "maxOccurs", "minOccurs"], |
|
1693 |
re.compile("((?:annotation )?(?:element |group |choice |sequence |any )*)")) |
|
1694 |
}, |
|
1695 |
"reduce": ReduceSequence |
|
1696 |
}, |
|
1697 |
||
1698 |
"simpleContent": {"struct" : """ |
|
1699 |
<simpleContent |
|
1700 |
id = ID |
|
1701 |
{any attributes with non-schema namespace . . .}> |
|
1702 |
Content: (annotation?, (restriction | extension)) |
|
1703 |
</simpleContent>""", |
|
1704 |
"type": SYNTAXELEMENT, |
|
1705 |
"extract": { |
|
1706 |
"default": GenerateElement("simpleContent", ["id"], |
|
1707 |
re.compile("((?:annotation )?(?:restriction |extension ))")) |
|
1708 |
}, |
|
1709 |
"reduce": ReduceSimpleContent |
|
1710 |
}, |
|
1711 |
||
1712 |
"simpleType": {"struct" : """ |
|
1713 |
<simpleType |
|
1714 |
final = (#all | List of (list | union | restriction)) |
|
1715 |
id = ID |
|
1716 |
name = NCName |
|
1717 |
{any attributes with non-schema namespace . . .}> |
|
1718 |
Content: (annotation?, (restriction | list | union)) |
|
1719 |
</simpleType>""", |
|
1720 |
"type": SYNTAXELEMENT, |
|
1721 |
"extract": { |
|
1722 |
"default": GenerateElement("simpleType", ["final", "id", "name"], |
|
1723 |
re.compile("((?:annotation )?(?:restriction |list |union ))")) |
|
1724 |
}, |
|
1725 |
"reduce": ReduceSimpleType |
|
1726 |
}, |
|
1727 |
||
1728 |
"totalDigits": {"struct" : """ |
|
1729 |
<totalDigits |
|
1730 |
fixed = boolean : false |
|
1731 |
id = ID |
|
1732 |
value = positiveInteger |
|
1733 |
{any attributes with non-schema namespace . . .}> |
|
1734 |
Content: (annotation?) |
|
1735 |
</totalDigits>""", |
|
1736 |
"type": SYNTAXELEMENT, |
|
1737 |
"extract": { |
|
1738 |
"default": GenerateElement("totalDigits", |
|
1739 |
["fixed", "id", "value"], ONLY_ANNOTATION), |
|
1740 |
}, |
|
1741 |
"reduce": GenerateFacetReducing("totalDigits", True) |
|
1742 |
}, |
|
1743 |
||
1744 |
"union": {"struct": """ |
|
1745 |
<union |
|
1746 |
id = ID |
|
1747 |
memberTypes = List of QName |
|
1748 |
{any attributes with non-schema namespace . . .}> |
|
1749 |
Content: (annotation?, simpleType*) |
|
1750 |
</union>""", |
|
1751 |
"type": SYNTAXELEMENT, |
|
1752 |
"extract": { |
|
1753 |
"default": GenerateElement("union", ["id", "memberTypes"], |
|
1754 |
re.compile("((?:annotation )?(?:simpleType )*)")) |
|
1755 |
}, |
|
1756 |
"reduce": ReduceUnion |
|
1757 |
}, |
|
1758 |
||
1759 |
"unique": {"struct": """ |
|
1760 |
<unique |
|
1761 |
id = ID |
|
1762 |
name = NCName |
|
1763 |
{any attributes with non-schema namespace . . .}> |
|
1764 |
Content: (annotation?, (selector, field+)) |
|
1765 |
</unique>""", |
|
1766 |
"type": SYNTAXELEMENT, |
|
1767 |
"extract": { |
|
1768 |
"default": GenerateElement("unique", ["id", "name"], |
|
1769 |
re.compile("((?:annotation )?(?:selector |(?:field )+))")) |
|
1770 |
}, |
|
1771 |
"reduce": ReduceUnique |
|
1772 |
}, |
|
1773 |
||
1774 |
"whiteSpace": {"struct" : """ |
|
1775 |
<whiteSpace |
|
1776 |
fixed = boolean : false |
|
1777 |
id = ID |
|
1778 |
value = (collapse | preserve | replace) |
|
1779 |
{any attributes with non-schema namespace . . .}> |
|
1780 |
Content: (annotation?) |
|
1781 |
</whiteSpace>""", |
|
1782 |
"type": SYNTAXELEMENT, |
|
1783 |
"extract": { |
|
1784 |
"default": GenerateElement("whiteSpace", |
|
1785 |
["fixed", "id", "value"], ONLY_ANNOTATION) |
|
1786 |
}, |
|
1787 |
"reduce": GenerateFacetReducing("whiteSpace", True) |
|
1788 |
}, |
|
1789 |
||
1790 |
#------------------------------------------------------------------------------- |
|
1791 |
# Syntax attributes definition |
|
1792 |
#------------------------------------------------------------------------------- |
|
1793 |
||
1794 |
"abstract": { |
|
1795 |
"type": SYNTAXATTRIBUTE, |
|
1796 |
"extract": { |
|
1797 |
"default": GetBoolean |
|
1798 |
}, |
|
1799 |
"default": { |
|
1800 |
"default": False |
|
1801 |
} |
|
1802 |
}, |
|
1803 |
||
1804 |
"attributeFormDefault": { |
|
1805 |
"type": SYNTAXATTRIBUTE, |
|
1806 |
"extract": { |
|
1807 |
"default": GenerateEnumeratedExtraction("member attributeFormDefault", ["qualified", "unqualified"]) |
|
1808 |
}, |
|
1809 |
"default": { |
|
1810 |
"default": "unqualified" |
|
1811 |
} |
|
1812 |
}, |
|
1813 |
||
1814 |
"base": { |
|
1815 |
"type": SYNTAXATTRIBUTE, |
|
1816 |
"extract": { |
|
1817 |
"default": GenerateModelNameExtraction("member base", QName_model) |
|
1818 |
} |
|
1819 |
}, |
|
1820 |
||
1821 |
"block": { |
|
1822 |
"type": SYNTAXATTRIBUTE, |
|
1823 |
"extract": { |
|
1824 |
"default": GenerateGetList("block", ["restriction", "extension", "substitution"]) |
|
1825 |
} |
|
1826 |
}, |
|
1827 |
||
1828 |
"blockDefault": { |
|
1829 |
"type": SYNTAXATTRIBUTE, |
|
1830 |
"extract": { |
|
1831 |
"default": GenerateGetList("block", ["restriction", "extension", "substitution"]) |
|
1832 |
}, |
|
1833 |
"default": { |
|
1834 |
"default": "" |
|
1835 |
} |
|
1836 |
}, |
|
1837 |
||
1838 |
"default": { |
|
1839 |
"type": SYNTAXATTRIBUTE, |
|
1840 |
"extract": { |
|
1841 |
"default": GetAttributeValue |
|
1842 |
} |
|
1843 |
}, |
|
1844 |
||
1845 |
"elementFormDefault": { |
|
1846 |
"type": SYNTAXATTRIBUTE, |
|
1847 |
"extract": { |
|
1848 |
"default": GenerateEnumeratedExtraction("member elementFormDefault", ["qualified", "unqualified"]) |
|
1849 |
}, |
|
1850 |
"default": { |
|
1851 |
"default": "unqualified" |
|
1852 |
} |
|
1853 |
}, |
|
1854 |
||
1855 |
"final": { |
|
1856 |
"type": SYNTAXATTRIBUTE, |
|
1857 |
"extract": { |
|
1858 |
"default": GenerateGetList("final", ["restriction", "extension", "substitution"]), |
|
1859 |
"simpleType": GenerateGetList("final", ["list", "union", "restriction"]) |
|
1860 |
} |
|
1861 |
}, |
|
1862 |
||
1863 |
"finalDefault": { |
|
1864 |
"type": SYNTAXATTRIBUTE, |
|
1865 |
"extract": { |
|
1866 |
"default": GenerateGetList("finalDefault", ["restriction", "extension", "list", "union"]) |
|
1867 |
}, |
|
1868 |
"default": { |
|
1869 |
"default": "" |
|
1870 |
} |
|
1871 |
}, |
|
1872 |
||
1873 |
"fixed": { |
|
1874 |
"type": SYNTAXATTRIBUTE, |
|
1875 |
"extract": { |
|
1876 |
"default": GetBoolean, |
|
1877 |
"attribute": GetAttributeValue, |
|
1878 |
"element": GetAttributeValue |
|
1879 |
}, |
|
1880 |
"default": { |
|
1881 |
"default": False, |
|
1882 |
"attribute": None, |
|
1883 |
"element": None |
|
1884 |
} |
|
1885 |
}, |
|
1886 |
||
1887 |
"form": { |
|
1888 |
"type": SYNTAXATTRIBUTE, |
|
1889 |
"extract": { |
|
1890 |
"default": GenerateEnumeratedExtraction("member form", ["qualified", "unqualified"]) |
|
1891 |
} |
|
1892 |
}, |
|
1893 |
||
1894 |
"id": { |
|
1895 |
"type": SYNTAXATTRIBUTE, |
|
1896 |
"extract": { |
|
1897 |
"default": GenerateModelNameExtraction("member id", NCName_model) |
|
1898 |
} |
|
1899 |
}, |
|
1900 |
||
1901 |
"itemType": { |
|
1902 |
"type": SYNTAXATTRIBUTE, |
|
1903 |
"extract": { |
|
1904 |
"default": GenerateModelNameExtraction("member itemType", QName_model) |
|
1905 |
} |
|
1906 |
}, |
|
1907 |
||
1908 |
"memberTypes": { |
|
1909 |
"type": SYNTAXATTRIBUTE, |
|
1910 |
"extract": { |
|
1911 |
"default": GenerateModelNameListExtraction("member memberTypes", QNames_model) |
|
1912 |
}, |
|
1913 |
}, |
|
1914 |
||
1915 |
"maxOccurs": { |
|
1916 |
"type": SYNTAXATTRIBUTE, |
|
1917 |
"extract": { |
|
1918 |
"default": GenerateLimitExtraction(), |
|
1919 |
"all": GenerateLimitExtraction(1, 1, False) |
|
1920 |
}, |
|
1921 |
"default": { |
|
1922 |
"default": 1 |
|
1923 |
} |
|
1924 |
}, |
|
1925 |
||
1926 |
"minOccurs": { |
|
1927 |
"type": SYNTAXATTRIBUTE, |
|
1928 |
"extract": { |
|
1929 |
"default": GenerateLimitExtraction(unbounded = False), |
|
1930 |
"all": GenerateLimitExtraction(0, 1, False) |
|
1931 |
}, |
|
1932 |
"default": { |
|
1933 |
"default": 1 |
|
1934 |
} |
|
1935 |
}, |
|
1936 |
||
1937 |
"mixed": { |
|
1938 |
"type": SYNTAXATTRIBUTE, |
|
1939 |
"extract": { |
|
1940 |
"default": GetBoolean |
|
1941 |
}, |
|
1942 |
"default": { |
|
1943 |
"default": None, |
|
1944 |
"complexType": False |
|
1945 |
} |
|
1946 |
}, |
|
1947 |
||
1948 |
"name": { |
|
1949 |
"type": SYNTAXATTRIBUTE, |
|
1950 |
"extract": { |
|
1951 |
"default": GenerateModelNameExtraction("member name", NCName_model) |
|
1952 |
} |
|
1953 |
}, |
|
1954 |
||
1955 |
"namespace": { |
|
1956 |
"type": SYNTAXATTRIBUTE, |
|
1957 |
"extract": { |
|
1958 |
"default": GenerateModelNameExtraction("member namespace", URI_model), |
|
1959 |
"any": GetNamespaces |
|
1960 |
}, |
|
1961 |
"default": { |
|
1962 |
"default": None, |
|
1963 |
"any": "##any" |
|
1964 |
} |
|
1965 |
}, |
|
1966 |
||
1967 |
"nillable": { |
|
1968 |
"type": SYNTAXATTRIBUTE, |
|
1969 |
"extract": { |
|
1970 |
"default": GetBoolean |
|
1971 |
}, |
|
1972 |
}, |
|
1973 |
||
1974 |
"processContents": { |
|
1975 |
"type": SYNTAXATTRIBUTE, |
|
1976 |
"extract": { |
|
1977 |
"default": GenerateEnumeratedExtraction("member processContents", ["lax", "skip", "strict"]) |
|
1978 |
}, |
|
1979 |
"default": { |
|
1980 |
"default": "strict" |
|
1981 |
} |
|
1982 |
}, |
|
1983 |
||
1984 |
"ref": { |
|
1985 |
"type": SYNTAXATTRIBUTE, |
|
1986 |
"extract": { |
|
1987 |
"default": GenerateModelNameExtraction("member ref", QName_model) |
|
1988 |
} |
|
1989 |
}, |
|
1990 |
||
1991 |
"refer": { |
|
1992 |
"type": SYNTAXATTRIBUTE, |
|
1993 |
"extract": { |
|
1994 |
"default": GenerateModelNameExtraction("member refer", QName_model) |
|
1995 |
} |
|
1996 |
}, |
|
1997 |
||
1998 |
"schemaLocation": { |
|
1999 |
"type": SYNTAXATTRIBUTE, |
|
2000 |
"extract": { |
|
2001 |
"default": GenerateModelNameExtraction("member schemaLocation", URI_model) |
|
2002 |
} |
|
2003 |
}, |
|
2004 |
||
2005 |
"source": { |
|
2006 |
"type": SYNTAXATTRIBUTE, |
|
2007 |
"extract": { |
|
2008 |
"default": GenerateModelNameExtraction("member source", URI_model) |
|
2009 |
} |
|
2010 |
}, |
|
2011 |
||
2012 |
"substitutionGroup": { |
|
2013 |
"type": SYNTAXATTRIBUTE, |
|
2014 |
"extract": { |
|
2015 |
"default": GenerateModelNameExtraction("member substitutionGroup", QName_model) |
|
2016 |
} |
|
2017 |
}, |
|
2018 |
||
2019 |
"targetNamespace": { |
|
2020 |
"type": SYNTAXATTRIBUTE, |
|
2021 |
"extract": { |
|
2022 |
"default": GenerateModelNameExtraction("member targetNamespace", URI_model) |
|
2023 |
} |
|
2024 |
}, |
|
2025 |
||
2026 |
"type": { |
|
2027 |
"type": SYNTAXATTRIBUTE, |
|
2028 |
"extract": { |
|
2029 |
"default": GenerateModelNameExtraction("member type", QName_model) |
|
2030 |
} |
|
2031 |
}, |
|
2032 |
||
2033 |
"use": { |
|
2034 |
"type": SYNTAXATTRIBUTE, |
|
2035 |
"extract": { |
|
2036 |
"default": GenerateEnumeratedExtraction("member usage", ["required", "optional", "prohibited"]) |
|
2037 |
}, |
|
2038 |
"default": { |
|
2039 |
"default": "optional" |
|
2040 |
} |
|
2041 |
}, |
|
2042 |
||
2043 |
"value": { |
|
2044 |
"type": SYNTAXATTRIBUTE, |
|
2045 |
"extract": { |
|
2046 |
"default": GetAttributeValue, |
|
2047 |
"fractionDigits": GenerateIntegerExtraction(minInclusive=0), |
|
2048 |
"length": GenerateIntegerExtraction(minInclusive=0), |
|
2049 |
"maxLength": GenerateIntegerExtraction(minInclusive=0), |
|
2050 |
"minLength": GenerateIntegerExtraction(minInclusive=0), |
|
2051 |
"totalDigits": GenerateIntegerExtraction(minExclusive=0), |
|
2052 |
"whiteSpace": GenerateEnumeratedExtraction("value", ["collapse", "preserve", "replace"]) |
|
2053 |
} |
|
2054 |
}, |
|
2055 |
||
2056 |
"version": { |
|
2057 |
"type": SYNTAXATTRIBUTE, |
|
2058 |
"extract": { |
|
2059 |
"default": GetToken |
|
2060 |
} |
|
2061 |
}, |
|
2062 |
||
2063 |
"xpath": { |
|
2064 |
"type": SYNTAXATTRIBUTE, |
|
2065 |
"extract": { |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
2066 |
# "default": NotSupportedYet("xpath") |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
2067 |
"default": GetAttributeValue |
565 | 2068 |
} |
2069 |
}, |
|
2070 |
||
2071 |
#------------------------------------------------------------------------------- |
|
2072 |
# Simple types definition |
|
2073 |
#------------------------------------------------------------------------------- |
|
2074 |
||
2075 |
"string": { |
|
2076 |
"type": SIMPLETYPE, |
|
2077 |
"basename": "string", |
|
2078 |
"extract": GetAttributeValue, |
|
2079 |
"facets": STRING_FACETS, |
|
2080 |
"generate": GenerateSimpleTypeXMLText(lambda x : x), |
|
2081 |
"initial": lambda: "", |
|
2082 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2083 |
}, |
|
2084 |
||
2085 |
"normalizedString": { |
|
2086 |
"type": SIMPLETYPE, |
|
2087 |
"basename": "normalizedString", |
|
2088 |
"extract": GetNormalizedString, |
|
2089 |
"facets": STRING_FACETS, |
|
2090 |
"generate": GenerateSimpleTypeXMLText(lambda x : x), |
|
2091 |
"initial": lambda: "", |
|
2092 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2093 |
}, |
|
2094 |
||
2095 |
"token": { |
|
2096 |
"type": SIMPLETYPE, |
|
2097 |
"basename": "token", |
|
2098 |
"extract": GetToken, |
|
2099 |
"facets": STRING_FACETS, |
|
2100 |
"generate": GenerateSimpleTypeXMLText(lambda x : x), |
|
2101 |
"initial": lambda: "", |
|
2102 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2103 |
}, |
|
2104 |
||
2105 |
"base64Binary": { |
|
2106 |
"type": SIMPLETYPE, |
|
2107 |
"basename": "base64Binary", |
|
2108 |
"extract": NotSupportedYet("base64Binary"), |
|
2109 |
"facets": STRING_FACETS, |
|
2110 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2111 |
"initial": lambda: 0, |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
2112 |
"check": lambda x: isinstance(x, (IntType, LongType)) |
565 | 2113 |
}, |
2114 |
||
2115 |
"hexBinary": { |
|
2116 |
"type": SIMPLETYPE, |
|
2117 |
"basename": "hexBinary", |
|
2118 |
"extract": GetHexInteger, |
|
2119 |
"facets": STRING_FACETS, |
|
2120 |
"generate": GenerateSimpleTypeXMLText(lambda x: ("%."+str(int(round(len("%X"%x)/2.)*2))+"X")%x), |
|
2121 |
"initial": lambda: 0, |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
2122 |
"check": lambda x: isinstance(x, (IntType, LongType)) |
565 | 2123 |
}, |
2124 |
||
2125 |
"integer": { |
|
2126 |
"type": SIMPLETYPE, |
|
2127 |
"basename": "integer", |
|
2128 |
"extract": GenerateIntegerExtraction(), |
|
2129 |
"facets": DECIMAL_FACETS, |
|
2130 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2131 |
"initial": lambda: 0, |
|
2132 |
"check": lambda x: isinstance(x, IntType) |
|
2133 |
}, |
|
2134 |
||
2135 |
"positiveInteger": { |
|
2136 |
"type": SIMPLETYPE, |
|
2137 |
"basename": "positiveInteger", |
|
2138 |
"extract": GenerateIntegerExtraction(minExclusive=0), |
|
2139 |
"facets": DECIMAL_FACETS, |
|
2140 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2141 |
"initial": lambda: 0, |
|
2142 |
"check": lambda x: isinstance(x, IntType) |
|
2143 |
}, |
|
2144 |
||
2145 |
"negativeInteger": { |
|
2146 |
"type": SIMPLETYPE, |
|
2147 |
"basename": "negativeInteger", |
|
2148 |
"extract": GenerateIntegerExtraction(maxExclusive=0), |
|
2149 |
"facets": DECIMAL_FACETS, |
|
2150 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2151 |
"initial": lambda: 0, |
|
2152 |
"check": lambda x: isinstance(x, IntType) |
|
2153 |
}, |
|
2154 |
||
2155 |
"nonNegativeInteger": { |
|
2156 |
"type": SIMPLETYPE, |
|
2157 |
"basename": "nonNegativeInteger", |
|
2158 |
"extract": GenerateIntegerExtraction(minInclusive=0), |
|
2159 |
"facets": DECIMAL_FACETS, |
|
2160 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2161 |
"initial": lambda: 0, |
|
2162 |
"check": lambda x: isinstance(x, IntType) |
|
2163 |
}, |
|
2164 |
||
2165 |
"nonPositiveInteger": { |
|
2166 |
"type": SIMPLETYPE, |
|
2167 |
"basename": "nonPositiveInteger", |
|
2168 |
"extract": GenerateIntegerExtraction(maxInclusive=0), |
|
2169 |
"facets": DECIMAL_FACETS, |
|
2170 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2171 |
"initial": lambda: 0, |
|
2172 |
"check": lambda x: isinstance(x, IntType) |
|
2173 |
}, |
|
2174 |
||
2175 |
"long": { |
|
2176 |
"type": SIMPLETYPE, |
|
2177 |
"basename": "long", |
|
2178 |
"extract": GenerateIntegerExtraction(minInclusive=-2**63,maxExclusive=2**63), |
|
2179 |
"facets": DECIMAL_FACETS, |
|
2180 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2181 |
"initial": lambda: 0, |
|
2182 |
"check": lambda x: isinstance(x, IntType) |
|
2183 |
}, |
|
2184 |
||
2185 |
"unsignedLong": { |
|
2186 |
"type": SIMPLETYPE, |
|
2187 |
"basename": "unsignedLong", |
|
2188 |
"extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**64), |
|
2189 |
"facets": DECIMAL_FACETS, |
|
2190 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2191 |
"initial": lambda: 0, |
|
2192 |
"check": lambda x: isinstance(x, IntType) |
|
2193 |
}, |
|
2194 |
||
2195 |
"int": { |
|
2196 |
"type": SIMPLETYPE, |
|
2197 |
"basename": "int", |
|
2198 |
"extract": GenerateIntegerExtraction(minInclusive=-2**31,maxExclusive=2**31), |
|
2199 |
"facets": DECIMAL_FACETS, |
|
2200 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2201 |
"initial": lambda: 0, |
|
2202 |
"check": lambda x: isinstance(x, IntType) |
|
2203 |
}, |
|
2204 |
||
2205 |
"unsignedInt": { |
|
2206 |
"type": SIMPLETYPE, |
|
2207 |
"basename": "unsignedInt", |
|
2208 |
"extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**32), |
|
2209 |
"facets": DECIMAL_FACETS, |
|
2210 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2211 |
"initial": lambda: 0, |
|
2212 |
"check": lambda x: isinstance(x, IntType) |
|
2213 |
}, |
|
2214 |
||
2215 |
"short": { |
|
2216 |
"type": SIMPLETYPE, |
|
2217 |
"basename": "short", |
|
2218 |
"extract": GenerateIntegerExtraction(minInclusive=-2**15,maxExclusive=2**15), |
|
2219 |
"facets": DECIMAL_FACETS, |
|
2220 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2221 |
"initial": lambda: 0, |
|
2222 |
"check": lambda x: isinstance(x, IntType) |
|
2223 |
}, |
|
2224 |
||
2225 |
"unsignedShort": { |
|
2226 |
"type": SIMPLETYPE, |
|
2227 |
"basename": "unsignedShort", |
|
2228 |
"extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**16), |
|
2229 |
"facets": DECIMAL_FACETS, |
|
2230 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2231 |
"initial": lambda: 0, |
|
2232 |
"check": lambda x: isinstance(x, IntType) |
|
2233 |
}, |
|
2234 |
||
2235 |
"byte": { |
|
2236 |
"type": SIMPLETYPE, |
|
2237 |
"basename": "byte", |
|
2238 |
"extract": GenerateIntegerExtraction(minInclusive=-2**7,maxExclusive=2**7), |
|
2239 |
"facets": DECIMAL_FACETS, |
|
2240 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2241 |
"initial": lambda: 0, |
|
2242 |
"check": lambda x: isinstance(x, IntType) |
|
2243 |
}, |
|
2244 |
||
2245 |
"unsignedByte": { |
|
2246 |
"type": SIMPLETYPE, |
|
2247 |
"basename": "unsignedByte", |
|
2248 |
"extract": GenerateIntegerExtraction(minInclusive=0,maxExclusive=2**8), |
|
2249 |
"facets": DECIMAL_FACETS, |
|
2250 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2251 |
"initial": lambda: 0, |
|
2252 |
"check": lambda x: isinstance(x, IntType) |
|
2253 |
}, |
|
2254 |
||
2255 |
"decimal": { |
|
2256 |
"type": SIMPLETYPE, |
|
2257 |
"basename": "decimal", |
|
2258 |
"extract": GenerateFloatExtraction("decimal"), |
|
2259 |
"facets": DECIMAL_FACETS, |
|
2260 |
"generate": GenerateFloatXMLText(), |
|
2261 |
"initial": lambda: 0., |
|
2262 |
"check": lambda x: isinstance(x, (IntType, FloatType)) |
|
2263 |
}, |
|
2264 |
||
2265 |
"float": { |
|
2266 |
"type": SIMPLETYPE, |
|
2267 |
"basename": "float", |
|
2268 |
"extract": GenerateFloatExtraction("float", ["INF", "-INF", "NaN"]), |
|
2269 |
"facets": NUMBER_FACETS, |
|
2270 |
"generate": GenerateFloatXMLText(["INF", "-INF", "NaN"]), |
|
2271 |
"initial": lambda: 0., |
|
2272 |
"check": lambda x: {"INF" : True, "-INF" : True, "NaN" : True}.get(x, isinstance(x, (IntType, FloatType))) |
|
2273 |
}, |
|
2274 |
||
2275 |
"double": { |
|
2276 |
"type": SIMPLETYPE, |
|
2277 |
"basename": "double", |
|
2278 |
"extract": GenerateFloatExtraction("double", ["INF", "-INF", "NaN"]), |
|
2279 |
"facets": NUMBER_FACETS, |
|
2280 |
"generate": GenerateFloatXMLText(["INF", "-INF", "NaN"]), |
|
2281 |
"initial": lambda: 0., |
|
2282 |
"check": lambda x: {"INF" : True, "-INF" : True, "NaN" : True}.get(x, isinstance(x, (IntType, FloatType))) |
|
2283 |
}, |
|
2284 |
||
2285 |
"boolean": { |
|
2286 |
"type": SIMPLETYPE, |
|
2287 |
"basename": "boolean", |
|
2288 |
"extract": GetBoolean, |
|
2289 |
"facets": GenerateDictFacets(["pattern", "whiteSpace"]), |
|
2290 |
"generate": GenerateSimpleTypeXMLText(lambda x:{True : "true", False : "false"}[x]), |
|
2291 |
"initial": lambda: False, |
|
2292 |
"check": lambda x: isinstance(x, BooleanType) |
|
2293 |
}, |
|
2294 |
||
2295 |
"duration": { |
|
2296 |
"type": SIMPLETYPE, |
|
2297 |
"basename": "duration", |
|
2298 |
"extract": NotSupportedYet("duration"), |
|
2299 |
"facets": NUMBER_FACETS, |
|
2300 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2301 |
"initial": lambda: "", |
|
2302 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2303 |
}, |
|
2304 |
||
2305 |
"dateTime": { |
|
2306 |
"type": SIMPLETYPE, |
|
2307 |
"basename": "dateTime", |
|
2308 |
"extract": GetDateTime, |
|
2309 |
"facets": NUMBER_FACETS, |
|
2310 |
"generate": GenerateSimpleTypeXMLText(datetime.datetime.isoformat), |
|
2311 |
"initial": lambda: datetime.datetime(1,1,1,0,0,0,0), |
|
2312 |
"check": lambda x: isinstance(x, datetime.datetime) |
|
2313 |
}, |
|
2314 |
||
2315 |
"date": { |
|
2316 |
"type": SIMPLETYPE, |
|
2317 |
"basename": "date", |
|
2318 |
"extract": GetDate, |
|
2319 |
"facets": NUMBER_FACETS, |
|
2320 |
"generate": GenerateSimpleTypeXMLText(datetime.date.isoformat), |
|
2321 |
"initial": lambda: datetime.date(1,1,1), |
|
2322 |
"check": lambda x: isinstance(x, datetime.date) |
|
2323 |
}, |
|
2324 |
||
2325 |
"time": { |
|
2326 |
"type": SIMPLETYPE, |
|
2327 |
"basename": "time", |
|
2328 |
"extract": GetTime, |
|
2329 |
"facets": NUMBER_FACETS, |
|
2330 |
"generate": GenerateSimpleTypeXMLText(datetime.time.isoformat), |
|
2331 |
"initial": lambda: datetime.time(0,0,0,0), |
|
2332 |
"check": lambda x: isinstance(x, datetime.time) |
|
2333 |
}, |
|
2334 |
||
2335 |
"gYear": { |
|
2336 |
"type": SIMPLETYPE, |
|
2337 |
"basename": "gYear", |
|
2338 |
"extract": NotSupportedYet("gYear"), |
|
2339 |
"facets": NUMBER_FACETS, |
|
2340 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2341 |
"initial": lambda: "", |
|
2342 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2343 |
}, |
|
2344 |
||
2345 |
"gYearMonth": { |
|
2346 |
"type": SIMPLETYPE, |
|
2347 |
"basename": "gYearMonth", |
|
2348 |
"extract": NotSupportedYet("gYearMonth"), |
|
2349 |
"facets": NUMBER_FACETS, |
|
2350 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2351 |
"initial": lambda: "", |
|
2352 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2353 |
}, |
|
2354 |
||
2355 |
"gMonth": { |
|
2356 |
"type": SIMPLETYPE, |
|
2357 |
"basename": "gMonth", |
|
2358 |
"extract": NotSupportedYet("gMonth"), |
|
2359 |
"facets": NUMBER_FACETS, |
|
2360 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2361 |
"initial": lambda: "", |
|
2362 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2363 |
}, |
|
2364 |
||
2365 |
"gMonthDay": { |
|
2366 |
"type": SIMPLETYPE, |
|
2367 |
"basename": "gMonthDay", |
|
2368 |
"extract": NotSupportedYet("gMonthDay"), |
|
2369 |
"facets": NUMBER_FACETS, |
|
2370 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2371 |
"initial": lambda: "", |
|
2372 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2373 |
}, |
|
2374 |
||
2375 |
"gDay": { |
|
2376 |
"type": SIMPLETYPE, |
|
2377 |
"basename": "gDay", |
|
2378 |
"extract": NotSupportedYet("gDay"), |
|
2379 |
"facets": NUMBER_FACETS, |
|
2380 |
"generate": GenerateSimpleTypeXMLText(str), |
|
2381 |
"initial": lambda: "", |
|
2382 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2383 |
}, |
|
2384 |
||
2385 |
"Name": { |
|
2386 |
"type": SIMPLETYPE, |
|
2387 |
"basename": "Name", |
|
2388 |
"extract": GenerateModelNameExtraction("Name", Name_model), |
|
2389 |
"facets": STRING_FACETS, |
|
2390 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2391 |
"initial": lambda: "", |
|
2392 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2393 |
}, |
|
2394 |
||
2395 |
"QName": { |
|
2396 |
"type": SIMPLETYPE, |
|
2397 |
"basename": "QName", |
|
2398 |
"extract": GenerateModelNameExtraction("QName", QName_model), |
|
2399 |
"facets": STRING_FACETS, |
|
2400 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2401 |
"initial": lambda: "", |
|
2402 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2403 |
}, |
|
2404 |
||
2405 |
"NCName": { |
|
2406 |
"type": SIMPLETYPE, |
|
2407 |
"basename": "NCName", |
|
2408 |
"extract": GenerateModelNameExtraction("NCName", NCName_model), |
|
2409 |
"facets": STRING_FACETS, |
|
2410 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2411 |
"initial": lambda: "", |
|
2412 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2413 |
}, |
|
2414 |
||
2415 |
"anyURI": { |
|
2416 |
"type": SIMPLETYPE, |
|
2417 |
"basename": "anyURI", |
|
2418 |
"extract": GenerateModelNameExtraction("anyURI", URI_model), |
|
2419 |
"facets": STRING_FACETS, |
|
2420 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2421 |
"initial": lambda: "", |
|
2422 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2423 |
}, |
|
2424 |
||
2425 |
"language": { |
|
2426 |
"type": SIMPLETYPE, |
|
2427 |
"basename": "language", |
|
2428 |
"extract": GenerateModelNameExtraction("language", LANGUAGE_model), |
|
2429 |
"facets": STRING_FACETS, |
|
2430 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2431 |
"initial": lambda: "en", |
|
2432 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2433 |
}, |
|
2434 |
||
2435 |
"ID": { |
|
2436 |
"type": SIMPLETYPE, |
|
2437 |
"basename": "ID", |
|
2438 |
"extract": GenerateModelNameExtraction("ID", Name_model), |
|
2439 |
"facets": STRING_FACETS, |
|
2440 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2441 |
"initial": lambda: "", |
|
2442 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2443 |
}, |
|
2444 |
||
2445 |
"IDREF": { |
|
2446 |
"type": SIMPLETYPE, |
|
2447 |
"basename": "IDREF", |
|
2448 |
"extract": GenerateModelNameExtraction("IDREF", Name_model), |
|
2449 |
"facets": STRING_FACETS, |
|
2450 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2451 |
"initial": lambda: "", |
|
2452 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2453 |
}, |
|
2454 |
||
2455 |
"IDREFS": { |
|
2456 |
"type": SIMPLETYPE, |
|
2457 |
"basename": "IDREFS", |
|
2458 |
"extract": GenerateModelNameExtraction("IDREFS", Names_model), |
|
2459 |
"facets": STRING_FACETS, |
|
2460 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2461 |
"initial": lambda: "", |
|
2462 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2463 |
}, |
|
2464 |
||
2465 |
"ENTITY": { |
|
2466 |
"type": SIMPLETYPE, |
|
2467 |
"basename": "ENTITY", |
|
2468 |
"extract": GenerateModelNameExtraction("ENTITY", Name_model), |
|
2469 |
"facets": STRING_FACETS, |
|
2470 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2471 |
"initial": lambda: "", |
|
2472 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2473 |
}, |
|
2474 |
||
2475 |
"ENTITIES": { |
|
2476 |
"type": SIMPLETYPE, |
|
2477 |
"basename": "ENTITIES", |
|
2478 |
"extract": GenerateModelNameExtraction("ENTITIES", Names_model), |
|
2479 |
"facets": STRING_FACETS, |
|
2480 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2481 |
"initial": lambda: "", |
|
2482 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2483 |
}, |
|
2484 |
||
2485 |
"NOTATION": { |
|
2486 |
"type": SIMPLETYPE, |
|
2487 |
"basename": "NOTATION", |
|
2488 |
"extract": GenerateModelNameExtraction("NOTATION", Name_model), |
|
2489 |
"facets": STRING_FACETS, |
|
2490 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2491 |
"initial": lambda: "", |
|
2492 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2493 |
}, |
|
2494 |
||
2495 |
"NMTOKEN": { |
|
2496 |
"type": SIMPLETYPE, |
|
2497 |
"basename": "NMTOKEN", |
|
2498 |
"extract": GenerateModelNameExtraction("NMTOKEN", NMToken_model), |
|
2499 |
"facets": STRING_FACETS, |
|
2500 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2501 |
"initial": lambda: "", |
|
2502 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2503 |
}, |
|
2504 |
||
2505 |
"NMTOKENS": { |
|
2506 |
"type": SIMPLETYPE, |
|
2507 |
"basename": "NMTOKENS", |
|
2508 |
"extract": GenerateModelNameExtraction("NMTOKENS", NMTokens_model), |
|
2509 |
"facets": STRING_FACETS, |
|
2510 |
"generate": GenerateSimpleTypeXMLText(lambda x: x), |
|
2511 |
"initial": lambda: "", |
|
2512 |
"check": lambda x: isinstance(x, (StringType, UnicodeType)) |
|
2513 |
}, |
|
2514 |
||
2515 |
# Complex Types |
|
2516 |
"anyType": {"type": COMPLEXTYPE, "extract": lambda x:None}, |
|
2517 |
} |
|
2518 |
||
2519 |
if __name__ == '__main__': |
|
2520 |
classes = GenerateClassesFromXSD("test.xsd") |
|
2521 |
||
2522 |
# Code for test of test.xsd |
|
2523 |
xmlfile = open("po.xml", 'r') |
|
2524 |
tree = minidom.parse(xmlfile) |
|
2525 |
xmlfile.close() |
|
2526 |
test = classes["PurchaseOrderType"]() |
|
2527 |
for child in tree.childNodes: |
|
2528 |
if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "purchaseOrder": |
|
2529 |
test.loadXMLTree(child) |
|
2530 |
test.items.item[0].setquantity(2) |
|
2531 |
testfile = open("test.xml", 'w') |
|
2532 |
testfile.write(u'<?xml version=\"1.0\"?>\n') |
|
2533 |
testfile.write(test.generateXMLText("purchaseOrder").encode("utf-8")) |
|
2534 |
testfile.close() |