Mercurial > hgrepos > Python > libs > ConfigMix
diff configmix/variables.py @ 305:f529ca46dd50
Implemented the "ref" namespace to get configuration tree references.
BUGS:
- Tests should be done more thoroughly and extensively
- Interaction of tree references and variable substitution should be
tested more properly
- Documentation is missing yet
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 26 Apr 2021 09:42:42 +0200 |
| parents | eed16a1ec8f3 |
| children | d7daec119383 |
line wrap: on
line diff
--- a/configmix/variables.py Sun Apr 25 18:05:26 2021 +0200 +++ b/configmix/variables.py Mon Apr 26 09:42:42 2021 +0200 @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # :- -# :Copyright: (c) 2015-2020, Franz Glasner. All rights reserved. +# :Copyright: (c) 2015-2021, Franz Glasner. All rights reserved. # :License: BSD-3-Clause. See LICENSE.txt for details. # :- """Variable interpolation: implementation of namespaces and filters @@ -18,6 +18,7 @@ from functools import wraps from .compat import PY2, native_os_str_to_text, u +from .constants import REF_NAMESPACE _MARKER = object() @@ -74,7 +75,13 @@ """Register a new variable namespace `name` and it's implementing function `fn` + ..note:: This function checks that `name` is not the special + namespace :data:`~configmix.constants.REF_NAMESPACE`. + """ + if name == REF_NAMESPACE: + raise ValueError( + "the special namespace `%s' is not allowed here" % REF_NAMESPACE) _varns_registry[name] = fn @@ -86,7 +93,13 @@ :returns: the implementing function :exception KeyError: if the namespace `name` doesn't exist + ..note:: This function checks that `name` is not the special + namespace :data:`~configmix.constants.REF_NAMESPACE`. + """ + if name == REF_NAMESPACE: + raise ValueError( + "the special namespace `%s' is not allowed here" % REF_NAMESPACE) return _varns_registry[_normalized(name)]
