better quote support

This commit is contained in:
2021-01-25 17:30:03 +01:00
parent 001a3131d5
commit 0b8a6e399a
243 changed files with 1868 additions and 1525 deletions

View File

@ -1,6 +1,8 @@
"""loader
flattened XML specific
"""
from json import dumps
from .config import Config
from .annotator import CONVERT_OPTION
from .objspace import RootRougailObject
@ -173,14 +175,14 @@ class Common:
def convert_str(value):
"""convert string
"""
return "'" + value.replace("'", "\\\'") + "'"
return dumps(value, ensure_ascii=False)
def properties_to_string(self,
values: list,
) -> None:
"""Change properties to string
"""
properties = [f"'{property_}'" for property_ in values if isinstance(property_, str)]
properties = [self.convert_str(property_) for property_ in values if isinstance(property_, str)]
calc_properties = [self.calc_properties(property_) for property_ in values \
if isinstance(property_, self.objectspace.property_)]
return 'frozenset({' + ', '.join(sorted(properties) + calc_properties) + '})'
@ -238,6 +240,7 @@ class Variable(Common):
if hasattr(self.elt, key) and getattr(self.elt, key) is not None:
value = getattr(self.elt, key)
if isinstance(value, str):
print('pouet')
value = self.convert_str(value)
elif isinstance(value, self.objectspace.value):
value = self.calculation_value(value, [])