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