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