Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/variables.py @ 349:83f76a41cf7c
Implement a special filter named "None" that suppresses "KeyErrors" from interpolation lookups and returns a Python "None" instead
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 24 Jun 2021 09:33:22 +0200 |
| parents | d7daec119383 |
| children | 2b209bdf6995 |
comparison
equal
deleted
inserted
replaced
| 348:396d8d9aaead | 349:83f76a41cf7c |
|---|---|
| 242 def upper_impl(config, v): | 242 def upper_impl(config, v): |
| 243 """Implementation of the `upper` filter function""" | 243 """Implementation of the `upper` filter function""" |
| 244 return v.upper() | 244 return v.upper() |
| 245 | 245 |
| 246 | 246 |
| 247 @filter("None") | |
| 248 def None_filter_impl(config, v): | |
| 249 """Identity. | |
| 250 | |
| 251 The `None` filter is just a marker to not throw `KeyError` but return | |
| 252 `None`. | |
| 253 | |
| 254 """ | |
| 255 return v | |
| 256 | |
| 257 | |
| 247 # Register the default namespaces | 258 # Register the default namespaces |
| 248 add_varns("ENV", _envlookup) | 259 add_varns("ENV", _envlookup) |
| 249 add_varns("OS", _oslookup) | 260 add_varns("OS", _oslookup) |
| 250 add_varns("PY", _pylookup) | 261 add_varns("PY", _pylookup) |
| 251 try: | 262 try: |
