changeset 478:ff8a9a7c6a93

Avoid some repeated string/unicode conversions for constants used by quoting
author Franz Glasner <f.glasner@feldmann-mg.com>
date Fri, 17 Dec 2021 11:46:36 +0100
parents 1de6cc49776e
children 490f0c4665bb
files configmix/config.py
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/configmix/config.py	Fri Dec 17 11:42:47 2021 +0100
+++ b/configmix/config.py	Fri Dec 17 11:46:36 2021 +0100
@@ -233,6 +233,9 @@
     _ENDTOK_REF = _ENDTOK
     _DOT = u(b'.')
     _QUOTE = u(b'%')
+    _QUOTE_x = u(b'x')
+    _QUOTE_u = u(b'u')
+    _QUOTE_U = u(b'U')
     _COMMENT = u(b'#')
 
     is_jail = False
@@ -740,17 +743,17 @@
         res = [parts[0]]
         res_append = res.append
         for p in parts[1:]:
-            if p.startswith(u(b'x')):
+            if p.startswith(klass._QUOTE_x):
                 if len(p) < 3:
                     raise ValueError("quote syntax: length too small")
                 res_append(uchr(int(p[1:3], 16)))
                 res_append(p[3:])
-            elif p.startswith(u(b'u')):
+            elif p.startswith(klass._QUOTE_u):
                 if len(p) < 5:
                     raise ValueError("quote syntax: length too small")
                 res_append(uchr(int(p[1:5], 16)))
                 res_append(p[5:])
-            elif p.startswith(u(b'U')):
+            elif p.startswith(klass._QUOTE_U):
                 if len(p) < 9:
                     raise ValueError("quote syntax: length too small")
                 res_append(uchr(int(p[1:9], 16)))