Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/variables.py @ 30:d70b58b0dfb9
A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Fri, 18 Mar 2016 09:27:14 +0100 |
| parents | 0b1292e920af |
| children | 3ee21f868440 |
comparison
equal
deleted
inserted
replaced
| 29:17af7a78710c | 30:d70b58b0dfb9 |
|---|---|
| 26 raise | 26 raise |
| 27 else: | 27 else: |
| 28 return default | 28 return default |
| 29 | 29 |
| 30 | 30 |
| 31 _varns_registry = {"ENV": _envlookup} | 31 def _oslookup(name, default=_MARKER): |
| 32 """Lookup an environment variable""" | |
| 33 if name == "cwd": | |
| 34 return native_os_str_to_text(os.getcwd()) | |
| 35 raise KeyError("key %r not found in the namespace" % name) | |
| 36 | |
| 37 | |
| 38 _varns_registry = { | |
| 39 "ENV": _envlookup, | |
| 40 "OS": _oslookup | |
| 41 } | |
| 32 | 42 |
| 33 | 43 |
| 34 def lookup_varns(name): | 44 def lookup_varns(name): |
| 35 return _varns_registry[_normalized(name)] | 45 return _varns_registry[_normalized(name)] |
| 36 | 46 |
| 92 This is a Stringprep Profile for usernames and passwords | 102 This is a Stringprep Profile for usernames and passwords |
| 93 | 103 |
| 94 """ | 104 """ |
| 95 import passlib.utils | 105 import passlib.utils |
| 96 return passlib.utils.saslprep(v) | 106 return passlib.utils.saslprep(v) |
| 107 | |
| 108 | |
| 109 @filter("normpath") | |
| 110 def normpath_impl(config, v): | |
| 111 return os.path.normpath(v) | |
| 112 | |
| 113 | |
| 114 @filter("abspath") | |
| 115 def abspath_impl(config, v): | |
| 116 return os.path.abspath(v) |
