author | laurent |
Wed, 07 Mar 2012 10:06:01 +0100 | |
changeset 652 | 676307069508 |
parent 626 | ac0a8f6462c3 |
child 674 | bbffe4110141 |
permissions | -rwxr-xr-x |
565 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
25 |
import os, sys |
565 | 26 |
import re |
27 |
import datetime |
|
28 |
from types import * |
|
29 |
from xml.dom import minidom |
|
30 |
from xml.sax.saxutils import escape, unescape, quoteattr |
|
31 |
from new import classobj |
|
32 |
||
33 |
def CreateNode(name): |
|
34 |
node = minidom.Node() |
|
35 |
node.nodeName = name |
|
36 |
node._attrs = {} |
|
37 |
node.childNodes = [] |
|
38 |
return node |
|
39 |
||
40 |
def NodeRenameAttr(node, old_name, new_name): |
|
41 |
node._attrs[new_name] = node._attrs.pop(old_name) |
|
42 |
||
43 |
def NodeSetAttr(node, name, value): |
|
44 |
attr = minidom.Attr(name) |
|
45 |
text = minidom.Text() |
|
46 |
text.data = value |
|
47 |
attr.childNodes[0] = text |
|
48 |
node._attrs[name] = attr |
|
49 |
||
50 |
""" |
|
51 |
Regular expression models for checking all kind of string values defined in XML |
|
52 |
standard |
|
53 |
""" |
|
54 |
Name_model = re.compile('([a-zA-Z_\:][\w\.\-\:]*)$') |
|
55 |
Names_model = re.compile('([a-zA-Z_\:][\w\.\-\:]*(?: [a-zA-Z_\:][\w\.\-\:]*)*)$') |
|
56 |
NMToken_model = re.compile('([\w\.\-\:]*)$') |
|
57 |
NMTokens_model = re.compile('([\w\.\-\:]*(?: [\w\.\-\:]*)*)$') |
|
58 |
QName_model = re.compile('((?:[a-zA-Z_][\w]*:)?[a-zA-Z_][\w]*)$') |
|
59 |
QNames_model = re.compile('((?:[a-zA-Z_][\w]*:)?[a-zA-Z_][\w]*(?: (?:[a-zA-Z_][\w]*:)?[a-zA-Z_][\w]*)*)$') |
|
60 |
NCName_model = re.compile('([a-zA-Z_][\w]*)$') |
|
61 |
URI_model = re.compile('((?:http://|/)?(?:[\w.-]*/?)*)$') |
|
62 |
LANGUAGE_model = re.compile('([a-zA-Z]{1,8}(?:-[a-zA-Z0-9]{1,8})*)$') |
|
63 |
||
64 |
ONLY_ANNOTATION = re.compile("((?:annotation )?)") |
|
65 |
||
66 |
""" |
|
67 |
Regular expression models for extracting dates and times from a string |
|
68 |
""" |
|
69 |
time_model = re.compile('([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]*)?)(?:Z)?$') |
|
70 |
date_model = re.compile('([0-9]{4})-([0-9]{2})-([0-9]{2})((?:[\-\+][0-9]{2}:[0-9]{2})|Z)?$') |
|
71 |
datetime_model = re.compile('([0-9]{4})-([0-9]{2})-([0-9]{2})[ T]([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]*)?)((?:[\-\+][0-9]{2}:[0-9]{2})|Z)?$') |
|
72 |
||
73 |
class xml_timezone(datetime.tzinfo): |
|
74 |
||
75 |
def SetOffset(self, offset): |
|
76 |
if offset == "Z": |
|
77 |
self.__offset = timedelta(minutes = 0) |
|
78 |
self.__name = "UTC" |
|
79 |
else: |
|
80 |
sign = {"-" : -1, "+" : 1}[offset[0]] |
|
81 |
hours, minutes = [int(val) for val in offset[1:].split(":")] |
|
82 |
self.__offset = timedelta(minutes=sign * (hours * 60 + minutes)) |
|
83 |
self.__name = "" |
|
84 |
||
85 |
def utcoffset(self, dt): |
|
86 |
return self.__offset |
|
87 |
||
88 |
def tzname(self, dt): |
|
89 |
return self.__name |
|
90 |
||
91 |
def dst(self, dt): |
|
92 |
return ZERO |
|
93 |
||
94 |
[SYNTAXELEMENT, SYNTAXATTRIBUTE, SIMPLETYPE, COMPLEXTYPE, COMPILEDCOMPLEXTYPE, |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
95 |
ATTRIBUTESGROUP, ELEMENTSGROUP, ATTRIBUTE, ELEMENT, CHOICE, ANY, TAG, CONSTRAINT, |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
96 |
] = range(13) |
565 | 97 |
|
98 |
def NotSupportedYet(type): |
|
99 |
""" |
|
100 |
Function that generates a function that point out to user that datatype |
|
101 |
used is not supported by xmlclass yet |
|
102 |
@param type: data type |
|
103 |
@return: function generated |
|
104 |
""" |
|
105 |
def GetUnknownValue(attr): |
|
106 |
raise ValueError("\"%s\" type isn't supported by \"xmlclass\" yet!" % \ |
|
107 |
type) |
|
108 |
return GetUnknownValue |
|
109 |
||
110 |
""" |
|
111 |
This function calculates the number of whitespace for indentation |
|
112 |
""" |
|
113 |
def getIndent(indent, balise): |
|
114 |
first = indent * 2 |
|
115 |
second = first + len(balise) + 1 |
|
116 |
return u'\t'.expandtabs(first), u'\t'.expandtabs(second) |
|
117 |
||
118 |
||
119 |
def GetAttributeValue(attr, extract=True): |
|
120 |
""" |
|
121 |
Function that extracts data from a tree node |
|
122 |
@param attr: tree node containing data to extract |
|
123 |
@param extract: attr is a tree node or not |
|
124 |
@return: data extracted as string |
|
125 |
""" |
|
126 |
if not extract: |
|
127 |
return attr |
|
128 |
if len(attr.childNodes) == 1: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
129 |
return unescape(attr.childNodes[0].data.encode("utf-8")) |
565 | 130 |
else: |
131 |
# content is a CDATA |
|
132 |
text = "" |
|
133 |
for node in attr.childNodes: |
|
602
7cadf0e2ae05
Adding support for unescape special character in #text node in formattedText
laurent
parents:
601
diff
changeset
|
134 |
if not (node.nodeName == "#text" and node.data.strip() == ""): |
7cadf0e2ae05
Adding support for unescape special character in #text node in formattedText
laurent
parents:
601
diff
changeset
|
135 |
text += unescape(node.data.encode("utf-8")) |
565 | 136 |
return text |
137 |
||
138 |
||
139 |
def GetNormalizedString(attr, extract=True): |
|
140 |
""" |
|
141 |
Function that normalizes a string according to XML 1.0. Replace |
|
142 |
tabulations, line feed and carriage return by white space |
|
143 |
@param attr: tree node containing data to extract or data to normalize |
|
144 |
@param extract: attr is a tree node or not |
|
145 |
@return: data normalized as string |
|
146 |
""" |
|
147 |
if extract: |
|
148 |
value = GetAttributeValue(attr) |
|
149 |
else: |
|
150 |
value = attr |
|
151 |
return value.replace("\t", " ").replace("\r", " ").replace("\n", " ") |
|
152 |
||
153 |
||
154 |
def GetToken(attr, extract=True): |
|
155 |
""" |
|
156 |
Function that tokenizes a string according to XML 1.0. Remove any leading |
|
157 |
and trailing white space and replace internal sequence of two or more |
|
158 |
spaces by only one white space |
|
159 |
@param attr: tree node containing data to extract or data to tokenize |
|
160 |
@param extract: attr is a tree node or not |
|
161 |
@return: data tokenized as string |
|
162 |
""" |
|
163 |
return " ".join([part for part in |
|
164 |
GetNormalizedString(attr, extract).split(" ") |
|
165 |
if part]) |
|
166 |
||
167 |
||
168 |
def GetHexInteger(attr, extract=True): |
|
169 |
""" |
|
170 |
Function that extracts an hexadecimal integer from a tree node or a string |
|
171 |
@param attr: tree node containing data to extract or data as a string |
|
172 |
@param extract: attr is a tree node or not |
|
173 |
@return: data as an integer |
|
174 |
""" |
|
175 |
if extract: |
|
176 |
value = GetAttributeValue(attr) |
|
177 |
else: |
|
178 |
value = attr |
|
179 |
if len(value) % 2 != 0: |
|
180 |
raise ValueError("\"%s\" isn't a valid hexadecimal integer!" % value) |
|
181 |
try: |
|
182 |
return int(value, 16) |
|
183 |
except: |
|
184 |
raise ValueError("\"%s\" isn't a valid hexadecimal integer!" % value) |
|
185 |
||
186 |
||
187 |
def GenerateIntegerExtraction(minInclusive=None, maxInclusive=None, |
|
188 |
minExclusive=None, maxExclusive=None): |
|
189 |
""" |
|
190 |
Function that generates an extraction function for integer defining min and |
|
191 |
max of integer value |
|
192 |
@param minInclusive: inclusive minimum |
|
193 |
@param maxInclusive: inclusive maximum |
|
194 |
@param minExclusive: exclusive minimum |
|
195 |
@param maxExclusive: exclusive maximum |
|
196 |
@return: function generated |
|
197 |
""" |
|
198 |
def GetInteger(attr, extract=True): |
|
199 |
""" |
|
200 |
Function that extracts an integer from a tree node or a string |
|
201 |
@param attr: tree node containing data to extract or data as a string |
|
202 |
@param extract: attr is a tree node or not |
|
203 |
@return: data as an integer |
|
204 |
""" |
|
205 |
||
206 |
if extract: |
|
207 |
value = GetAttributeValue(attr) |
|
208 |
else: |
|
209 |
value = attr |
|
210 |
try: |
|
211 |
# TODO: permit to write value like 1E2 |
|
212 |
value = int(value) |
|
213 |
except: |
|
214 |
raise ValueError("\"%s\" isn't a valid integer!" % value) |
|
215 |
if minInclusive is not None and value < minInclusive: |
|
216 |
raise ValueError("\"%d\" isn't greater or equal to %d!" % \ |
|
217 |
(value, minInclusive)) |
|
218 |
if maxInclusive is not None and value > maxInclusive: |
|
219 |
raise ValueError("\"%d\" isn't lesser or equal to %d!" % \ |
|
220 |
(value, maxInclusive)) |
|
221 |
if minExclusive is not None and value <= minExclusive: |
|
222 |
raise ValueError("\"%d\" isn't greater than %d!" % \ |
|
223 |
(value, minExclusive)) |
|
224 |
if maxExclusive is not None and value >= maxExclusive: |
|
225 |
raise ValueError("\"%d\" isn't lesser than %d!" % \ |
|
226 |
(value, maxExclusive)) |
|
227 |
return value |
|
228 |
return GetInteger |
|
229 |
||
230 |
||
231 |
def GenerateFloatExtraction(type, extra_values=[]): |
|
232 |
""" |
|
233 |
Function that generates an extraction function for float |
|
234 |
@param type: name of the type of float |
|
235 |
@return: function generated |
|
236 |
""" |
|
237 |
def GetFloat(attr, extract = True): |
|
238 |
""" |
|
239 |
Function that extracts a float from a tree node or a string |
|
240 |
@param attr: tree node containing data to extract or data as a string |
|
241 |
@param extract: attr is a tree node or not |
|
242 |
@return: data as a float |
|
243 |
""" |
|
244 |
if extract: |
|
245 |
value = GetAttributeValue(attr) |
|
246 |
else: |
|
247 |
value = attr |
|
248 |
if value in extra_values: |
|
249 |
return value |
|
250 |
try: |
|
251 |
return float(value) |
|
252 |
except: |
|
253 |
raise ValueError("\"%s\" isn't a valid %s!" % (value, type)) |
|
254 |
return GetFloat |
|
255 |
||
256 |
||
257 |
def GetBoolean(attr, extract=True): |
|
258 |
""" |
|
259 |
Function that extracts a boolean from a tree node or a string |
|
260 |
@param attr: tree node containing data to extract or data as a string |
|
261 |
@param extract: attr is a tree node or not |
|
262 |
@return: data as a boolean |
|
263 |
""" |
|
264 |
if extract: |
|
265 |
value = GetAttributeValue(attr) |
|
266 |
else: |
|
267 |
value = attr |
|
268 |
if value == "true" or value == "1": |
|
269 |
return True |
|
270 |
elif value == "false" or value == "0": |
|
271 |
return False |
|
272 |
else: |
|
273 |
raise ValueError("\"%s\" isn't a valid boolean!" % value) |
|
274 |
||
275 |
||
276 |
def GetTime(attr, extract=True): |
|
277 |
""" |
|
278 |
Function that extracts a time from a tree node or a string |
|
279 |
@param attr: tree node containing data to extract or data as a string |
|
280 |
@param extract: attr is a tree node or not |
|
281 |
@return: data as a time |
|
282 |
""" |
|
283 |
if extract: |
|
284 |
value = GetAttributeValue(attr) |
|
285 |
else: |
|
286 |
value = attr |
|
287 |
result = time_model.match(value) |
|
288 |
if result: |
|
289 |
values = result.groups() |
|
290 |
time_values = [int(v) for v in values[:2]] |
|
291 |
seconds = float(values[2]) |
|
292 |
time_values.extend([int(seconds), int((seconds % 1) * 1000000)]) |
|
293 |
return datetime.time(*time_values) |
|
294 |
else: |
|
295 |
raise ValueError("\"%s\" isn't a valid time!" % value) |
|
296 |
||
297 |
||
298 |
def GetDate(attr, extract=True): |
|
299 |
""" |
|
300 |
Function that extracts a date from a tree node or a string |
|
301 |
@param attr: tree node containing data to extract or data as a string |
|
302 |
@param extract: attr is a tree node or not |
|
303 |
@return: data as a date |
|
304 |
""" |
|
305 |
if extract: |
|
306 |
value = GetAttributeValue(attr) |
|
307 |
else: |
|
308 |
value = attr |
|
309 |
result = date_model.match(value) |
|
310 |
if result: |
|
311 |
values = result.groups() |
|
312 |
date_values = [int(v) for v in values[:3]] |
|
313 |
if values[3] is not None: |
|
314 |
tz = xml_timezone() |
|
315 |
tz.SetOffset(values[3]) |
|
316 |
date_values.append(tz) |
|
317 |
return datetime.date(*date_values) |
|
318 |
else: |
|
319 |
raise ValueError("\"%s\" isn't a valid date!" % value) |
|
320 |
||
321 |
||
322 |
def GetDateTime(attr, extract=True): |
|
323 |
""" |
|
324 |
Function that extracts date and time from a tree node or a string |
|
325 |
@param attr: tree node containing data to extract or data as a string |
|
326 |
@param extract: attr is a tree node or not |
|
327 |
@return: data as date and time |
|
328 |
""" |
|
329 |
if extract: |
|
330 |
value = GetAttributeValue(attr) |
|
331 |
else: |
|
332 |
value = attr |
|
333 |
result = datetime_model.match(value) |
|
334 |
if result: |
|
335 |
values = result.groups() |
|
336 |
datetime_values = [int(v) for v in values[:5]] |
|
337 |
seconds = float(values[5]) |
|
338 |
datetime_values.extend([int(seconds), int((seconds % 1) * 1000000)]) |
|
339 |
if values[6] is not None: |
|
340 |
tz = xml_timezone() |
|
341 |
tz.SetOffset(values[6]) |
|
342 |
datetime_values.append(tz) |
|
343 |
return datetime.datetime(*datetime_values) |
|
344 |
else: |
|
345 |
raise ValueError("\"%s\" isn't a valid datetime!" % value) |
|
346 |
||
347 |
||
348 |
def GenerateModelNameExtraction(type, model): |
|
349 |
""" |
|
350 |
Function that generates an extraction function for string matching a model |
|
351 |
@param type: name of the data type |
|
352 |
@param model: model that data must match |
|
353 |
@return: function generated |
|
354 |
""" |
|
355 |
def GetModelName(attr, extract=True): |
|
356 |
""" |
|
357 |
Function that extracts a string from a tree node or not and check that |
|
358 |
string extracted or given match the model |
|
359 |
@param attr: tree node containing data to extract or data as a string |
|
360 |
@param extract: attr is a tree node or not |
|
361 |
@return: data as a string if matching |
|
362 |
""" |
|
363 |
if extract: |
|
364 |
value = GetAttributeValue(attr) |
|
365 |
else: |
|
366 |
value = attr |
|
367 |
result = model.match(value) |
|
368 |
if not result: |
|
369 |
raise ValueError("\"%s\" isn't a valid %s!" % (value, type)) |
|
370 |
return value |
|
371 |
return GetModelName |
|
372 |
||
373 |
||
374 |
def GenerateLimitExtraction(min=None, max=None, unbounded=True): |
|
375 |
""" |
|
376 |
Function that generates an extraction function for integer defining min and |
|
377 |
max of integer value |
|
378 |
@param min: minimum limit value |
|
379 |
@param max: maximum limit value |
|
380 |
@param unbounded: value can be "unbounded" or not |
|
381 |
@return: function generated |
|
382 |
""" |
|
383 |
def GetLimit(attr, extract=True): |
|
384 |
""" |
|
385 |
Function that extracts a string from a tree node or not and check that |
|
386 |
string extracted or given is in a list of values |
|
387 |
@param attr: tree node containing data to extract or data as a string |
|
388 |
@param extract: attr is a tree node or not |
|
389 |
@return: data as a string |
|
390 |
""" |
|
391 |
if extract: |
|
392 |
value = GetAttributeValue(attr) |
|
393 |
else: |
|
394 |
value = attr |
|
395 |
if value == "unbounded": |
|
396 |
if unbounded: |
|
397 |
return value |
|
398 |
else: |
|
399 |
raise ValueError("Member limit can't be defined to \"unbounded\"!") |
|
400 |
try: |
|
401 |
limit = int(value) |
|
402 |
except: |
|
403 |
raise ValueError("\"%s\" isn't a valid value for this member limit!" % value) |
|
404 |
if limit < 0: |
|
405 |
raise ValueError("Member limit can't be negative!") |
|
406 |
elif min is not None and limit < min: |
|
407 |
raise ValueError("Member limit can't be lower than \"%d\"!" % min) |
|
408 |
elif max is not None and limit > max: |
|
409 |
raise ValueError("Member limit can't be upper than \"%d\"!" % max) |
|
410 |
return limit |
|
411 |
return GetLimit |
|
412 |
||
413 |
||
414 |
def GenerateEnumeratedExtraction(type, list): |
|
415 |
""" |
|
416 |
Function that generates an extraction function for enumerated values |
|
417 |
@param type: name of the data type |
|
418 |
@param list: list of possible values |
|
419 |
@return: function generated |
|
420 |
""" |
|
421 |
def GetEnumerated(attr, extract=True): |
|
422 |
""" |
|
423 |
Function that extracts a string from a tree node or not and check that |
|
424 |
string extracted or given is in a list of values |
|
425 |
@param attr: tree node containing data to extract or data as a string |
|
426 |
@param extract: attr is a tree node or not |
|
427 |
@return: data as a string |
|
428 |
""" |
|
429 |
if extract: |
|
430 |
value = GetAttributeValue(attr) |
|
431 |
else: |
|
432 |
value = attr |
|
433 |
if value in list: |
|
434 |
return value |
|
435 |
else: |
|
436 |
raise ValueError("\"%s\" isn't a valid value for %s!" % \ |
|
437 |
(value, type)) |
|
438 |
return GetEnumerated |
|
439 |
||
440 |
||
441 |
def GetNamespaces(attr, extract=True): |
|
442 |
""" |
|
443 |
Function that extracts a list of namespaces from a tree node or a string |
|
444 |
@param attr: tree node containing data to extract or data as a string |
|
445 |
@param extract: attr is a tree node or not |
|
446 |
@return: list of namespaces |
|
447 |
""" |
|
448 |
if extract: |
|
449 |
value = GetAttributeValue(attr) |
|
450 |
else: |
|
451 |
value = attr |
|
452 |
if value == "": |
|
453 |
return [] |
|
454 |
elif value == "##any" or value == "##other": |
|
455 |
namespaces = [value] |
|
456 |
else: |
|
457 |
namespaces = [] |
|
458 |
for item in value.split(" "): |
|
459 |
if item == "##targetNamespace" or item == "##local": |
|
460 |
namespaces.append(item) |
|
461 |
else: |
|
462 |
result = URI_model.match(item) |
|
463 |
if result is not None: |
|
464 |
namespaces.append(item) |
|
465 |
else: |
|
466 |
raise ValueError("\"%s\" isn't a valid value for namespace!" % value) |
|
467 |
return namespaces |
|
468 |
||
469 |
||
470 |
def GenerateGetList(type, list): |
|
471 |
""" |
|
472 |
Function that generates an extraction function for a list of values |
|
473 |
@param type: name of the data type |
|
474 |
@param list: list of possible values |
|
475 |
@return: function generated |
|
476 |
""" |
|
477 |
def GetLists(attr, extract=True): |
|
478 |
""" |
|
479 |
Function that extracts a list of values from a tree node or a string |
|
480 |
@param attr: tree node containing data to extract or data as a string |
|
481 |
@param extract: attr is a tree node or not |
|
482 |
@return: list of values |
|
483 |
""" |
|
484 |
if extract: |
|
485 |
value = GetAttributeValue(attr) |
|
486 |
else: |
|
487 |
value = attr |
|
488 |
if value == "": |
|
489 |
return [] |
|
490 |
elif value == "#all": |
|
491 |
return [value] |
|
492 |
else: |
|
493 |
values = [] |
|
494 |
for item in value.split(" "): |
|
495 |
if item in list: |
|
496 |
values.append(item) |
|
497 |
else: |
|
498 |
raise ValueError("\"%s\" isn't a valid value for %s!" % \ |
|
499 |
(value, type)) |
|
500 |
return values |
|
501 |
return GetLists |
|
502 |
||
503 |
||
504 |
def GenerateModelNameListExtraction(type, model): |
|
505 |
""" |
|
506 |
Function that generates an extraction function for list of string matching |
|
507 |
a model |
|
508 |
@param type: name of the data type |
|
509 |
@param model: model that list elements must match |
|
510 |
@return: function generated |
|
511 |
""" |
|
512 |
def GetModelNameList(attr, extract=True): |
|
513 |
""" |
|
514 |
Function that extracts a list of string from a tree node or not and |
|
515 |
check that all extracted items match the model |
|
516 |
@param attr: tree node containing data to extract or data as a string |
|
517 |
@param extract: attr is a tree node or not |
|
518 |
@return: data as a list of string if matching |
|
519 |
""" |
|
520 |
if extract: |
|
521 |
value = GetAttributeValue(attr) |
|
522 |
else: |
|
523 |
value = attr |
|
524 |
values = [] |
|
525 |
for item in value.split(" "): |
|
526 |
result = model.match(item) |
|
527 |
if result is not None: |
|
528 |
values.append(item) |
|
529 |
else: |
|
530 |
raise ValueError("\"%s\" isn't a valid value for %s!" % \ |
|
531 |
(value, type)) |
|
532 |
return values |
|
533 |
return GetModelNameList |
|
534 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
535 |
def GenerateAnyInfos(infos): |
565 | 536 |
def ExtractAny(tree): |
601
32c0f4a626db
Adding support for loading #text node in formattedText
laurent
parents:
594
diff
changeset
|
537 |
if tree.nodeName in ["#text", "#cdata-section"]: |
602
7cadf0e2ae05
Adding support for unescape special character in #text node in formattedText
laurent
parents:
601
diff
changeset
|
538 |
return unescape(tree.data.encode("utf-8")) |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
539 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
540 |
return tree |
565 | 541 |
|
542 |
def GenerateAny(value, name=None, indent=0): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
543 |
if isinstance(value, (StringType, UnicodeType)): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
544 |
try: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
545 |
value = value.decode("utf-8") |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
546 |
except: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
547 |
pass |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
548 |
return u'<![CDATA[%s]]>\n' % value |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
549 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
550 |
return value.toprettyxml(indent=" "*indent, encoding="utf-8") |
565 | 551 |
|
552 |
return { |
|
553 |
"type": COMPLEXTYPE, |
|
554 |
"extract": ExtractAny, |
|
555 |
"generate": GenerateAny, |
|
556 |
"initial": lambda: "", |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
557 |
"check": lambda x: isinstance(x, (StringType, UnicodeType, minidom.Node)) |
565 | 558 |
} |
559 |
||
607
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
560 |
def GenerateTagInfos(infos): |
565 | 561 |
def ExtractTag(tree): |
562 |
if len(tree._attrs) > 0: |
|
607
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
563 |
raise ValueError("\"%s\" musn't have attributes!" % infos["name"]) |
565 | 564 |
if len(tree.childNodes) > 0: |
607
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
565 |
raise ValueError("\"%s\" musn't have children!" % infos["name"]) |
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
566 |
if infos["minOccurs"] == 0: |
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
567 |
return True |
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
568 |
else: |
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
569 |
return None |
565 | 570 |
|
571 |
def GenerateTag(value, name=None, indent=0): |
|
607
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
572 |
if name is not None and not (infos["minOccurs"] == 0 and value is None): |
565 | 573 |
ind1, ind2 = getIndent(indent, name) |
574 |
return ind1 + "<%s/>\n" % name |
|
575 |
else: |
|
576 |
return "" |
|
577 |
||
578 |
return { |
|
579 |
"type": TAG, |
|
580 |
"extract": ExtractTag, |
|
581 |
"generate": GenerateTag, |
|
582 |
"initial": lambda: None, |
|
607
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
583 |
"check": lambda x: x == None or infos["minOccurs"] == 0 and value == True |
565 | 584 |
} |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
585 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
586 |
def FindTypeInfos(factory, infos): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
587 |
if isinstance(infos, (UnicodeType, StringType)): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
588 |
namespace, name = DecomposeQualifiedName(infos) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
589 |
return factory.GetQualifiedNameInfos(name, namespace) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
590 |
return infos |
565 | 591 |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
592 |
def GetElementInitialValue(factory, infos): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
593 |
infos["elmt_type"] = FindTypeInfos(factory, infos["elmt_type"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
594 |
if infos["minOccurs"] == 0 and infos["maxOccurs"] == 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
595 |
if infos.has_key("default"): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
596 |
return infos["elmt_type"]["extract"](infos["default"], False) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
597 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
598 |
return None |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
599 |
elif infos["minOccurs"] == 1 and infos["maxOccurs"] == 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
600 |
return infos["elmt_type"]["initial"]() |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
601 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
602 |
return [infos["elmt_type"]["initial"]() for i in xrange(infos["minOccurs"])] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
603 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
604 |
def HandleError(message, raise_exception): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
605 |
if raise_exception: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
606 |
raise ValueError(message) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
607 |
return False |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
608 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
609 |
def CheckElementValue(factory, name, infos, value, raise_exception=True): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
610 |
infos["elmt_type"] = FindTypeInfos(factory, infos["elmt_type"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
611 |
if value is None and raise_exception: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
612 |
if not (infos["minOccurs"] == 0 and infos["maxOccurs"] == 1): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
613 |
return HandleError("Attribute '%s' isn't optional." % name, raise_exception) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
614 |
elif infos["maxOccurs"] == "unbounded" or infos["maxOccurs"] > 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
615 |
if not isinstance(value, ListType): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
616 |
return HandleError("Attribute '%s' must be a list." % name, raise_exception) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
617 |
if len(value) < infos["minOccurs"] or infos["maxOccurs"] != "unbounded" and len(value) > infos["maxOccurs"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
618 |
return HandleError("List out of bounds for attribute '%s'." % name, raise_exception) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
619 |
if not reduce(lambda x, y: x and y, map(infos["elmt_type"]["check"], value), True): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
620 |
return HandleError("Attribute '%s' must be a list of valid elements." % name, raise_exception) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
621 |
elif infos.has_key("fixed") and value != infos["fixed"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
622 |
return HandleError("Value of attribute '%s' can only be '%s'." % (name, str(infos["fixed"])), raise_exception) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
623 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
624 |
return infos["elmt_type"]["check"](value) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
625 |
return True |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
626 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
627 |
def GetContentInfos(name, choices): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
628 |
for choice_infos in choices: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
629 |
if choices_infos["type"] == "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
630 |
for element_infos in choices_infos["elements"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
631 |
if element_infos["type"] == CHOICE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
632 |
if GetContentInfos(name, element_infos["choices"]): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
633 |
return choices_infos |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
634 |
elif element_infos["name"] == name: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
635 |
return choices_infos |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
636 |
elif choice_infos["name"] == name: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
637 |
return choices_infos |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
638 |
return None |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
639 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
640 |
def ComputeContentChoices(factory, name, infos): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
641 |
choices = [] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
642 |
for choice in infos["choices"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
643 |
if choice["type"] == "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
644 |
choice["name"] = "sequence" |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
645 |
for sequence_element in choice["elements"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
646 |
if sequence_element["type"] != CHOICE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
647 |
element_infos = factory.ExtractTypeInfos(sequence_element["name"], name, sequence_element["elmt_type"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
648 |
if element_infos is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
649 |
sequence_element["elmt_type"] = element_infos |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
650 |
elif choice["elmt_type"] == "tag": |
607
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
651 |
choice["elmt_type"] = GenerateTagInfos(choice) |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
652 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
653 |
choice_infos = factory.ExtractTypeInfos(choice["name"], name, choice["elmt_type"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
654 |
if choice_infos is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
655 |
choice["elmt_type"] = choice_infos |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
656 |
choices.append((choice["name"], choice)) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
657 |
return choices |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
658 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
659 |
def ExtractContentElement(factory, tree, infos, content): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
660 |
infos["elmt_type"] = FindTypeInfos(factory, infos["elmt_type"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
661 |
if infos["maxOccurs"] == "unbounded" or infos["maxOccurs"] > 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
662 |
if isinstance(content, ListType) and len(content) > 0 and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
663 |
content[-1]["name"] == tree.nodeName: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
664 |
content_item = content.pop(-1) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
665 |
content_item["value"].append(infos["elmt_type"]["extract"](tree)) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
666 |
return content_item |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
667 |
elif not isinstance(content, ListType) and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
668 |
content is not None and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
669 |
content["name"] == tree.nodeName: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
670 |
return {"name": tree.nodeName, |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
671 |
"value": content["value"] + [infos["elmt_type"]["extract"](tree)]} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
672 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
673 |
return {"name": tree.nodeName, |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
674 |
"value": [infos["elmt_type"]["extract"](tree)]} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
675 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
676 |
return {"name": tree.nodeName, |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
677 |
"value": infos["elmt_type"]["extract"](tree)} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
678 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
679 |
def GenerateContentInfos(factory, name, choices): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
680 |
choices_dict = {} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
681 |
for choice_name, infos in choices: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
682 |
if choice_name == "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
683 |
for element in infos["elements"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
684 |
if element["type"] == CHOICE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
685 |
element["elmt_type"] = GenerateContentInfos(factory, name, ComputeContentChoices(factory, name, element)) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
686 |
elif choices_dict.has_key(element["name"]): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
687 |
raise ValueError("'%s' element defined two times in choice" % choice_name) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
688 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
689 |
choices_dict[element["name"]] = infos |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
690 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
691 |
if choices_dict.has_key(choice_name): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
692 |
raise ValueError("'%s' element defined two times in choice" % choice_name) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
693 |
choices_dict[choice_name] = infos |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
694 |
|
565 | 695 |
def GetContentInitial(): |
696 |
content_name, infos = choices[0] |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
697 |
if content_name == "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
698 |
content_value = [] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
699 |
for i in xrange(infos["minOccurs"]): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
700 |
for element_infos in infos["elements"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
701 |
value = GetElementInitialValue(factory, element_infos) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
702 |
if value is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
703 |
if element_infos["type"] == CHOICE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
704 |
content_value.append(value) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
705 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
706 |
content_value.append({"name": element_infos["name"], "value": value}) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
707 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
708 |
content_value = GetElementInitialValue(factory, infos) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
709 |
return {"name": content_name, "value": content_value} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
710 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
711 |
def CheckContent(value): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
712 |
if value["name"] != "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
713 |
infos = choices_dict.get(value["name"], None) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
714 |
if infos is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
715 |
return CheckElementValue(factory, value["name"], infos, value["value"], False) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
716 |
elif len(value["value"]) > 0: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
717 |
infos = choices_dict.get(value["value"][0]["name"], None) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
718 |
if infos is None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
719 |
for choice_name, infos in choices: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
720 |
if infos["type"] == "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
721 |
for element_infos in infos["elements"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
722 |
if element_infos["type"] == CHOICE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
723 |
infos = GetContentInfos(value["value"][0]["name"], element_infos["choices"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
724 |
if infos is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
725 |
sequence_number = 0 |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
726 |
element_idx = 0 |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
727 |
while element_idx < len(value["value"]): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
728 |
for element_infos in infos["elements"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
729 |
if element_infos["name"] == value["value"][element_idx]["name"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
730 |
element_value = value["value"][element_idx]["value"] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
731 |
element_idx += 1 |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
732 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
733 |
element_value = None |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
734 |
if not CheckElementValue(factory, element_infos["name"], element_infos, element_value, False): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
735 |
raise ValueError("Invalid sequence value in attribute 'content'") |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
736 |
sequence_number += 1 |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
737 |
if sequence_number < infos["minOccurs"] or infos["maxOccurs"] != "unbounded" and sequence_number > infos["maxOccurs"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
738 |
raise ValueError("Invalid sequence value in attribute 'content'") |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
739 |
return True |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
740 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
741 |
for element_name, infos in choices: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
742 |
if element_name == "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
743 |
required = 0 |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
744 |
for element in infos["elements"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
745 |
if element["minOccurs"] > 0: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
746 |
required += 1 |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
747 |
if required == 0: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
748 |
return True |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
749 |
return False |
565 | 750 |
|
751 |
def ExtractContent(tree, content): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
752 |
infos = choices_dict.get(tree.nodeName, None) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
753 |
if infos is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
754 |
if infos["name"] == "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
755 |
sequence_dict = dict([(element_infos["name"], element_infos) for element_infos in infos["elements"] if element_infos["type"] != CHOICE]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
756 |
element_infos = sequence_dict.get(tree.nodeName) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
757 |
if content is not None and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
758 |
content["name"] == "sequence" and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
759 |
len(content["value"]) > 0 and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
760 |
choices_dict.get(content["value"][-1]["name"]) == infos: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
761 |
return {"name": "sequence", |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
762 |
"value": content["value"] + [ExtractContentElement(factory, tree, element_infos, content["value"][-1])]} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
763 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
764 |
return {"name": "sequence", |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
765 |
"value": [ExtractContentElement(factory, tree, element_infos, None)]} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
766 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
767 |
return ExtractContentElement(factory, tree, infos, content) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
768 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
769 |
for choice_name, infos in choices: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
770 |
if infos["type"] == "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
771 |
for element_infos in infos["elements"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
772 |
if element_infos["type"] == CHOICE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
773 |
try: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
774 |
if content is not None and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
775 |
content["name"] == "sequence" and \ |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
776 |
len(content["value"]) > 0: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
777 |
return {"name": "sequence", |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
778 |
"value": content["value"] + [element_infos["elmt_type"]["extract"](tree, content["value"][-1])]} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
779 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
780 |
return {"name": "sequence", |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
781 |
"value": [element_infos["elmt_type"]["extract"](tree, None)]} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
782 |
except: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
783 |
pass |
565 | 784 |
raise ValueError("Invalid element \"%s\" for content!" % tree.nodeName) |
785 |
||
786 |
def GenerateContent(value, name=None, indent=0): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
787 |
text = "" |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
788 |
if value["name"] != "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
789 |
infos = choices_dict.get(value["name"], None) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
790 |
if infos is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
791 |
infos["elmt_type"] = FindTypeInfos(factory, infos["elmt_type"]) |
565 | 792 |
if infos["maxOccurs"] == "unbounded" or infos["maxOccurs"] > 1: |
793 |
for item in value["value"]: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
794 |
text += infos["elmt_type"]["generate"](item, value["name"], indent) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
795 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
796 |
text += infos["elmt_type"]["generate"](value["value"], value["name"], indent) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
797 |
elif len(value["value"]) > 0: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
798 |
infos = choices_dict.get(value["value"][0]["name"], None) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
799 |
if infos is None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
800 |
for choice_name, infos in choices: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
801 |
if infos["type"] == "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
802 |
for element_infos in infos["elements"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
803 |
if element_infos["type"] == CHOICE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
804 |
infos = GetContentInfos(value["value"][0]["name"], element_infos["choices"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
805 |
if infos is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
806 |
sequence_dict = dict([(element_infos["name"], element_infos) for element_infos in infos["elements"]]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
807 |
for element_value in value["value"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
808 |
element_infos = sequence_dict.get(element_value["name"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
809 |
if element_infos["maxOccurs"] == "unbounded" or element_infos["maxOccurs"] > 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
810 |
for item in element_value["value"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
811 |
text += element_infos["elmt_type"]["generate"](item, element_value["name"], indent) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
812 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
813 |
text += element_infos["elmt_type"]["generate"](element_value["value"], element_infos["name"], indent) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
814 |
return text |
565 | 815 |
|
816 |
return { |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
817 |
"type": COMPLEXTYPE, |
565 | 818 |
"initial": GetContentInitial, |
819 |
"check": CheckContent, |
|
820 |
"extract": ExtractContent, |
|
821 |
"generate": GenerateContent |
|
822 |
} |
|
823 |
||
824 |
#------------------------------------------------------------------------------- |
|
825 |
# Structure extraction functions |
|
826 |
#------------------------------------------------------------------------------- |
|
827 |
||
828 |
||
829 |
def DecomposeQualifiedName(name): |
|
830 |
result = QName_model.match(name) |
|
831 |
if not result: |
|
832 |
raise ValueError("\"%s\" isn't a valid QName value!" % name) |
|
833 |
parts = result.groups()[0].split(':') |
|
834 |
if len(parts) == 1: |
|
835 |
return None, parts[0] |
|
836 |
return parts |
|
837 |
||
838 |
def GenerateElement(element_name, attributes, elements_model, |
|
839 |
accept_text=False): |
|
840 |
def ExtractElement(factory, node): |
|
841 |
attrs = factory.ExtractNodeAttrs(element_name, node, attributes) |
|
842 |
children_structure = "" |
|
843 |
children_infos = [] |
|
844 |
children = [] |
|
845 |
for child in node.childNodes: |
|
846 |
if child.nodeName not in ["#comment", "#text"]: |
|
847 |
namespace, childname = DecomposeQualifiedName(child.nodeName) |
|
848 |
children_structure += "%s "%childname |
|
849 |
result = elements_model.match(children_structure) |
|
850 |
if not result: |
|
851 |
raise ValueError("Invalid structure for \"%s\" children!. First element invalid." % node.nodeName) |
|
852 |
valid = result.groups()[0] |
|
853 |
if len(valid) < len(children_structure): |
|
854 |
raise ValueError("Invalid structure for \"%s\" children!. Element number %d invalid." % (node.nodeName, len(valid.split(" ")) - 1)) |
|
855 |
for child in node.childNodes: |
|
856 |
if child.nodeName != "#comment" and \ |
|
857 |
(accept_text or child.nodeName != "#text"): |
|
858 |
if child.nodeName == "#text": |
|
859 |
children.append(GetAttributeValue(node)) |
|
860 |
else: |
|
861 |
namespace, childname = DecomposeQualifiedName(child.nodeName) |
|
862 |
infos = factory.GetQualifiedNameInfos(childname, namespace) |
|
863 |
if infos["type"] != SYNTAXELEMENT: |
|
864 |
raise ValueError("\"%s\" can't be a member child!" % name) |
|
865 |
if infos["extract"].has_key(element_name): |
|
866 |
children.append(infos["extract"][element_name](factory, child)) |
|
867 |
else: |
|
868 |
children.append(infos["extract"]["default"](factory, child)) |
|
869 |
return node.nodeName, attrs, children |
|
870 |
return ExtractElement |
|
871 |
||
872 |
||
873 |
""" |
|
874 |
Class that generate class from an XML Tree |
|
875 |
""" |
|
876 |
class ClassFactory: |
|
877 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
878 |
def __init__(self, document, filepath=None, debug=False): |
565 | 879 |
self.Document = document |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
880 |
if filepath is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
881 |
self.BaseFolder, self.FileName = os.path.split(filepath) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
882 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
883 |
self.BaseFolder = self.FileName = None |
565 | 884 |
self.Debug = debug |
885 |
||
886 |
# Dictionary for stocking Classes and Types definitions created from |
|
887 |
# the XML tree |
|
888 |
self.XMLClassDefinitions = {} |
|
889 |
||
890 |
self.DefinedNamespaces = {} |
|
891 |
self.Namespaces = {} |
|
892 |
self.SchemaNamespace = None |
|
893 |
self.TargetNamespace = None |
|
894 |
||
895 |
self.CurrentCompilations = [] |
|
896 |
||
897 |
# Dictionaries for stocking Classes and Types generated |
|
898 |
self.ComputeAfter = [] |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
899 |
if self.FileName is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
900 |
self.ComputedClasses = {self.FileName: {}} |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
901 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
902 |
self.ComputedClasses = {} |
565 | 903 |
self.ComputedClassesInfos = {} |
904 |
self.AlreadyComputed = {} |
|
905 |
||
906 |
def GetQualifiedNameInfos(self, name, namespace=None, canbenone=False): |
|
907 |
if namespace is None: |
|
908 |
if self.Namespaces[self.SchemaNamespace].has_key(name): |
|
909 |
return self.Namespaces[self.SchemaNamespace][name] |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
910 |
for space, elements in self.Namespaces.iteritems(): |
565 | 911 |
if space != self.SchemaNamespace and elements.has_key(name): |
912 |
return elements[name] |
|
913 |
parts = name.split("_", 1) |
|
914 |
if len(parts) > 1: |
|
915 |
group = self.GetQualifiedNameInfos(parts[0], namespace) |
|
916 |
if group is not None and group["type"] == ELEMENTSGROUP: |
|
917 |
elements = [] |
|
918 |
if group.has_key("elements"): |
|
919 |
elements = group["elements"] |
|
920 |
elif group.has_key("choices"): |
|
921 |
elements = group["choices"] |
|
922 |
for element in elements: |
|
923 |
if element["name"] == parts[1]: |
|
924 |
return element |
|
925 |
if not canbenone: |
|
926 |
raise ValueError("Unknown element \"%s\" for any defined namespaces!" % name) |
|
927 |
elif self.Namespaces.has_key(namespace): |
|
928 |
if self.Namespaces[namespace].has_key(name): |
|
929 |
return self.Namespaces[namespace][name] |
|
930 |
parts = name.split("_", 1) |
|
931 |
if len(parts) > 1: |
|
932 |
group = self.GetQualifiedNameInfos(parts[0], namespace) |
|
933 |
if group is not None and group["type"] == ELEMENTSGROUP: |
|
934 |
elements = [] |
|
935 |
if group.has_key("elements"): |
|
936 |
elements = group["elements"] |
|
937 |
elif group.has_key("choices"): |
|
938 |
elements = group["choices"] |
|
939 |
for element in elements: |
|
940 |
if element["name"] == parts[1]: |
|
941 |
return element |
|
942 |
if not canbenone: |
|
943 |
raise ValueError("Unknown element \"%s\" for namespace \"%s\"!" % (name, namespace)) |
|
944 |
elif not canbenone: |
|
945 |
raise ValueError("Unknown namespace \"%s\"!" % namespace) |
|
946 |
return None |
|
947 |
||
948 |
def SplitQualifiedName(self, name, namespace=None, canbenone=False): |
|
949 |
if namespace is None: |
|
950 |
if self.Namespaces[self.SchemaNamespace].has_key(name): |
|
951 |
return name, None |
|
952 |
for space, elements in self.Namespaces.items(): |
|
953 |
if space != self.SchemaNamespace and elements.has_key(name): |
|
954 |
return name, None |
|
955 |
parts = name.split("_", 1) |
|
956 |
if len(parts) > 1: |
|
957 |
group = self.GetQualifiedNameInfos(parts[0], namespace) |
|
958 |
if group is not None and group["type"] == ELEMENTSGROUP: |
|
959 |
elements = [] |
|
960 |
if group.has_key("elements"): |
|
961 |
elements = group["elements"] |
|
962 |
elif group.has_key("choices"): |
|
963 |
elements = group["choices"] |
|
964 |
for element in elements: |
|
965 |
if element["name"] == parts[1]: |
|
966 |
return part[1], part[0] |
|
967 |
if not canbenone: |
|
968 |
raise ValueError("Unknown element \"%s\" for any defined namespaces!" % name) |
|
969 |
elif self.Namespaces.has_key(namespace): |
|
970 |
if self.Namespaces[namespace].has_key(name): |
|
971 |
return name, None |
|
972 |
parts = name.split("_", 1) |
|
973 |
if len(parts) > 1: |
|
974 |
group = self.GetQualifiedNameInfos(parts[0], namespace) |
|
975 |
if group is not None and group["type"] == ELEMENTSGROUP: |
|
976 |
elements = [] |
|
977 |
if group.has_key("elements"): |
|
978 |
elements = group["elements"] |
|
979 |
elif group.has_key("choices"): |
|
980 |
elements = group["choices"] |
|
981 |
for element in elements: |
|
982 |
if element["name"] == parts[1]: |
|
983 |
return parts[1], parts[0] |
|
984 |
if not canbenone: |
|
985 |
raise ValueError("Unknown element \"%s\" for namespace \"%s\"!" % (name, namespace)) |
|
986 |
elif not canbenone: |
|
987 |
raise ValueError("Unknown namespace \"%s\"!" % namespace) |
|
988 |
return None, None |
|
989 |
||
990 |
def ExtractNodeAttrs(self, element_name, node, valid_attrs): |
|
991 |
attrs = {} |
|
992 |
for qualified_name, attr in node._attrs.items(): |
|
993 |
namespace, name = DecomposeQualifiedName(qualified_name) |
|
994 |
if name in valid_attrs: |
|
995 |
infos = self.GetQualifiedNameInfos(name, namespace) |
|
996 |
if infos["type"] != SYNTAXATTRIBUTE: |
|
997 |
raise ValueError("\"%s\" can't be a member attribute!" % name) |
|
998 |
elif name in attrs: |
|
999 |
raise ValueError("\"%s\" attribute has been twice!" % name) |
|
1000 |
elif element_name in infos["extract"]: |
|
1001 |
attrs[name] = infos["extract"][element_name](attr) |
|
1002 |
else: |
|
1003 |
attrs[name] = infos["extract"]["default"](attr) |
|
1004 |
elif namespace == "xmlns": |
|
1005 |
infos = self.GetQualifiedNameInfos("anyURI", self.SchemaNamespace) |
|
1006 |
self.DefinedNamespaces[infos["extract"](attr)] = name |
|
1007 |
else: |
|
1008 |
raise ValueError("Invalid attribute \"%s\" for member \"%s\"!" % (qualified_name, node.nodeName)) |
|
1009 |
for attr in valid_attrs: |
|
1010 |
if attr not in attrs and \ |
|
1011 |
self.Namespaces[self.SchemaNamespace].has_key(attr) and \ |
|
1012 |
self.Namespaces[self.SchemaNamespace][attr].has_key("default"): |
|
1013 |
if self.Namespaces[self.SchemaNamespace][attr]["default"].has_key(element_name): |
|
1014 |
default = self.Namespaces[self.SchemaNamespace][attr]["default"][element_name] |
|
1015 |
else: |
|
1016 |
default = self.Namespaces[self.SchemaNamespace][attr]["default"]["default"] |
|
1017 |
if default is not None: |
|
1018 |
attrs[attr] = default |
|
1019 |
return attrs |
|
1020 |
||
1021 |
def ReduceElements(self, elements, schema=False): |
|
1022 |
result = [] |
|
1023 |
for child_infos in elements: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1024 |
if child_infos is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1025 |
if child_infos[1].has_key("name") and schema: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1026 |
self.CurrentCompilations.append(child_infos[1]["name"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1027 |
namespace, name = DecomposeQualifiedName(child_infos[0]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1028 |
infos = self.GetQualifiedNameInfos(name, namespace) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1029 |
if infos["type"] != SYNTAXELEMENT: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1030 |
raise ValueError("\"%s\" can't be a member child!" % name) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1031 |
element = infos["reduce"](self, child_infos[1], child_infos[2]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1032 |
if element is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1033 |
result.append(element) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1034 |
if child_infos[1].has_key("name") and schema: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1035 |
self.CurrentCompilations.pop(-1) |
565 | 1036 |
annotations = [] |
1037 |
children = [] |
|
1038 |
for element in result: |
|
1039 |
if element["type"] == "annotation": |
|
1040 |
annotations.append(element) |
|
1041 |
else: |
|
1042 |
children.append(element) |
|
1043 |
return annotations, children |
|
1044 |
||
1045 |
def AddComplexType(self, typename, infos): |
|
1046 |
if not self.XMLClassDefinitions.has_key(typename): |
|
1047 |
self.XMLClassDefinitions[typename] = infos |
|
1048 |
else: |
|
1049 |
raise ValueError("\"%s\" class already defined. Choose another name!" % typename) |
|
1050 |
||
1051 |
def ParseSchema(self): |
|
1052 |
pass |
|
1053 |
||
1054 |
def ExtractTypeInfos(self, name, parent, typeinfos): |
|
1055 |
if isinstance(typeinfos, (StringType, UnicodeType)): |
|
1056 |
namespace, name = DecomposeQualifiedName(typeinfos) |
|
1057 |
infos = self.GetQualifiedNameInfos(name, namespace) |
|
1058 |
if infos["type"] == COMPLEXTYPE: |
|
1059 |
name, parent = self.SplitQualifiedName(name, namespace) |
|
1060 |
result = self.CreateClass(name, parent, infos) |
|
1061 |
if result is not None and not isinstance(result, (UnicodeType, StringType)): |
|
1062 |
self.Namespaces[self.TargetNamespace][result["name"]] = result |
|
1063 |
return result |
|
1064 |
elif infos["type"] == ELEMENT and infos["elmt_type"]["type"] == COMPLEXTYPE: |
|
1065 |
name, parent = self.SplitQualifiedName(name, namespace) |
|
1066 |
result = self.CreateClass(name, parent, infos["elmt_type"]) |
|
1067 |
if result is not None and not isinstance(result, (UnicodeType, StringType)): |
|
1068 |
self.Namespaces[self.TargetNamespace][result["name"]] = result |
|
1069 |
return result |
|
1070 |
else: |
|
1071 |
return infos |
|
1072 |
elif typeinfos["type"] == COMPLEXTYPE: |
|
1073 |
return self.CreateClass(name, parent, typeinfos) |
|
1074 |
elif typeinfos["type"] == SIMPLETYPE: |
|
1075 |
return typeinfos |
|
1076 |
||
1077 |
""" |
|
1078 |
Methods that generates the classes |
|
1079 |
""" |
|
1080 |
def CreateClasses(self): |
|
1081 |
self.ParseSchema() |
|
1082 |
for name, infos in self.Namespaces[self.TargetNamespace].items(): |
|
1083 |
if infos["type"] == ELEMENT: |
|
1084 |
if not isinstance(infos["elmt_type"], (UnicodeType, StringType)) and \ |
|
1085 |
infos["elmt_type"]["type"] == COMPLEXTYPE: |
|
1086 |
self.ComputeAfter.append((name, None, infos["elmt_type"], True)) |
|
1087 |
while len(self.ComputeAfter) > 0: |
|
1088 |
result = self.CreateClass(*self.ComputeAfter.pop(0)) |
|
1089 |
if result is not None and not isinstance(result, (UnicodeType, StringType)): |
|
1090 |
self.Namespaces[self.TargetNamespace][result["name"]] = result |
|
1091 |
elif infos["type"] == COMPLEXTYPE: |
|
1092 |
self.ComputeAfter.append((name, None, infos)) |
|
1093 |
while len(self.ComputeAfter) > 0: |
|
1094 |
result = self.CreateClass(*self.ComputeAfter.pop(0)) |
|
1095 |
if result is not None and \ |
|
1096 |
not isinstance(result, (UnicodeType, StringType)): |
|
1097 |
self.Namespaces[self.TargetNamespace][result["name"]] = result |
|
1098 |
elif infos["type"] == ELEMENTSGROUP: |
|
1099 |
elements = [] |
|
1100 |
if infos.has_key("elements"): |
|
1101 |
elements = infos["elements"] |
|
1102 |
elif infos.has_key("choices"): |
|
1103 |
elements = infos["choices"] |
|
1104 |
for element in elements: |
|
1105 |
if not isinstance(element["elmt_type"], (UnicodeType, StringType)) and \ |
|
1106 |
element["elmt_type"]["type"] == COMPLEXTYPE: |
|
1107 |
self.ComputeAfter.append((element["name"], infos["name"], element["elmt_type"])) |
|
1108 |
while len(self.ComputeAfter) > 0: |
|
1109 |
result = self.CreateClass(*self.ComputeAfter.pop(0)) |
|
1110 |
if result is not None and \ |
|
1111 |
not isinstance(result, (UnicodeType, StringType)): |
|
1112 |
self.Namespaces[self.TargetNamespace][result["name"]] = result |
|
1113 |
return self.ComputedClasses |
|
1114 |
||
1115 |
def CreateClass(self, name, parent, classinfos, baseclass = False): |
|
1116 |
if parent is not None: |
|
1117 |
classname = "%s_%s" % (parent, name) |
|
1118 |
else: |
|
1119 |
classname = name |
|
1120 |
||
1121 |
# Checks that classe haven't been generated yet |
|
1122 |
if self.AlreadyComputed.get(classname, False): |
|
1123 |
if baseclass: |
|
1124 |
self.AlreadyComputed[classname].IsBaseClass = baseclass |
|
1125 |
return self.ComputedClassesInfos.get(classname, None) |
|
1126 |
||
1127 |
# If base classes haven't been generated |
|
1128 |
bases = [] |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1129 |
base_infos = classinfos.get("base", None) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1130 |
if base_infos is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1131 |
result = self.ExtractTypeInfos("base", name, base_infos) |
565 | 1132 |
if result is None: |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1133 |
namespace, base_name = DecomposeQualifiedName(base_infos) |
565 | 1134 |
if self.AlreadyComputed.get(base_name, False): |
1135 |
self.ComputeAfter.append((name, parent, classinfos)) |
|
1136 |
if self.TargetNamespace is not None: |
|
1137 |
return "%s:%s" % (self.TargetNamespace, classname) |
|
1138 |
else: |
|
1139 |
return classname |
|
1140 |
elif result is not None: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1141 |
if self.FileName is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1142 |
classinfos["base"] = self.ComputedClasses[self.FileName].get(result["name"], None) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1143 |
if classinfos["base"] is None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1144 |
for filename, classes in self.ComputedClasses.iteritems(): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1145 |
if filename != self.FileName: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1146 |
classinfos["base"] = classes.get(result["name"], None) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1147 |
if classinfos["base"] is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1148 |
break |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1149 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1150 |
classinfos["base"] = self.ComputedClasses.get(result["name"], None) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1151 |
if classinfos["base"] is None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1152 |
raise ValueError("No class found for base type") |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1153 |
bases.append(classinfos["base"]) |
565 | 1154 |
bases.append(object) |
1155 |
bases = tuple(bases) |
|
1156 |
classmembers = {"__doc__": classinfos.get("doc", ""), "IsBaseClass": baseclass} |
|
1157 |
||
1158 |
self.AlreadyComputed[classname] = True |
|
1159 |
||
1160 |
for attribute in classinfos["attributes"]: |
|
1161 |
infos = self.ExtractTypeInfos(attribute["name"], name, attribute["attr_type"]) |
|
1162 |
if infos is not None: |
|
1163 |
if infos["type"] != SIMPLETYPE: |
|
1164 |
raise ValueError("\"%s\" type is not a simple type!" % attribute["attr_type"]) |
|
1165 |
attrname = attribute["name"] |
|
1166 |
if attribute["use"] == "optional": |
|
1167 |
classmembers[attrname] = None |
|
1168 |
classmembers["add%s"%attrname] = generateAddMethod(attrname, self, attribute) |
|
1169 |
classmembers["delete%s"%attrname] = generateDeleteMethod(attrname) |
|
1170 |
else: |
|
1171 |
classmembers[attrname] = infos["initial"]() |
|
1172 |
classmembers["set%s"%attrname] = generateSetMethod(attrname) |
|
1173 |
classmembers["get%s"%attrname] = generateGetMethod(attrname) |
|
1174 |
else: |
|
1175 |
raise ValueError("\"%s\" type unrecognized!" % attribute["attr_type"]) |
|
1176 |
attribute["attr_type"] = infos |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1177 |
|
565 | 1178 |
for element in classinfos["elements"]: |
1179 |
if element["type"] == CHOICE: |
|
1180 |
elmtname = element["name"] |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1181 |
choices = ComputeContentChoices(self, name, element) |
565 | 1182 |
classmembers["get%schoices"%elmtname] = generateGetChoicesMethod(element["choices"]) |
1183 |
if element["maxOccurs"] == "unbounded" or element["maxOccurs"] > 1: |
|
1184 |
classmembers["append%sbytype" % elmtname] = generateAppendChoiceByTypeMethod(element["maxOccurs"], self, element["choices"]) |
|
1185 |
classmembers["insert%sbytype" % elmtname] = generateInsertChoiceByTypeMethod(element["maxOccurs"], self, element["choices"]) |
|
1186 |
else: |
|
1187 |
classmembers["set%sbytype" % elmtname] = generateSetChoiceByTypeMethod(self, element["choices"]) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1188 |
infos = GenerateContentInfos(self, name, choices) |
565 | 1189 |
elif element["type"] == ANY: |
1190 |
elmtname = element["name"] = "text" |
|
1191 |
element["minOccurs"] = element["maxOccurs"] = 1 |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1192 |
infos = GenerateAnyInfos(element) |
565 | 1193 |
else: |
1194 |
elmtname = element["name"] |
|
607
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
1195 |
if element["elmt_type"] == "tag": |
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
1196 |
infos = GenerateTagInfos(element) |
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
1197 |
else: |
9c133d675b69
Adding support for defining tag element without attributes or children as sequence element
laurent
parents:
603
diff
changeset
|
1198 |
infos = self.ExtractTypeInfos(element["name"], name, element["elmt_type"]) |
565 | 1199 |
if infos is not None: |
1200 |
element["elmt_type"] = infos |
|
1201 |
if element["maxOccurs"] == "unbounded" or element["maxOccurs"] > 1: |
|
1202 |
classmembers[elmtname] = [] |
|
1203 |
classmembers["append%s" % elmtname] = generateAppendMethod(elmtname, element["maxOccurs"], self, element) |
|
1204 |
classmembers["insert%s" % elmtname] = generateInsertMethod(elmtname, element["maxOccurs"], self, element) |
|
1205 |
classmembers["remove%s" % elmtname] = generateRemoveMethod(elmtname, element["minOccurs"]) |
|
1206 |
classmembers["count%s" % elmtname] = generateCountMethod(elmtname) |
|
1207 |
else: |
|
1208 |
if element["minOccurs"] == 0: |
|
1209 |
classmembers[elmtname] = None |
|
1210 |
classmembers["add%s" % elmtname] = generateAddMethod(elmtname, self, element) |
|
1211 |
classmembers["delete%s" % elmtname] = generateDeleteMethod(elmtname) |
|
1212 |
elif not isinstance(element["elmt_type"], (UnicodeType, StringType)): |
|
1213 |
classmembers[elmtname] = element["elmt_type"]["initial"]() |
|
1214 |
else: |
|
1215 |
classmembers[elmtname] = None |
|
1216 |
classmembers["set%s" % elmtname] = generateSetMethod(elmtname) |
|
1217 |
classmembers["get%s" % elmtname] = generateGetMethod(elmtname) |
|
1218 |
||
1219 |
classmembers["__init__"] = generateInitMethod(self, classinfos) |
|
1220 |
classmembers["getStructure"] = generateStructureMethod(classinfos) |
|
1221 |
classmembers["loadXMLTree"] = generateLoadXMLTree(self, classinfos) |
|
1222 |
classmembers["generateXMLText"] = generateGenerateXMLText(self, classinfos) |
|
1223 |
classmembers["getElementAttributes"] = generateGetElementAttributes(self, classinfos) |
|
1224 |
classmembers["getElementInfos"] = generateGetElementInfos(self, classinfos) |
|
1225 |
classmembers["setElementValue"] = generateSetElementValue(self, classinfos) |
|
1226 |
classmembers["singleLineAttributes"] = True |
|
1227 |
classmembers["compatibility"] = lambda x, y: None |
|
1228 |
||
1229 |
class_definition = classobj(str(classname), bases, classmembers) |
|
626
ac0a8f6462c3
Fix bug in xmlclass when allowing custom class attributes definition on inherited classes
laurent
parents:
616
diff
changeset
|
1230 |
setattr(class_definition, "__setattr__", generateSetattrMethod(self, class_definition, classinfos)) |
565 | 1231 |
class_infos = {"type": COMPILEDCOMPLEXTYPE, |
1232 |
"name": classname, |
|
1233 |
"check": generateClassCheckFunction(class_definition), |
|
1234 |
"initial": generateClassCreateFunction(class_definition), |
|
1235 |
"extract": generateClassExtractFunction(class_definition), |
|
1236 |
"generate": class_definition.generateXMLText} |
|
1237 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1238 |
if self.FileName is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1239 |
self.ComputedClasses[self.FileName][classname] = class_definition |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1240 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1241 |
self.ComputedClasses[classname] = class_definition |
565 | 1242 |
self.ComputedClassesInfos[classname] = class_infos |
1243 |
||
1244 |
return class_infos |
|
1245 |
||
1246 |
""" |
|
1247 |
Methods that print the classes generated |
|
1248 |
""" |
|
1249 |
def PrintClasses(self): |
|
1250 |
items = self.ComputedClasses.items() |
|
1251 |
items.sort() |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1252 |
if self.FileName is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1253 |
for filename, classes in items: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1254 |
print "File '%s':" % filename |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1255 |
class_items = classes.items() |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1256 |
class_items.sort() |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1257 |
for classname, xmlclass in class_items: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1258 |
print "%s: %s" % (classname, str(xmlclass)) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1259 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1260 |
for classname, xmlclass in items: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1261 |
print "%s: %s" % (classname, str(xmlclass)) |
565 | 1262 |
|
1263 |
def PrintClassNames(self): |
|
1264 |
classnames = self.XMLClassDefinitions.keys() |
|
1265 |
classnames.sort() |
|
1266 |
for classname in classnames: |
|
1267 |
print classname |
|
1268 |
||
1269 |
""" |
|
1270 |
Method that generate the method for checking a class instance |
|
1271 |
""" |
|
1272 |
def generateClassCheckFunction(class_definition): |
|
1273 |
def classCheckfunction(instance): |
|
1274 |
return isinstance(instance, class_definition) |
|
1275 |
return classCheckfunction |
|
1276 |
||
1277 |
""" |
|
1278 |
Method that generate the method for creating a class instance |
|
1279 |
""" |
|
1280 |
def generateClassCreateFunction(class_definition): |
|
1281 |
def classCreatefunction(): |
|
1282 |
return class_definition() |
|
1283 |
return classCreatefunction |
|
1284 |
||
1285 |
""" |
|
1286 |
Method that generate the method for extracting a class instance |
|
1287 |
""" |
|
1288 |
def generateClassExtractFunction(class_definition): |
|
1289 |
def classExtractfunction(node): |
|
1290 |
instance = class_definition() |
|
1291 |
instance.loadXMLTree(node) |
|
1292 |
return instance |
|
1293 |
return classExtractfunction |
|
1294 |
||
1295 |
""" |
|
1296 |
Method that generate the method for loading an xml tree by following the |
|
1297 |
attributes list defined |
|
1298 |
""" |
|
626
ac0a8f6462c3
Fix bug in xmlclass when allowing custom class attributes definition on inherited classes
laurent
parents:
616
diff
changeset
|
1299 |
def generateSetattrMethod(factory, class_definition, classinfos): |
565 | 1300 |
attributes = dict([(attr["name"], attr) for attr in classinfos["attributes"] if attr["use"] != "prohibited"]) |
1301 |
optional_attributes = dict([(attr["name"], True) for attr in classinfos["attributes"] if attr["use"] == "optional"]) |
|
1302 |
elements = dict([(element["name"], element) for element in classinfos["elements"]]) |
|
1303 |
||
1304 |
def setattrMethod(self, name, value): |
|
1305 |
if attributes.has_key(name): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1306 |
attributes[name]["attr_type"] = FindTypeInfos(factory, attributes[name]["attr_type"]) |
565 | 1307 |
if value is None: |
1308 |
if optional_attributes.get(name, False): |
|
1309 |
return object.__setattr__(self, name, None) |
|
1310 |
else: |
|
1311 |
raise ValueError("Attribute '%s' isn't optional." % name) |
|
1312 |
elif attributes[name].has_key("fixed") and value != attributes[name]["fixed"]: |
|
1313 |
raise ValueError, "Value of attribute '%s' can only be '%s'."%(name, str(attributes[name]["fixed"])) |
|
1314 |
elif attributes[name]["attr_type"]["check"](value): |
|
1315 |
return object.__setattr__(self, name, value) |
|
1316 |
else: |
|
1317 |
raise ValueError("Invalid value for attribute '%s'." % (name)) |
|
1318 |
elif elements.has_key(name): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1319 |
if CheckElementValue(factory, name, elements[name], value): |
565 | 1320 |
return object.__setattr__(self, name, value) |
1321 |
else: |
|
1322 |
raise ValueError("Invalid value for attribute '%s'." % (name)) |
|
1323 |
elif classinfos.has_key("base"): |
|
1324 |
return classinfos["base"].__setattr__(self, name, value) |
|
626
ac0a8f6462c3
Fix bug in xmlclass when allowing custom class attributes definition on inherited classes
laurent
parents:
616
diff
changeset
|
1325 |
elif class_definition.__dict__.has_key(name): |
565 | 1326 |
return object.__setattr__(self, name, value) |
1327 |
else: |
|
1328 |
raise AttributeError("'%s' can't have an attribute '%s'." % (self.__class__.__name__, name)) |
|
1329 |
||
1330 |
return setattrMethod |
|
1331 |
||
1332 |
""" |
|
1333 |
Method that generate the method for generating the xml tree structure model by |
|
1334 |
following the attributes list defined |
|
1335 |
""" |
|
1336 |
def ComputeMultiplicity(name, infos): |
|
1337 |
if infos["minOccurs"] == 0: |
|
1338 |
if infos["maxOccurs"] == "unbounded": |
|
1339 |
return "(?:%s)*" % name |
|
1340 |
elif infos["maxOccurs"] == 1: |
|
1341 |
return "(?:%s)?" % name |
|
1342 |
else: |
|
1343 |
return "(?:%s){,%d}" % (name, infos["maxOccurs"]) |
|
1344 |
elif infos["minOccurs"] == 1: |
|
1345 |
if infos["maxOccurs"] == "unbounded": |
|
1346 |
return "(?:%s)+" % name |
|
1347 |
elif infos["maxOccurs"] == 1: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1348 |
return "(?:%s)" % name |
565 | 1349 |
else: |
1350 |
return "(?:%s){1,%d}" % (name, infos["maxOccurs"]) |
|
1351 |
else: |
|
1352 |
if infos["maxOccurs"] == "unbounded": |
|
1353 |
return "(?:%s){%d,}" % (name, infos["minOccurs"], name) |
|
1354 |
else: |
|
1355 |
return "(?:%s){%d,%d}" % (name, infos["minOccurs"], |
|
1356 |
infos["maxOccurs"]) |
|
1357 |
||
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1358 |
def GetStructure(classinfos): |
565 | 1359 |
elements = [] |
1360 |
for element in classinfos["elements"]: |
|
1361 |
if element["type"] == ANY: |
|
593
34c3569042db
Fixing bug in xmlclass with empty CDATA. Empty CDATA aren't present in xml tree and prompt error when trying to load empty ANY tag using CDATA
laurent
parents:
592
diff
changeset
|
1362 |
infos = element.copy() |
34c3569042db
Fixing bug in xmlclass with empty CDATA. Empty CDATA aren't present in xml tree and prompt error when trying to load empty ANY tag using CDATA
laurent
parents:
592
diff
changeset
|
1363 |
infos["minOccurs"] = 0 |
601
32c0f4a626db
Adding support for loading #text node in formattedText
laurent
parents:
594
diff
changeset
|
1364 |
elements.append(ComputeMultiplicity("#text |#cdata-section |\w* ", infos)) |
565 | 1365 |
elif element["type"] == CHOICE: |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1366 |
choices = [] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1367 |
for infos in element["choices"]: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1368 |
if infos["type"] == "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1369 |
structure = "(?:%s)" % GetStructure(infos) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1370 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1371 |
structure = "%s " % infos["name"] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1372 |
choices.append(ComputeMultiplicity(structure, infos)) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1373 |
elements.append(ComputeMultiplicity("|".join(choices), element)) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1374 |
elif element["name"] == "content" and element["elmt_type"]["type"] == SIMPLETYPE: |
603
25c92309cdae
Fixing bug in xmlclass with simple type elements containing #text node instead of cdata
laurent
parents:
602
diff
changeset
|
1375 |
elements.append("(?:#text |#cdata-section )?") |
565 | 1376 |
else: |
1377 |
elements.append(ComputeMultiplicity("%s " % element["name"], element)) |
|
1378 |
if classinfos.get("order", True) or len(elements) == 0: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1379 |
return "".join(elements) |
565 | 1380 |
else: |
1381 |
raise ValueError("XSD structure not yet supported!") |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1382 |
|
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1383 |
def generateStructureMethod(classinfos): |
565 | 1384 |
def getStructureMethod(self): |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1385 |
structure = GetStructure(classinfos) |
565 | 1386 |
if classinfos.has_key("base"): |
1387 |
return classinfos["base"].getStructure(self) + structure |
|
1388 |
return structure |
|
1389 |
return getStructureMethod |
|
1390 |
||
1391 |
""" |
|
1392 |
Method that generate the method for loading an xml tree by following the |
|
1393 |
attributes list defined |
|
1394 |
""" |
|
1395 |
def generateLoadXMLTree(factory, classinfos): |
|
1396 |
attributes = dict([(attr["name"], attr) for attr in classinfos["attributes"] if attr["use"] != "prohibited"]) |
|
1397 |
elements = dict([(element["name"], element) for element in classinfos["elements"]]) |
|
1398 |
||
1399 |
def loadXMLTreeMethod(self, tree, extras=[], derived=False): |
|
1400 |
self.compatibility(tree) |
|
1401 |
if not derived: |
|
1402 |
children_structure = "" |
|
1403 |
for node in tree.childNodes: |
|
601
32c0f4a626db
Adding support for loading #text node in formattedText
laurent
parents:
594
diff
changeset
|
1404 |
if not (node.nodeName == "#text" and node.data.strip() == "") and node.nodeName != "#comment": |
565 | 1405 |
children_structure += "%s " % node.nodeName |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1406 |
structure_pattern = self.getStructure() |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1407 |
if structure_pattern != "": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1408 |
structure_model = re.compile("(%s)$" % structure_pattern) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1409 |
result = structure_model.match(children_structure) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1410 |
if not result: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1411 |
raise ValueError("Invalid structure for \"%s\" children!." % tree.nodeName) |
565 | 1412 |
required_attributes = dict([(attr["name"], True) for attr in classinfos["attributes"] if attr["use"] == "required"]) |
1413 |
if classinfos.has_key("base"): |
|
1414 |
extras.extend([attr["name"] for attr in classinfos["attributes"] if attr["use"] != "prohibited"]) |
|
1415 |
classinfos["base"].loadXMLTree(self, tree, extras, True) |
|
1416 |
for attrname, attr in tree._attrs.iteritems(): |
|
1417 |
if attributes.has_key(attrname): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1418 |
attributes[attrname]["attr_type"] = FindTypeInfos(factory, attributes[attrname]["attr_type"]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1419 |
object.__setattr__(self, attrname, attributes[attrname]["attr_type"]["extract"](attr)) |
565 | 1420 |
elif not classinfos.has_key("base") and attrname not in extras: |
1421 |
raise ValueError("Invalid attribute \"%s\" for \"%s\" element!" % (attrname, tree.nodeName)) |
|
1422 |
required_attributes.pop(attrname, None) |
|
1423 |
if len(required_attributes) > 0: |
|
1424 |
raise ValueError("Required attributes %s missing for \"%s\" element!" % (", ".join(["\"%s\""%name for name in required_attributes]), tree.nodeName)) |
|
1425 |
first = {} |
|
1426 |
for node in tree.childNodes: |
|
1427 |
name = node.nodeName |
|
601
32c0f4a626db
Adding support for loading #text node in formattedText
laurent
parents:
594
diff
changeset
|
1428 |
if name == "#text" and node.data.strip() == "" or name == "#comment": |
565 | 1429 |
continue |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1430 |
elif elements.has_key(name): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1431 |
elements[name]["elmt_type"] = FindTypeInfos(factory, elements[name]["elmt_type"]) |
565 | 1432 |
if elements[name]["maxOccurs"] == "unbounded" or elements[name]["maxOccurs"] > 1: |
1433 |
if first.get(name, True): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1434 |
object.__setattr__(self, name, [elements[name]["elmt_type"]["extract"](node)]) |
565 | 1435 |
first[name] = False |
1436 |
else: |
|
1437 |
getattr(self, name).append(elements[name]["elmt_type"]["extract"](node)) |
|
1438 |
else: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1439 |
object.__setattr__(self, name, elements[name]["elmt_type"]["extract"](node)) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1440 |
elif elements.has_key("text"): |
565 | 1441 |
if elements["text"]["maxOccurs"] == "unbounded" or elements["text"]["maxOccurs"] > 1: |
1442 |
if first.get("text", True): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1443 |
object.__setattr__(self, "text", [elements["text"]["elmt_type"]["extract"](node)]) |
565 | 1444 |
first["text"] = False |
1445 |
else: |
|
1446 |
getattr(self, "text").append(elements["text"]["elmt_type"]["extract"](node)) |
|
1447 |
else: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1448 |
object.__setattr__(self, "text", elements["text"]["elmt_type"]["extract"](node)) |
565 | 1449 |
elif elements.has_key("content"): |
601
32c0f4a626db
Adding support for loading #text node in formattedText
laurent
parents:
594
diff
changeset
|
1450 |
if name in ["#cdata-section", "#text"]: |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1451 |
if elements["content"]["elmt_type"]["type"] == SIMPLETYPE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1452 |
object.__setattr__(self, "content", elements["content"]["elmt_type"]["extract"](node.data, False)) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1453 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1454 |
content = getattr(self, "content") |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1455 |
if elements["content"]["maxOccurs"] == "unbounded" or elements["content"]["maxOccurs"] > 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1456 |
if first.get("content", True): |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1457 |
object.__setattr__(self, "content", [elements["content"]["elmt_type"]["extract"](node, None)]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1458 |
first["content"] = False |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1459 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1460 |
content.append(elements["content"]["elmt_type"]["extract"](node, content)) |
565 | 1461 |
else: |
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1462 |
object.__setattr__(self, "content", elements["content"]["elmt_type"]["extract"](node, content)) |
565 | 1463 |
return loadXMLTreeMethod |
1464 |
||
1465 |
||
1466 |
""" |
|
1467 |
Method that generates the method for generating an xml text by following the |
|
1468 |
attributes list defined |
|
1469 |
""" |
|
1470 |
def generateGenerateXMLText(factory, classinfos): |
|
1471 |
def generateXMLTextMethod(self, name, indent=0, extras={}, derived=False): |
|
1472 |
ind1, ind2 = getIndent(indent, name) |
|
1473 |
if not derived: |
|
1474 |
text = ind1 + u'<%s' % name |
|
1475 |
else: |
|
1476 |
text = u'' |
|
1477 |
||
1478 |
first = True |
|
1479 |
if not classinfos.has_key("base"): |
|
1480 |
for attr, value in extras.items(): |
|
1481 |
if not first and not self.singleLineAttributes: |
|
1482 |
text += u'\n%s' % (ind2) |
|
1483 |
text += u' %s=%s' % (attr, quoteattr(value)) |
|
1484 |
first = False |
|
1485 |
extras.clear() |
|
1486 |
for attr in classinfos["attributes"]: |
|
1487 |
if attr["use"] != "prohibited": |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1488 |
attr["attr_type"] = FindTypeInfos(factory, attr["attr_type"]) |
565 | 1489 |
value = getattr(self, attr["name"], None) |
1490 |
if value != None: |
|
1491 |
computed_value = attr["attr_type"]["generate"](value) |
|
1492 |
else: |
|
1493 |
computed_value = None |
|
1494 |
if attr["use"] != "optional" or (value != None and \ |
|
1495 |
computed_value != attr.get("default", attr["attr_type"]["generate"](attr["attr_type"]["initial"]()))): |
|
1496 |
if classinfos.has_key("base"): |
|
1497 |
extras[attr["name"]] = computed_value |
|
1498 |
else: |
|
1499 |
if not first and not self.singleLineAttributes: |
|
1500 |
text += u'\n%s' % (ind2) |
|
1501 |
text += ' %s=%s' % (attr["name"], quoteattr(computed_value)) |
|
1502 |
first = False |
|
1503 |
if classinfos.has_key("base"): |
|
1504 |
first, new_text = classinfos["base"].generateXMLText(self, name, indent, extras, True) |
|
1505 |
text += new_text |
|
1506 |
else: |
|
1507 |
first = True |
|
1508 |
for element in classinfos["elements"]: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1509 |
element["elmt_type"] = FindTypeInfos(factory, element["elmt_type"]) |
565 | 1510 |
value = getattr(self, element["name"], None) |
1511 |
if element["minOccurs"] == 0 and element["maxOccurs"] == 1: |
|
1512 |
if value is not None: |
|
1513 |
if first: |
|
1514 |
text += u'>\n' |
|
1515 |
first = False |
|
1516 |
text += element["elmt_type"]["generate"](value, element["name"], indent + 1) |
|
1517 |
elif element["minOccurs"] == 1 and element["maxOccurs"] == 1: |
|
1518 |
if first: |
|
1519 |
text += u'>\n' |
|
1520 |
first = False |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1521 |
if element["name"] == "content" and element["elmt_type"]["type"] == SIMPLETYPE: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1522 |
text += element["elmt_type"]["generate"](value) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1523 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1524 |
text += element["elmt_type"]["generate"](value, element["name"], indent + 1) |
565 | 1525 |
else: |
1526 |
if first and len(value) > 0: |
|
1527 |
text += u'>\n' |
|
1528 |
first = False |
|
1529 |
for item in value: |
|
1530 |
text += element["elmt_type"]["generate"](item, element["name"], indent + 1) |
|
1531 |
if not derived: |
|
1532 |
if first: |
|
1533 |
text += u'/>\n' |
|
1534 |
else: |
|
1535 |
text += ind1 + u'</%s>\n' % (name) |
|
1536 |
return text |
|
1537 |
else: |
|
1538 |
return first, text |
|
1539 |
return generateXMLTextMethod |
|
1540 |
||
1541 |
def gettypeinfos(name, facets): |
|
1542 |
if facets.has_key("enumeration") and facets["enumeration"][0] is not None: |
|
1543 |
return facets["enumeration"][0] |
|
1544 |
elif facets.has_key("maxInclusive"): |
|
1545 |
limits = {"max" : None, "min" : None} |
|
1546 |
if facets["maxInclusive"][0] is not None: |
|
1547 |
limits["max"] = facets["maxInclusive"][0] |
|
1548 |
elif facets["maxExclusive"][0] is not None: |
|
1549 |
limits["max"] = facets["maxExclusive"][0] - 1 |
|
1550 |
if facets["minInclusive"][0] is not None: |
|
1551 |
limits["min"] = facets["minInclusive"][0] |
|
1552 |
elif facets["minExclusive"][0] is not None: |
|
1553 |
limits["min"] = facets["minExclusive"][0] + 1 |
|
1554 |
if limits["max"] is not None or limits["min"] is not None: |
|
1555 |
return limits |
|
1556 |
return name |
|
1557 |
||
1558 |
def generateGetElementAttributes(factory, classinfos): |
|
1559 |
def getElementAttributes(self): |
|
1560 |
attr_list = [] |
|
1561 |
if classinfos.has_key("base"): |
|
1562 |
attr_list.extend(classinfos["base"].getElementAttributes(self)) |
|
1563 |
for attr in classinfos["attributes"]: |
|
1564 |
if attr["use"] != "prohibited": |
|
1565 |
attr_params = {"name" : attr["name"], "use" : attr["use"], |
|
1566 |
"type" : gettypeinfos(attr["attr_type"]["basename"], attr["attr_type"]["facets"]), |
|
1567 |
"value" : getattr(self, attr["name"], "")} |
|
1568 |
attr_list.append(attr_params) |
|
1569 |
return attr_list |
|
1570 |
return getElementAttributes |
|
1571 |
||
1572 |
def generateGetElementInfos(factory, classinfos): |
|
1573 |
attributes = dict([(attr["name"], attr) for attr in classinfos["attributes"] if attr["use"] != "prohibited"]) |
|
1574 |
elements = dict([(element["name"], element) for element in classinfos["elements"]]) |
|
1575 |
||
1576 |
def getElementInfos(self, name, path=None, derived=False): |
|
1577 |
attr_type = "element" |
|
1578 |
value = None |
|
1579 |
use = "required" |
|
1580 |
children = [] |
|
1581 |
if path is not None: |
|
1582 |
parts = path.split(".", 1) |
|
1583 |
if attributes.has_key(parts[0]): |
|
1584 |
if len(parts) != 0: |
|
1585 |
raise ValueError("Wrong path!") |
|
1586 |
attr_type = gettypeinfos(attributes[parts[0]]["attr_type"]["basename"], |
|
1587 |
attributes[parts[0]]["attr_type"]["facets"]) |
|
1588 |
value = getattr(self, parts[0], "") |
|
1589 |
elif elements.has_key(parts[0]): |
|
1590 |
if elements[parts[0]]["elmt_type"]["type"] == SIMPLETYPE: |
|
1591 |
if len(parts) != 0: |
|
1592 |
raise ValueError("Wrong path!") |
|
1593 |
attr_type = gettypeinfos(elements[parts[0]]["elmt_type"]["basename"], |
|
1594 |
elements[parts[0]]["elmt_type"]["facets"]) |
|
1595 |
value = getattr(self, parts[0], "") |
|
1596 |
elif parts[0] == "content": |
|
1597 |
return self.content["value"].getElementInfos(self.content["name"], path) |
|
1598 |
else: |
|
1599 |
attr = getattr(self, parts[0], None) |
|
1600 |
if attr is None: |
|
1601 |
raise ValueError("Wrong path!") |
|
1602 |
if len(parts) == 1: |
|
1603 |
return attr.getElementInfos(parts[0]) |
|
1604 |
else: |
|
1605 |
return attr.getElementInfos(parts[0], parts[1]) |
|
1606 |
else: |
|
1607 |
raise ValueError("Wrong path!") |
|
1608 |
else: |
|
1609 |
if not derived: |
|
1610 |
children.extend(self.getElementAttributes()) |
|
1611 |
if classinfos.has_key("base"): |
|
1612 |
children.extend(classinfos["base"].getElementInfos(self, name, derived=True)["children"]) |
|
1613 |
for element_name, element in elements.items(): |
|
1614 |
if element["minOccurs"] == 0: |
|
1615 |
use = "optional" |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1616 |
if element_name == "content" and element["type"] == CHOICE: |
565 | 1617 |
attr_type = [(choice["name"], None) for choice in element["choices"]] |
1618 |
if self.content is None: |
|
1619 |
value = "" |
|
1620 |
else: |
|
1621 |
value = self.content["name"] |
|
1622 |
if self.content["value"] is not None: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1623 |
if self.content["name"] == "sequence": |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1624 |
choices_dict = dict([(choice["name"], choice) for choice in element["choices"]]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1625 |
sequence_infos = choices_dict.get("sequence", None) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1626 |
if sequence_infos is not None: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1627 |
children.extend([item.getElementInfos(infos["name"]) for item, infos in zip(self.content["value"], sequence_infos["elements"])]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1628 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1629 |
children.extend(self.content["value"].getElementInfos(self.content["name"])["children"]) |
565 | 1630 |
elif element["elmt_type"]["type"] == SIMPLETYPE: |
1631 |
children.append({"name": element_name, "require": element["minOccurs"] != 0, |
|
1632 |
"type": gettypeinfos(element["elmt_type"]["basename"], |
|
1633 |
element["elmt_type"]["facets"]), |
|
1634 |
"value": getattr(self, element_name, None)}) |
|
1635 |
else: |
|
1636 |
instance = getattr(self, element_name, None) |
|
1637 |
if instance is None: |
|
1638 |
instance = element["elmt_type"]["initial"]() |
|
1639 |
children.append(instance.getElementInfos(element_name)) |
|
1640 |
return {"name": name, "type": attr_type, "value": value, "use": use, "children": children} |
|
1641 |
return getElementInfos |
|
1642 |
||
1643 |
def generateSetElementValue(factory, classinfos): |
|
1644 |
attributes = dict([(attr["name"], attr) for attr in classinfos["attributes"] if attr["use"] != "prohibited"]) |
|
1645 |
elements = dict([(element["name"], element) for element in classinfos["elements"]]) |
|
1646 |
||
1647 |
def setElementValue(self, path, value): |
|
1648 |
if path is not None: |
|
1649 |
parts = path.split(".", 1) |
|
1650 |
if attributes.has_key(parts[0]): |
|
1651 |
if len(parts) != 1: |
|
1652 |
raise ValueError("Wrong path!") |
|
1653 |
if attributes[parts[0]]["attr_type"]["basename"] == "boolean": |
|
1654 |
setattr(self, parts[0], value) |
|
1655 |
else: |
|
1656 |
setattr(self, parts[0], attributes[parts[0]]["attr_type"]["extract"](value, False)) |
|
1657 |
elif elements.has_key(parts[0]): |
|
1658 |
if elements[parts[0]]["elmt_type"]["type"] == SIMPLETYPE: |
|
1659 |
if len(parts) != 1: |
|
1660 |
raise ValueError("Wrong path!") |
|
1661 |
if elements[parts[0]]["elmt_type"]["basename"] == "boolean": |
|
1662 |
setattr(self, parts[0], value) |
|
1663 |
else: |
|
1664 |
setattr(self, parts[0], elements[parts[0]]["elmt_type"]["extract"](value, False)) |
|
1665 |
else: |
|
1666 |
instance = getattr(self, parts[0], None) |
|
1667 |
if instance != None: |
|
1668 |
if len(parts) > 1: |
|
1669 |
instance.setElementValue(parts[1], value) |
|
1670 |
else: |
|
1671 |
instance.setElementValue(None, value) |
|
1672 |
elif elements.has_key("content"): |
|
1673 |
if len(parts) > 0: |
|
1674 |
self.content["value"].setElementValue(path, value) |
|
1675 |
elif classinfos.has_key("base"): |
|
1676 |
classinfos["base"].setElementValue(self, path, value) |
|
1677 |
elif elements.has_key("content"): |
|
1678 |
if value == "": |
|
1679 |
if elements["content"]["minOccurs"] == 0: |
|
1680 |
self.setcontent(None) |
|
1681 |
else: |
|
1682 |
raise ValueError("\"content\" element is required!") |
|
1683 |
else: |
|
1684 |
self.setcontentbytype(value) |
|
1685 |
return setElementValue |
|
1686 |
||
1687 |
""" |
|
1688 |
Methods that generates the different methods for setting and getting the attributes |
|
1689 |
""" |
|
1690 |
def generateInitMethod(factory, classinfos): |
|
1691 |
def initMethod(self): |
|
1692 |
if classinfos.has_key("base"): |
|
1693 |
classinfos["base"].__init__(self) |
|
1694 |
for attribute in classinfos["attributes"]: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1695 |
attribute["attr_type"] = FindTypeInfos(factory, attribute["attr_type"]) |
565 | 1696 |
if attribute["use"] == "required": |
1697 |
setattr(self, attribute["name"], attribute["attr_type"]["initial"]()) |
|
1698 |
elif attribute["use"] == "optional": |
|
1699 |
if attribute.has_key("default"): |
|
1700 |
setattr(self, attribute["name"], attribute["attr_type"]["extract"](attribute["default"], False)) |
|
1701 |
else: |
|
1702 |
setattr(self, attribute["name"], None) |
|
1703 |
for element in classinfos["elements"]: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1704 |
setattr(self, element["name"], GetElementInitialValue(factory, element)) |
565 | 1705 |
return initMethod |
1706 |
||
1707 |
def generateSetMethod(attr): |
|
1708 |
def setMethod(self, value): |
|
1709 |
setattr(self, attr, value) |
|
1710 |
return setMethod |
|
1711 |
||
1712 |
def generateGetMethod(attr): |
|
1713 |
def getMethod(self): |
|
1714 |
return getattr(self, attr, None) |
|
1715 |
return getMethod |
|
1716 |
||
1717 |
def generateAddMethod(attr, factory, infos): |
|
1718 |
def addMethod(self): |
|
1719 |
if infos["type"] == ATTRIBUTE: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1720 |
infos["attr_type"] = FindTypeInfos(factory, infos["attr_type"]) |
565 | 1721 |
initial = infos["attr_type"]["initial"] |
1722 |
extract = infos["attr_type"]["extract"] |
|
1723 |
elif infos["type"] == ELEMENT: |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1724 |
infos["elmt_type"] = FindTypeInfos(factory, infos["elmt_type"]) |
565 | 1725 |
initial = infos["elmt_type"]["initial"] |
1726 |
extract = infos["elmt_type"]["extract"] |
|
1727 |
else: |
|
1728 |
raise ValueError("Invalid class attribute!") |
|
1729 |
if infos.has_key("default"): |
|
1730 |
setattr(self, attr, extract(infos["default"], False)) |
|
1731 |
else: |
|
1732 |
setattr(self, attr, initial()) |
|
1733 |
return addMethod |
|
1734 |
||
1735 |
def generateDeleteMethod(attr): |
|
1736 |
def deleteMethod(self): |
|
1737 |
setattr(self, attr, None) |
|
1738 |
return deleteMethod |
|
1739 |
||
1740 |
def generateAppendMethod(attr, maxOccurs, factory, infos): |
|
1741 |
def appendMethod(self, value): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1742 |
infos["elmt_type"] = FindTypeInfos(factory, infos["elmt_type"]) |
565 | 1743 |
attr_list = getattr(self, attr) |
1744 |
if maxOccurs == "unbounded" or len(attr_list) < maxOccurs: |
|
1745 |
if infos["elmt_type"]["check"](value): |
|
1746 |
attr_list.append(value) |
|
1747 |
else: |
|
1748 |
raise ValueError("\"%s\" value isn't valid!" % attr) |
|
1749 |
else: |
|
1750 |
raise ValueError("There can't be more than %d values in \"%s\"!" % (maxOccurs, attr)) |
|
1751 |
return appendMethod |
|
1752 |
||
1753 |
def generateInsertMethod(attr, maxOccurs, factory, infos): |
|
1754 |
def insertMethod(self, index, value): |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1755 |
infos["elmt_type"] = FindTypeInfos(factory, infos["elmt_type"]) |
565 | 1756 |
attr_list = getattr(self, attr) |
1757 |
if maxOccurs == "unbounded" or len(attr_list) < maxOccurs: |
|
1758 |
if infos["elmt_type"]["check"](value): |
|
1759 |
attr_list.insert(index, value) |
|
1760 |
else: |
|
1761 |
raise ValueError("\"%s\" value isn't valid!" % attr) |
|
1762 |
else: |
|
1763 |
raise ValueError("There can't be more than %d values in \"%s\"!" % (maxOccurs, attr)) |
|
1764 |
return insertMethod |
|
1765 |
||
1766 |
def generateGetChoicesMethod(choice_types): |
|
1767 |
def getChoicesMethod(self): |
|
1768 |
return [choice["name"] for choice in choice_types] |
|
1769 |
return getChoicesMethod |
|
1770 |
||
1771 |
def generateSetChoiceByTypeMethod(factory, choice_types): |
|
1772 |
choices = dict([(choice["name"], choice) for choice in choice_types]) |
|
1773 |
def setChoiceMethod(self, type): |
|
1774 |
if not choices.has_key(type): |
|
1775 |
raise ValueError("Unknown \"%s\" choice type for \"content\"!" % type) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1776 |
choices[type]["elmt_type"] = FindTypeInfos(factory, choices[type]["elmt_type"]) |
565 | 1777 |
new_element = choices[type]["elmt_type"]["initial"]() |
1778 |
self.content = {"name": type, "value": new_element} |
|
1779 |
return new_element |
|
1780 |
return setChoiceMethod |
|
1781 |
||
1782 |
def generateAppendChoiceByTypeMethod(maxOccurs, factory, choice_types): |
|
1783 |
choices = dict([(choice["name"], choice) for choice in choice_types]) |
|
1784 |
def appendChoiceMethod(self, type): |
|
1785 |
if not choices.has_key(type): |
|
1786 |
raise ValueError("Unknown \"%s\" choice type for \"content\"!" % type) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1787 |
choices[type]["elmt_type"] = FindTypeInfos(factory, choices[type]["elmt_type"]) |
565 | 1788 |
if maxOccurs == "unbounded" or len(self.content) < maxOccurs: |
1789 |
new_element = choices[type]["elmt_type"]["initial"]() |
|
1790 |
self.content.append({"name": type, "value": new_element}) |
|
1791 |
return new_element |
|
1792 |
else: |
|
1793 |
raise ValueError("There can't be more than %d values in \"content\"!" % maxOccurs) |
|
1794 |
return appendChoiceMethod |
|
1795 |
||
1796 |
def generateInsertChoiceByTypeMethod(maxOccurs, factory, choice_types): |
|
1797 |
choices = dict([(choice["name"], choice) for choice in choice_types]) |
|
1798 |
def insertChoiceMethod(self, index, type): |
|
1799 |
if not choices.has_key(type): |
|
1800 |
raise ValueError("Unknown \"%s\" choice type for \"content\"!" % type) |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1801 |
choices[type]["elmt_type"] = FindTypeInfos(factory, choices[type]["elmt_type"]) |
565 | 1802 |
if maxOccurs == "unbounded" or len(self.content) < maxOccurs: |
1803 |
new_element = choices[type]["elmt_type"]["initial"]() |
|
1804 |
self.content.insert(index, {"name" : type, "value" : new_element}) |
|
1805 |
return new_element |
|
1806 |
else: |
|
1807 |
raise ValueError("There can't be more than %d values in \"content\"!" % maxOccurs) |
|
1808 |
return insertChoiceMethod |
|
1809 |
||
1810 |
def generateRemoveMethod(attr, minOccurs): |
|
1811 |
def removeMethod(self, index): |
|
1812 |
attr_list = getattr(self, attr) |
|
1813 |
if len(attr_list) > minOccurs: |
|
1814 |
getattr(self, attr).pop(index) |
|
1815 |
else: |
|
1816 |
raise ValueError("There can't be less than %d values in \"%s\"!" % (minOccurs, attr)) |
|
1817 |
return removeMethod |
|
1818 |
||
1819 |
def generateCountMethod(attr): |
|
1820 |
def countMethod(self): |
|
1821 |
return len(getattr(self, attr)) |
|
1822 |
return countMethod |
|
1823 |
||
1824 |
""" |
|
1825 |
This function generate the classes from a class factory |
|
1826 |
""" |
|
1827 |
def GenerateClasses(factory, declare=False): |
|
1828 |
ComputedClasses = factory.CreateClasses() |
|
1829 |
#factory.PrintClasses() |
|
1830 |
if declare: |
|
1831 |
for ClassName, Class in pluginClasses.items(): |
|
1832 |
sys._getframe(1).f_locals[ClassName] = Class |
|
1833 |
for TypeName, Type in pluginTypes.items(): |
|
1834 |
sys._getframe(1).f_locals[TypeName] = Type |
|
592
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1835 |
if factory.FileName is not None and len(ComputedClasses) == 1: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1836 |
globals().update(ComputedClasses[factory.FileName]) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1837 |
return ComputedClasses[factory.FileName] |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1838 |
else: |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1839 |
globals().update(ComputedClasses) |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1840 |
return ComputedClasses |
89ff2738ef20
Adding support in xmlclass for handling some not yet supported XML syntaxes
laurent
parents:
565
diff
changeset
|
1841 |