[FIX]Yaltik DSL fix xmln with only children

This commit is contained in:
Fabien BOURGEOIS 2020-05-01 18:58:34 +02:00
parent 4938cec43d
commit 0c037815b9
9 changed files with 43 additions and 22 deletions

View File

@ -628,11 +628,6 @@ def addpattern(base_func, **kwargs):
raise _coconut.TypeError("addpattern() got unexpected keyword arguments " + _coconut.repr(kwargs))
return _coconut.functools.partial(_coconut_base_pattern_func, base_func)
_coconut_addpattern = addpattern
def prepattern(base_func, **kwargs):
"""DEPRECATED: Use addpattern instead."""
def pattern_prepender(func):
return addpattern(func, **kwargs)(base_func)
return pattern_prepender
class _coconut_partial(object):
__slots__ = ("func", "_argdict", "_arglen", "_stargs", "keywords")
if hasattr(_coconut.functools.partial, "__doc__"):
@ -714,9 +709,6 @@ def makedata(data_type, *args):
if _coconut.issubclass(data_type, _coconut.str):
return "".join(args)
return data_type(args)
def datamaker(data_type):
"""DEPRECATED: Use makedata instead."""
return _coconut.functools.partial(makedata, data_type)
def fmap(func, obj):
"""fmap(func, obj) creates a copy of obj with func applied to its contents.
Override by defining obj.__fmap__(func)."""

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# __coconut_hash__ = 0x4a7a90c3
# __coconut_hash__ = 0x73d2bb80
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]

View File

@ -19,7 +19,7 @@
'name': 'Yaltik Odoo DSL base module and fns',
'summary': 'Yaltik Odoo Domain Specific Language base module and functions',
'description': """ Yaltik Odoo Domain Specific Language base module and functions """,
'version': '10.0.0.3.0',
'version': '10.0.0.3.1',
'category': 'Yaltik',
'author': 'Fabien Bourgeois',
'license': 'AGPL-3',

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# __coconut_hash__ = 0x992b21a8
# __coconut_hash__ = 0xb0af9f53
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# __coconut_hash__ = 0xdf0c086d
# __coconut_hash__ = 0xb59e6156
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]

View File

@ -45,6 +45,15 @@ class TestXMLBase(unittest.TestCase):
with self.assertRaisesRegexp(TypeError, 'Invalid arguments'):
xmln <**| {'children': False}
# Ensure that only children after tags is managed
element = xmln <*| ('tag', {'something': 'inside'})
element.attrs `self.assertIsInstance` dict
element.children `self.assertIsInstance` list
element = xmln <*| ('tag', ['something', 'inside'])
element.attrs `self.assertIsInstance` dict
element.children `self.assertIsInstance` list
def test_xmlchild(self):
parent = {'tag': 'root', 'attrs': {}, 'children': []} |> xmlroot

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# __coconut_hash__ = 0xd35c4ffa
# __coconut_hash__ = 0x84c101a5
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]
@ -71,6 +71,15 @@ class TestXMLBase(unittest.TestCase):
with self.assertRaisesRegexp(TypeError, 'Invalid arguments'):
(xmln)(**{'children': False})
# Ensure that only children after tags is managed
element = (xmln)(*('tag', {'something': 'inside'}))
(self.assertIsInstance)(element.attrs, dict)
(self.assertIsInstance)(element.children, list)
element = (xmln)(*('tag', ['something', 'inside']))
(self.assertIsInstance)(element.attrs, dict)
(self.assertIsInstance)(element.children, list)
def test_xmlchild(self):
parent = (xmlroot)({'tag': 'root', 'attrs': {}, 'children': []})

View File

@ -59,6 +59,10 @@ def xmln(tag: Text = '',
attrs: XMLAttrs = {},
children: Union[Text, List] = []) -> XMLDictElement:
""" XMLDictElement building from dict object, with defaults """
case attrs:
match _ is list:
children = attrs
attrs = {}
xmldictel = XMLDictElement$ <*| (tag, attrs)
case children:
match c is Text:

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# __coconut_hash__ = 0x970fdbe8
# __coconut_hash__ = 0x178765c5
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]
@ -109,21 +109,28 @@ def xmln(tag='', # type: Text
):
# type: (...) -> XMLDictElement
""" XMLDictElement building from dict object, with defaults """
xmldictel = (_coconut.functools.partial(_coconut.functools.partial, XMLDictElement))(*(tag, attrs))
_coconut_match_to = children
_coconut_match_to = attrs
_coconut_case_check_1 = False
if _coconut.isinstance(_coconut_match_to, Text):
c = _coconut_match_to
if _coconut.isinstance(_coconut_match_to, list):
_coconut_case_check_1 = True
if _coconut_case_check_1:
children = attrs
attrs = {}
xmldictel = (_coconut.functools.partial(_coconut.functools.partial, XMLDictElement))(*(tag, attrs))
_coconut_match_to = children
_coconut_case_check_2 = False
if _coconut.isinstance(_coconut_match_to, Text):
c = _coconut_match_to
_coconut_case_check_2 = True
if _coconut_case_check_2:
return (xmldictel)([c])
if not _coconut_case_check_1:
if not _coconut_case_check_2:
if _coconut.isinstance(_coconut_match_to, list):
c = _coconut_match_to
_coconut_case_check_1 = True
if _coconut_case_check_1:
_coconut_case_check_2 = True
if _coconut_case_check_2:
return (xmldictel)(c)
if not _coconut_case_check_1:
if not _coconut_case_check_2:
raise TypeError('Invalid arguments for xmln')