[REF]Yaltik DSL : XML Base better xmln
This commit is contained in:
parent
cfb99c113d
commit
742d395427
@ -40,6 +40,7 @@ def xmlroot(tree: Dict[str, Any]) -> ET.Element:
|
|||||||
(rootel, tree['children']) |*> xmlchild
|
(rootel, tree['children']) |*> xmlchild
|
||||||
return rootel
|
return rootel
|
||||||
|
|
||||||
|
# TODO: addpattern here
|
||||||
def xmlchild(parent: ET.Element, children: XMLDictElement) -> None:
|
def xmlchild(parent: ET.Element, children: XMLDictElement) -> None:
|
||||||
""" Handling of children (ie non root) XML Nodes with/o text and
|
""" Handling of children (ie non root) XML Nodes with/o text and
|
||||||
subchildren (recursive) """
|
subchildren (recursive) """
|
||||||
@ -62,13 +63,12 @@ def xmln(tag: XMLText = '',
|
|||||||
attrs: XMLAttrs = {},
|
attrs: XMLAttrs = {},
|
||||||
children: Union[str, List] = []) -> XMLDictElement:
|
children: Union[str, List] = []) -> XMLDictElement:
|
||||||
""" XMLNode with default children, not attributes """
|
""" XMLNode with default children, not attributes """
|
||||||
|
xmldictel = XMLDictElement$ <*| (tag, attrs)
|
||||||
case children:
|
case children:
|
||||||
match c is str:
|
match c is str:
|
||||||
return XMLDictElement(tag=tag, attrs=attrs, children=[c])
|
return [c] |> xmldictel
|
||||||
# return {'tag': tag, 'attrs': attrs, 'children': [c]}
|
|
||||||
match c is list:
|
match c is list:
|
||||||
return XMLDictElement(tag=tag, attrs=attrs, children=c)
|
return c |> xmldictel
|
||||||
# return {'tag': tag, 'attrs': attrs, 'children': c}
|
|
||||||
else:
|
else:
|
||||||
raise TypeError('Invalid arguments for xmln')
|
raise TypeError('Invalid arguments for xmln')
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# __coconut_hash__ = 0x65805ba7
|
# __coconut_hash__ = 0xf1882627
|
||||||
|
|
||||||
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]
|
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]
|
||||||
|
|
||||||
@ -75,6 +75,7 @@ def xmlroot(tree # type: Dict[str, Any]
|
|||||||
(xmlchild)(*(rootel, tree['children']))
|
(xmlchild)(*(rootel, tree['children']))
|
||||||
return rootel
|
return rootel
|
||||||
|
|
||||||
|
# TODO: addpattern here
|
||||||
def xmlchild(parent, # type: ET.Element
|
def xmlchild(parent, # type: ET.Element
|
||||||
children # type: XMLDictElement
|
children # type: XMLDictElement
|
||||||
):
|
):
|
||||||
@ -111,21 +112,20 @@ def xmln(tag='', # type: XMLText
|
|||||||
):
|
):
|
||||||
# type: (...) -> XMLDictElement
|
# type: (...) -> XMLDictElement
|
||||||
""" XMLNode with default children, not attributes """
|
""" XMLNode with default children, not attributes """
|
||||||
|
xmldictel = (_coconut.functools.partial(_coconut.functools.partial, XMLDictElement))(*(tag, attrs))
|
||||||
_coconut_match_to = children
|
_coconut_match_to = children
|
||||||
_coconut_case_check_1 = False
|
_coconut_case_check_1 = False
|
||||||
if _coconut.isinstance(_coconut_match_to, str):
|
if _coconut.isinstance(_coconut_match_to, str):
|
||||||
c = _coconut_match_to
|
c = _coconut_match_to
|
||||||
_coconut_case_check_1 = True
|
_coconut_case_check_1 = True
|
||||||
if _coconut_case_check_1:
|
if _coconut_case_check_1:
|
||||||
return XMLDictElement(tag=tag, attrs=attrs, children=[c])
|
return (xmldictel)([c])
|
||||||
# return {'tag': tag, 'attrs': attrs, 'children': [c]}
|
|
||||||
if not _coconut_case_check_1:
|
if not _coconut_case_check_1:
|
||||||
if _coconut.isinstance(_coconut_match_to, list):
|
if _coconut.isinstance(_coconut_match_to, list):
|
||||||
c = _coconut_match_to
|
c = _coconut_match_to
|
||||||
_coconut_case_check_1 = True
|
_coconut_case_check_1 = True
|
||||||
if _coconut_case_check_1:
|
if _coconut_case_check_1:
|
||||||
return XMLDictElement(tag=tag, attrs=attrs, children=c)
|
return (xmldictel)(c)
|
||||||
# return {'tag': tag, 'attrs': attrs, 'children': c}
|
|
||||||
if not _coconut_case_check_1:
|
if not _coconut_case_check_1:
|
||||||
raise TypeError('Invalid arguments for xmln')
|
raise TypeError('Invalid arguments for xmln')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user