6 from aestate.exception import NotFindTemplateError, TagAttributeError, TagHandlerError
17 def __init__(self, target_obj, params, aestate_xml_cls, root, value, XML_KEY, XML_IGNORE_NODES):
27 def apply(self, *args, **kwargs):
31 for root_index, root_value
in enumerate(node.childNodes):
32 if root_value.nodeName
in self.
XML_KEY.keys():
35 texts = obj.apply(texts=texts)
38 texts.add(node=root_value, index=root_index)
39 except Exception
as e:
42 obj=e, LogObject=self.
target_obj.log_obj, raise_exception=
True)
45 except Exception
as e:
48 obj=e, LogObject=self.
target_obj.log_obj, raise_exception=
True)
54 def apply(self, *args, **kwargs):
56 texts = kwargs[
'texts']
59 resultType = axc_node.attrs[
'resultType']
60 texts.mark[
'resultType'] = resultType.text
69 def apply(self, *args, **kwargs):
71 texts = kwargs[
'texts']
74 has_last_id = axc_node.attrs[
'last']
if 'last' in axc_node.attrs.keys()
else self.
TempTextNode(
'True')
75 texts.mark[
'has_last_id'] = has_last_id.text ==
'True'
81 def apply(self, *args, **kwargs):
82 texts = kwargs[
'texts']
84 if 'test' not in axc_node.attrs.keys():
86 msg=f
'The attribute`test` in the if tag is missing a required structure',
87 obj=TagAttributeError, LogObject=self.
target_obj.log_obj, raise_exception=
True)
89 test_syntax = axc_node.attrs[
'test']
90 syntax_re_text = re.findall(
'(.*?)([>=|<=|==|<|>]+)(.*)', test_syntax.text)
91 if len(syntax_re_text) == 0:
94 msg=f
'The attribute`test` in the if tag is missing a required structure',
95 obj=TagAttributeError, LogObject=self.
target_obj.log_obj, raise_exception=
True)
97 syntax_using = [x
for x
in syntax_re_text[0]
if x !=
'']
98 if len(syntax_using) == 2
or len(syntax_using) > 3:
100 msg=f
'The node rule parsing failed and did not conform to the grammatical structure.{syntax_using}',
101 obj=TagHandlerError, LogObject=self.
target_obj.log_obj, raise_exception=
True)
103 initial_field = syntax_using[0]
104 symbol = syntax_using[1]
105 value = syntax_using[2]
107 rfield = re.findall(
'#{(.*?)}', initial_field)
109 field = rfield[0]
if len(rfield) > 0
and rfield[0]
in self.
params.keys()
else initial_field
111 ih =
IfHandler(initial_field=initial_field, field=field, params=self.
params, value=value, symbol=symbol)
118 if ih.checking_mark(self.
node):
120 texts.mark[
'if_next'] =
not success
128 texts = kwargs[
'texts']
129 if 'if_next' not in texts.mark.keys():
131 msg=
'Cannot find the if tag in front of the else tag',
132 obj=TagHandlerError, LogObject=self.
target_obj.log_obj, raise_exception=
True)
134 if_next = texts.mark[
'if_next']
136 texts.mark.pop(
'if_next')
139 texts.mark.pop(
'if_next')
146 texts = kwargs[
'texts']
148 field_name = axc_node.attrs[
'field'].text
150 value = self.
params[field_name]
151 except KeyError
as ke:
153 msg=f
'The parameter named `{field_name}` does not exist in the called method',
154 obj=TagHandlerError, LogObject=self.
target_obj.log_obj, raise_exception=
True)
155 case_nodes = axc_node.children[
'case']
157 for cn
in case_nodes:
158 if cn.attrs[
'value'].text == value:
161 if check_node
is None:
162 check_node = axc_node.children[
'default'][0].node
163 texts = self.
parseNode(texts, check_node)
171 texts = kwargs[
'texts']
173 from_node_name = axc_node.attrs[
'from'].text
174 templates = self.
target_obj.xNode.children[
'template']
175 target_template =
None
177 if t.attrs[
'id'].text == from_node_name:
179 if target_template
is None:
181 msg=f
'The template named `{from_node_name}` could not be found from the node',
182 obj=NotFindTemplateError, LogObject=self.
target_obj.log_obj, raise_exception=
True)
183 texts = self.
parseNode(texts, target_template.node)
190 t = structure[
'_type'].split(
'.')
191 cls_name = t[len(t) - 1]
192 package_name =
'.'.join(t[:len(t) - 1])
193 package = importlib.import_module(package_name)
194 _type = getattr(package, cls_name)
200 if not isinstance(data, list):
202 for _data_item
in data:
203 obj = ResultABC.get_type(structure)()
204 for field, properties
in structure.items():
206 if isinstance(properties, dict):
207 setattr(obj, field, ResultABC.generate(_data_item, properties))
209 setattr(obj, properties, _data_item[field])
222 resultMapTags = self.
target_obj.xNode.children[
'resultMap']
224 for i
in resultMapTags:
225 if i.attrs[
'id'].text == self.
node.mark[
'resultType']:
229 if resultNode
is None:
231 msg=
"Can't find resultMap template",
232 obj=NotFindTemplateError, LogObject=self.
target_obj.log_obj, raise_exception=
True)
233 structure = ForeignNode.apply(resultNode)
234 return ResultABC.generate(self.
data, structure)
240 structure = {
'_type': resultNode.attrs[
'type'].text}
241 if 'result' in resultNode.children.keys():
242 for i
in resultNode.children[
'result']:
243 structure[i.attrs[
'field'].text] = i.attrs[
'properties'].text
245 if 'foreign' in resultNode.children.keys():
246 for i
in resultNode.children[
'foreign']:
247 structure[i.attrs[
'name'].text] = ForeignNode.apply(i)