comparison configmix/config.py @ 325:ab33d51f3412

By default quote the "#" character also because it is typically a comment in all the configuration file formats. Test quoting the "#" also
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 06 May 2021 20:55:43 +0200
parents 4aa19e04ff65
children b7abfbfe806d
comparison
equal deleted inserted replaced
324:87424f4754d1 325:ab33d51f3412
69 _FILTER_SEPARATOR = u(b'|') 69 _FILTER_SEPARATOR = u(b'|')
70 _STARTTOK_REF = _STARTTOK + REF_NAMESPACE + _NS_SEPARATOR 70 _STARTTOK_REF = _STARTTOK + REF_NAMESPACE + _NS_SEPARATOR
71 _ENDTOK_REF = _ENDTOK 71 _ENDTOK_REF = _ENDTOK
72 _DOT = u(b'.') 72 _DOT = u(b'.')
73 _QUOTE = u(b'%') 73 _QUOTE = u(b'%')
74 _COMMENT = u(b'#')
74 75
75 def getvarl(self, *names, **kwds): 76 def getvarl(self, *names, **kwds):
76 """Get a variable where the hierarchy is given in `names` as sequence 77 """Get a variable where the hierarchy is given in `names` as sequence
77 and the namespace is given in `namespace`. 78 and the namespace is given in `namespace`.
78 79
372 value = filterfn(self, value) 373 value = filterfn(self, value)
373 return value 374 return value
374 375
375 @classmethod 376 @classmethod
376 def quote(klass, s): 377 def quote(klass, s):
377 """Quote a key to protect all dangerous chars: ``%``, ``.``, ``:`` 378 """Quote a key to protect all dangerous chars: ``%``, ``.``, ``:``,
378 and ``|`` 379 ``#`` and ``|``
379 380
380 """ 381 """
381 qc = klass._QUOTE 382 qc = klass._QUOTE
382 s = s.replace(qc, qc + "x25") 383 s = s.replace(qc, qc + "x25")
383 s = s.replace(klass._DOT, qc + "x2e") 384 s = s.replace(klass._DOT, qc + "x2e")
384 s = s.replace(klass._NS_SEPARATOR, qc + "x3a") 385 s = s.replace(klass._NS_SEPARATOR, qc + "x3a")
386 s = s.replace(klass._COMMENT, qc + "x23")
385 return s.replace(klass._FILTER_SEPARATOR, qc + "x7c") 387 return s.replace(klass._FILTER_SEPARATOR, qc + "x7c")
386 388
387 @classmethod 389 @classmethod
388 def unquote(klass, s): 390 def unquote(klass, s):
389 """Unquote the content of `s`: handle all patterns ``%xXX``, 391 """Unquote the content of `s`: handle all patterns ``%xXX``,