comparison configmix/config.py @ 334:a04cd5dbcd2c

By default quote also the characters "{", "}", "[" and "]" because they are special in YAML
author Franz Glasner <f.glasner@feldmann-mg.com>
date Fri, 07 May 2021 10:35:21 +0200
parents 5ec0ae3bb8db
children 83f76a41cf7c
comparison
equal deleted inserted replaced
333:5ec0ae3bb8db 334:a04cd5dbcd2c
385 """Replace important special characters in string `s` by replacing 385 """Replace important special characters in string `s` by replacing
386 them with ``%xNN`` where `NN` are the two hexadecimal digits of the 386 them with ``%xNN`` where `NN` are the two hexadecimal digits of the
387 characters unicode codepoint value. 387 characters unicode codepoint value.
388 388
389 Handled are the important special chars: ``%``, ``.``, ``:``, 389 Handled are the important special chars: ``%``, ``.``, ``:``,
390 ``#``; ``'``, ``"`` and ``|``. 390 ``#``; ``'``, ``"``, ``|``, ``{``, ``}``, ``[`` and ``]``.
391 391
392 See also the :ref:`quoting` section. 392 See also the :ref:`quoting` section.
393 393
394 """ 394 """
395 qc = klass._QUOTE 395 qc = klass._QUOTE
397 s = s.replace(klass._DOT, qc + "x2e") 397 s = s.replace(klass._DOT, qc + "x2e")
398 s = s.replace(klass._NS_SEPARATOR, qc + "x3a") 398 s = s.replace(klass._NS_SEPARATOR, qc + "x3a")
399 s = s.replace(klass._COMMENT, qc + "x23") 399 s = s.replace(klass._COMMENT, qc + "x23")
400 s = s.replace(klass._FILTER_SEPARATOR, qc + "x7c") 400 s = s.replace(klass._FILTER_SEPARATOR, qc + "x7c")
401 s = s.replace('"', qc + "x22") 401 s = s.replace('"', qc + "x22")
402 return s.replace("'", qc + "x27") 402 s = s.replace("'", qc + "x27")
403 s = s.replace('{', qc + "x7b")
404 s = s.replace('}', qc + "x7d")
405 s = s.replace('[', qc + "x5b")
406 return s.replace(']', qc + "x5d")
403 407
404 @classmethod 408 @classmethod
405 def unquote(klass, s): 409 def unquote(klass, s):
406 """Unquote the content of `s`: handle all patterns ``%xNN``, 410 """Unquote the content of `s`: handle all patterns ``%xNN``,
407 ``%uNNNN`` or ``%UNNNNNNNN``. 411 ``%uNNNN`` or ``%UNNNNNNNN``.