Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 481:e3990ec55f2a
Use a quick-check for .quote() if no quoting is needed
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Fri, 17 Dec 2021 13:12:19 +0100 |
| parents | 3cfc808e613b |
| children | 8b8ffb74d452 |
comparison
equal
deleted
inserted
replaced
| 480:3cfc808e613b | 481:e3990ec55f2a |
|---|---|
| 235 _QUOTE = u(b'%') | 235 _QUOTE = u(b'%') |
| 236 _QUOTE_x = u(b'x') | 236 _QUOTE_x = u(b'x') |
| 237 _QUOTE_u = u(b'u') | 237 _QUOTE_u = u(b'u') |
| 238 _QUOTE_U = u(b'U') | 238 _QUOTE_U = u(b'U') |
| 239 _COMMENT = u(b'#') | 239 _COMMENT = u(b'#') |
| 240 _QUOTE_SAFE = u(b'abcdefghijklmnopqrstuvwxyz' | |
| 241 b'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
| 242 b'0123456789' | |
| 243 b'-_@!§$&/()=?*+~;,<>´`^') | |
| 244 """Mostly used configuration key characters that do not need any quoting | |
| 245 | |
| 246 """ | |
| 240 | 247 |
| 241 is_jail = False | 248 is_jail = False |
| 242 """Flag to show that this is not a jail for another configuration""" | 249 """Flag to show that this is not a jail for another configuration""" |
| 243 | 250 |
| 244 def __getitem__(self, key): | 251 def __getitem__(self, key): |
| 698 ``#``; ``'``, ``"``, ``|``, ``{``, ``}``, ``[`` and ``]``. | 705 ``#``; ``'``, ``"``, ``|``, ``{``, ``}``, ``[`` and ``]``. |
| 699 | 706 |
| 700 See also the :ref:`quoting` section. | 707 See also the :ref:`quoting` section. |
| 701 | 708 |
| 702 """ | 709 """ |
| 710 # Quick check whether all of the chars is in _QUOTE_SAFE | |
| 711 if not s.rstrip(klass._QUOTE_SAFE): | |
| 712 return s | |
| 713 # Slow path | |
| 703 qc = klass._QUOTE | 714 qc = klass._QUOTE |
| 704 s = s.replace(qc, qc + "x25") | 715 s = s.replace(qc, qc + "x25") |
| 705 s = s.replace(klass._DOT, qc + "x2e") | 716 s = s.replace(klass._DOT, qc + "x2e") |
| 706 s = s.replace(klass._NS_SEPARATOR, qc + "x3a") | 717 s = s.replace(klass._NS_SEPARATOR, qc + "x3a") |
| 707 s = s.replace(klass._COMMENT, qc + "x23") | 718 s = s.replace(klass._COMMENT, qc + "x23") |
