Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 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 |
comparison
equal
deleted
inserted
replaced
| 477:1de6cc49776e | 478:ff8a9a7c6a93 |
|---|---|
| 231 _FILTER_SEPARATOR = u(b'|') | 231 _FILTER_SEPARATOR = u(b'|') |
| 232 _STARTTOK_REF = _STARTTOK + REF_NAMESPACE + _NS_SEPARATOR | 232 _STARTTOK_REF = _STARTTOK + REF_NAMESPACE + _NS_SEPARATOR |
| 233 _ENDTOK_REF = _ENDTOK | 233 _ENDTOK_REF = _ENDTOK |
| 234 _DOT = u(b'.') | 234 _DOT = u(b'.') |
| 235 _QUOTE = u(b'%') | 235 _QUOTE = u(b'%') |
| 236 _QUOTE_x = u(b'x') | |
| 237 _QUOTE_u = u(b'u') | |
| 238 _QUOTE_U = u(b'U') | |
| 236 _COMMENT = u(b'#') | 239 _COMMENT = u(b'#') |
| 237 | 240 |
| 238 is_jail = False | 241 is_jail = False |
| 239 """Flag to show that this is not a jail for another configuration""" | 242 """Flag to show that this is not a jail for another configuration""" |
| 240 | 243 |
| 738 return s | 741 return s |
| 739 parts = s.split(klass._QUOTE) | 742 parts = s.split(klass._QUOTE) |
| 740 res = [parts[0]] | 743 res = [parts[0]] |
| 741 res_append = res.append | 744 res_append = res.append |
| 742 for p in parts[1:]: | 745 for p in parts[1:]: |
| 743 if p.startswith(u(b'x')): | 746 if p.startswith(klass._QUOTE_x): |
| 744 if len(p) < 3: | 747 if len(p) < 3: |
| 745 raise ValueError("quote syntax: length too small") | 748 raise ValueError("quote syntax: length too small") |
| 746 res_append(uchr(int(p[1:3], 16))) | 749 res_append(uchr(int(p[1:3], 16))) |
| 747 res_append(p[3:]) | 750 res_append(p[3:]) |
| 748 elif p.startswith(u(b'u')): | 751 elif p.startswith(klass._QUOTE_u): |
| 749 if len(p) < 5: | 752 if len(p) < 5: |
| 750 raise ValueError("quote syntax: length too small") | 753 raise ValueError("quote syntax: length too small") |
| 751 res_append(uchr(int(p[1:5], 16))) | 754 res_append(uchr(int(p[1:5], 16))) |
| 752 res_append(p[5:]) | 755 res_append(p[5:]) |
| 753 elif p.startswith(u(b'U')): | 756 elif p.startswith(klass._QUOTE_U): |
| 754 if len(p) < 9: | 757 if len(p) < 9: |
| 755 raise ValueError("quote syntax: length too small") | 758 raise ValueError("quote syntax: length too small") |
| 756 res_append(uchr(int(p[1:9], 16))) | 759 res_append(uchr(int(p[1:9], 16))) |
| 757 res_append(p[9:]) | 760 res_append(p[9:]) |
| 758 else: | 761 else: |
