annotate configmix/variables.py @ 654:0d6673d06c2c

Add support for using "tomllib" (in Python's stdlib since 3.11) and "tomli" TOML packages. They are preferred if they are found to be installed. But note that the declared dependency for the "toml" extra nevertheless is the "toml" package. Because it is available for all supported Python versions. So use Python 3.11+ or install "tomli" manually if you want to use the alternate packages.
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 19 May 2022 22:10:59 +0200
parents f454889e41fa
children 57fe110c50c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
208
bbe8513ea649 Handle flake8 E265 "block comment should start with '# ': use '# :-' instead of '#-' to mark copyright and license comments
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
2 # :-
593
f454889e41fa Adjust copyright year (the end) to 2022
Franz Glasner <fzglas.hg@dom66.de>
parents: 522
diff changeset
3 # :Copyright: (c) 2015-2022, Franz Glasner. All rights reserved.
296
eed16a1ec8f3 Use SPDX license identifiers (either full or short) all over the package
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
4 # :License: BSD-3-Clause. See LICENSE.txt for details.
208
bbe8513ea649 Handle flake8 E265 "block comment should start with '# ': use '# :-' instead of '#-' to mark copyright and license comments
Franz Glasner <fzglas.hg@dom66.de>
parents: 207
diff changeset
5 # :-
202
2e66178a09d8 Docu: Ban "keyword expansion" -- use "variable interpolation" instead
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
6 """Variable interpolation: implementation of namespaces and filters
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
7
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
8 """
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
9
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
10 from __future__ import division, absolute_import, print_function
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
11
250
ff964825a75a Style: placement of "__all__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 243
diff changeset
12
ff964825a75a Style: placement of "__all__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 243
diff changeset
13 __all__ = []
ff964825a75a Style: placement of "__all__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 243
diff changeset
14
ff964825a75a Style: placement of "__all__"
Franz Glasner <fzglas.hg@dom66.de>
parents: 243
diff changeset
15
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
16 import os
243
57ff12610dc5 Implemented OS:node to return the host's computername
Franz Glasner <fzglas.hg@dom66.de>
parents: 242
diff changeset
17 import platform
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
18 from functools import wraps
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
19
357
dd454e1efea4 Use constants for the names of the "None" and "Empty" filters
Franz Glasner <fzglas.hg@dom66.de>
parents: 352
diff changeset
20 from .compat import PY2, native_os_str_to_text, text_to_native_os_str, u
dd454e1efea4 Use constants for the names of the "None" and "Empty" filters
Franz Glasner <fzglas.hg@dom66.de>
parents: 352
diff changeset
21 from .constants import REF_NAMESPACE, NONE_FILTER, EMPTY_FILTER
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
22
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
23
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
24 _MARKER = object()
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
25
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
26
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
27 def _envlookup(name, default=_MARKER):
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
28 """Lookup an environment variable"""
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
29 try:
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
30 return native_os_str_to_text(os.environ[name])
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
31 except KeyError:
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
32 if default is _MARKER:
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
33 raise
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
34 else:
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
35 return default
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
36
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
37
30
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
38 def _oslookup(name, default=_MARKER):
99
cd6c5c1494f5 FIX: Comment for function "_oslookup()" was wrong by copy/paste
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 89
diff changeset
39 """Lookup some process and/or OS state """
30
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
40 if name == "cwd":
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
41 return native_os_str_to_text(os.getcwd())
243
57ff12610dc5 Implemented OS:node to return the host's computername
Franz Glasner <fzglas.hg@dom66.de>
parents: 242
diff changeset
42 elif name == "node":
57ff12610dc5 Implemented OS:node to return the host's computername
Franz Glasner <fzglas.hg@dom66.de>
parents: 242
diff changeset
43 return native_os_str_to_text(platform.node())
242
bfa4d125fd14 FIX: The namespace lookup implementation for the "OS" namespace did not properly handle the "default" argument.
Franz Glasner <fzglas.hg@dom66.de>
parents: 237
diff changeset
44 else:
bfa4d125fd14 FIX: The namespace lookup implementation for the "OS" namespace did not properly handle the "default" argument.
Franz Glasner <fzglas.hg@dom66.de>
parents: 237
diff changeset
45 if default is _MARKER:
bfa4d125fd14 FIX: The namespace lookup implementation for the "OS" namespace did not properly handle the "default" argument.
Franz Glasner <fzglas.hg@dom66.de>
parents: 237
diff changeset
46 raise KeyError("key %r not found in the namespace" % name)
bfa4d125fd14 FIX: The namespace lookup implementation for the "OS" namespace did not properly handle the "default" argument.
Franz Glasner <fzglas.hg@dom66.de>
parents: 237
diff changeset
47 else:
bfa4d125fd14 FIX: The namespace lookup implementation for the "OS" namespace did not properly handle the "default" argument.
Franz Glasner <fzglas.hg@dom66.de>
parents: 237
diff changeset
48 return default
30
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
49
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
50
43
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
51 def _pylookup(name, default=_MARKER):
100
e3289a56ba80 Enhance docu
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 99
diff changeset
52 """Lookup Python specific information"""
43
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
53 if name == "version":
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
54 return u(platform.python_version())
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
55 elif name == "implementation":
207
b3b5ed34d180 Handle most flake8 errors and warnings.
Franz Glasner <fzglas.hg@dom66.de>
parents: 202
diff changeset
56 return u(platform.python_implementation())
43
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
57 elif name == "version_maj_min":
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
58 t = platform.python_version_tuple()
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
59 return u('.'.join(t[:2]))
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
60 elif name == "version_maj":
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
61 t = platform.python_version_tuple()
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
62 return u(t[0])
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
63 else:
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
64 if default is _MARKER:
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
65 raise KeyError("variable %r not found in namespace PY" % name)
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
66 else:
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
67 return default
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
68
0e9f1f875ab0 A new PY variable namespace with some variables about the Python implementation and version
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 33
diff changeset
69
106
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
70 _varns_registry = {}
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
71 """Namespace registry"""
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
72
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
73
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
74 def add_varns(name, fn):
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
75 """Register a new variable namespace `name` and it's implementing
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
76 function `fn`
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
77
305
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
78 ..note:: This function checks that `name` is not the special
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
79 namespace :data:`~configmix.constants.REF_NAMESPACE`.
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
80
106
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
81 """
305
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
82 if name == REF_NAMESPACE:
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
83 raise ValueError(
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
84 "the special namespace `%s' is not allowed here" % REF_NAMESPACE)
106
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
85 _varns_registry[name] = fn
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
86
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
87
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
88 def lookup_varns(name):
106
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
89 """Lookup the variable namespace `name` and return it's implementing
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
90 function
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
91
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
92 :param str name: the namespace name
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
93 :returns: the implementing function
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
94 :exception KeyError: if the namespace `name` doesn't exist
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
95
305
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
96 ..note:: This function checks that `name` is not the special
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
97 namespace :data:`~configmix.constants.REF_NAMESPACE`.
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
98
106
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
99 """
305
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
100 if name == REF_NAMESPACE:
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
101 raise ValueError(
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 296
diff changeset
102 "the special namespace `%s' is not allowed here" % REF_NAMESPACE)
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
103 return _varns_registry[_normalized(name)]
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
104
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
105
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
106 _filter_registry = {}
106
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
107 """Filter registry"""
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
108
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
109
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
110 def add_filter(name, fn):
106
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
111 """Register a variable filter function with name `name` and
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
112 implementation `fn`
101
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
113
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
114 """
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
115 _filter_registry[_normalized(name)] = fn
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
116
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
117
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
118 def lookup_filter(name):
106
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
119 """Lookup a variable filter with name `name` and return it's
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
120 implementation function
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
121
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
122 :param str name: the logical filter name
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
123 :returns: the implementing filter function
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
124 :exception KeyError: if the filter cannot be found
101
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
125
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
126 """
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
127 return _filter_registry[_normalized(name)]
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
128
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
129
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
130 def filter(name):
101
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
131 """Decorator for a filter function.
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
132
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
133 Example usage::
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
134
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
135 @filter("myfilter")
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
136 def myfilter_impl(appconfig, variable_value):
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
137 filtered_value = ...
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
138 return filtered_value
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
139
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
140
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
141 """
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
142
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
143 def _decorator(f):
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
144
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
145 @wraps(f)
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
146 def _f(appconfig, v):
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
147 return f(appconfig, v)
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
148
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
149 add_filter(name, _f)
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
150 return _f
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
151
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
152 return _decorator
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
153
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
154
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
155 def _normalized(name):
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
156 return name.replace('-', '_')
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
157
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
158
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
159 #
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
160 # Some pre-defined filter functions
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
161 #
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
162 if PY2:
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
163
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
164 @filter("urlquote")
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
165 def urlquote(config, v):
347
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
166 """Filter function to replace all special characters in string `v`
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
167 using the ``%xx`` escape
101
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
168
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
169 """
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
170 from urllib import quote
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
171 return quote(v.encode("utf-8"), safe=b"").decode("utf-8")
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
172
347
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
173
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
174 @filter("urlquote_plus")
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
175 def urlquote_plus(config, v):
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
176 """Filter function to replace all special characters (including
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
177 spaces) in string `v` using the ``%xx`` escape
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
178
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
179 """
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
180 from urllib import quote_plus
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
181 return quote_plus(v.encode("utf-8"), safe=b"").decode("utf-8")
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
182
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
183 else:
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
184
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
185 @filter("urlquote")
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
186 def urlquote(config, v):
347
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
187 """Filter function to replace all special characters in string `v`
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
188 using the ``%xx`` escape
101
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
189
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
190 """
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
191 from urllib.parse import quote
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
192 return quote(v, safe="")
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
193
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
194
347
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
195 @filter("urlquote_plus")
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
196 def urlquote_plus(config, v):
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
197 """Filter function to replace all special characters (including
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
198 spaces) in string `v` using the ``%xx`` escape
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
199
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
200 """
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
201 from urllib.parse import quote_plus
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
202 return quote_plus(v, safe="")
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
203
d7daec119383 New filter function "urlquote_plus" which quotes a space into a '+' character
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
204
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
205 @filter("saslprep")
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
206 def saslprep(config, v):
101
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
207 """Filter function to perform a `SASLprep` according to :rfc:`4013` on
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
208 `v`.
15
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
209
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
210 This is a Stringprep Profile for usernames and passwords
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
211
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
212 """
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
213 import passlib.utils
0b1292e920af Variables: namespaces and filters
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
diff changeset
214 return passlib.utils.saslprep(v)
30
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
215
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
216
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
217 @filter("normpath")
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
218 def normpath_impl(config, v):
101
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
219 """Implementation of the `normpath` filter function"""
30
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
220 return os.path.normpath(v)
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
221
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
222
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
223 @filter("abspath")
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
224 def abspath_impl(config, v):
101
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
225 """Implementation of the `abspath` filter function"""
30
d70b58b0dfb9 A new variable namespace "OS" with a "cwd" function with new filters "abspath" and "normpath" for some minimal path manipulation
Franz Glasner <hg@dom66.de>
parents: 15
diff changeset
226 return os.path.abspath(v)
33
3ee21f868440 Implement a "posixpath" filter to convert file path strings to use forward slashes.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
227
3ee21f868440 Implement a "posixpath" filter to convert file path strings to use forward slashes.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
228
3ee21f868440 Implement a "posixpath" filter to convert file path strings to use forward slashes.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
229 @filter("posixpath")
3ee21f868440 Implement a "posixpath" filter to convert file path strings to use forward slashes.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
230 def posixpath_impl(config, v):
101
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
231 """Implementation of the `posixpath` filter function"""
33
3ee21f868440 Implement a "posixpath" filter to convert file path strings to use forward slashes.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
232 return v.replace(u('\\'), u('/'))
44
b42e9936df2d Added "lower" and "upper" filters to make variable lower-case and upper-case
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 43
diff changeset
233
b42e9936df2d Added "lower" and "upper" filters to make variable lower-case and upper-case
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 43
diff changeset
234
b42e9936df2d Added "lower" and "upper" filters to make variable lower-case and upper-case
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 43
diff changeset
235 @filter("lower")
b42e9936df2d Added "lower" and "upper" filters to make variable lower-case and upper-case
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 43
diff changeset
236 def lower_impl(config, v):
101
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
237 """Implementation of the `lower` filter function"""
44
b42e9936df2d Added "lower" and "upper" filters to make variable lower-case and upper-case
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 43
diff changeset
238 return v.lower()
b42e9936df2d Added "lower" and "upper" filters to make variable lower-case and upper-case
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 43
diff changeset
239
b42e9936df2d Added "lower" and "upper" filters to make variable lower-case and upper-case
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 43
diff changeset
240
b42e9936df2d Added "lower" and "upper" filters to make variable lower-case and upper-case
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 43
diff changeset
241 @filter("upper")
b42e9936df2d Added "lower" and "upper" filters to make variable lower-case and upper-case
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 43
diff changeset
242 def upper_impl(config, v):
101
f6f2dc7cf053 Better docu of the configmix.variables module
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 100
diff changeset
243 """Implementation of the `upper` filter function"""
44
b42e9936df2d Added "lower" and "upper" filters to make variable lower-case and upper-case
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 43
diff changeset
244 return v.upper()
106
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
245
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
246
357
dd454e1efea4 Use constants for the names of the "None" and "Empty" filters
Franz Glasner <fzglas.hg@dom66.de>
parents: 352
diff changeset
247 @filter(text_to_native_os_str(NONE_FILTER, encoding="ascii"))
349
83f76a41cf7c Implement a special filter named "None" that suppresses "KeyErrors" from interpolation lookups and returns a Python "None" instead
Franz Glasner <fzglas.hg@dom66.de>
parents: 347
diff changeset
248 def None_filter_impl(config, v):
83f76a41cf7c Implement a special filter named "None" that suppresses "KeyErrors" from interpolation lookups and returns a Python "None" instead
Franz Glasner <fzglas.hg@dom66.de>
parents: 347
diff changeset
249 """Identity.
83f76a41cf7c Implement a special filter named "None" that suppresses "KeyErrors" from interpolation lookups and returns a Python "None" instead
Franz Glasner <fzglas.hg@dom66.de>
parents: 347
diff changeset
250
360
d2751a80d9b7 Docu: fix link to KeyError in the new filter function implementations
Franz Glasner <fzglas.hg@dom66.de>
parents: 357
diff changeset
251 The `None` filter is just a marker to not throw :exc:`KeyError`
522
Franz Glasner <fzglas.hg@dom66.de>
parents: 360
diff changeset
252 but return `None`. It is a no-op within the filter-chain itself.
349
83f76a41cf7c Implement a special filter named "None" that suppresses "KeyErrors" from interpolation lookups and returns a Python "None" instead
Franz Glasner <fzglas.hg@dom66.de>
parents: 347
diff changeset
253
83f76a41cf7c Implement a special filter named "None" that suppresses "KeyErrors" from interpolation lookups and returns a Python "None" instead
Franz Glasner <fzglas.hg@dom66.de>
parents: 347
diff changeset
254 """
83f76a41cf7c Implement a special filter named "None" that suppresses "KeyErrors" from interpolation lookups and returns a Python "None" instead
Franz Glasner <fzglas.hg@dom66.de>
parents: 347
diff changeset
255 return v
83f76a41cf7c Implement a special filter named "None" that suppresses "KeyErrors" from interpolation lookups and returns a Python "None" instead
Franz Glasner <fzglas.hg@dom66.de>
parents: 347
diff changeset
256
83f76a41cf7c Implement a special filter named "None" that suppresses "KeyErrors" from interpolation lookups and returns a Python "None" instead
Franz Glasner <fzglas.hg@dom66.de>
parents: 347
diff changeset
257
357
dd454e1efea4 Use constants for the names of the "None" and "Empty" filters
Franz Glasner <fzglas.hg@dom66.de>
parents: 352
diff changeset
258 @filter(text_to_native_os_str(EMPTY_FILTER, encoding="ascii"))
352
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 349
diff changeset
259 def Empty_filter_impl(config, v):
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 349
diff changeset
260 """Identity.
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 349
diff changeset
261
360
d2751a80d9b7 Docu: fix link to KeyError in the new filter function implementations
Franz Glasner <fzglas.hg@dom66.de>
parents: 357
diff changeset
262 The `Empty` filter is just a marker to not throw :exc:`KeyError`
522
Franz Glasner <fzglas.hg@dom66.de>
parents: 360
diff changeset
263 but return the empty string. It is a no-op within the filter-chain itself.
352
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 349
diff changeset
264
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 349
diff changeset
265 """
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 349
diff changeset
266 return v
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 349
diff changeset
267
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 349
diff changeset
268
106
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
269 # Register the default namespaces
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
270 add_varns("ENV", _envlookup)
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
271 add_varns("OS", _oslookup)
b35837427a7a Add an "add_varns()" function to add new namespaces for variables.
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
272 add_varns("PY", _pylookup)
282
da1596034954 Implemented an "AWS" namespace to retrieve some AWS-specific metadata
Franz Glasner <fzglas.hg@dom66.de>
parents: 250
diff changeset
273 try:
da1596034954 Implemented an "AWS" namespace to retrieve some AWS-specific metadata
Franz Glasner <fzglas.hg@dom66.de>
parents: 250
diff changeset
274 from .extras import aws
da1596034954 Implemented an "AWS" namespace to retrieve some AWS-specific metadata
Franz Glasner <fzglas.hg@dom66.de>
parents: 250
diff changeset
275 except ImportError:
da1596034954 Implemented an "AWS" namespace to retrieve some AWS-specific metadata
Franz Glasner <fzglas.hg@dom66.de>
parents: 250
diff changeset
276 pass
da1596034954 Implemented an "AWS" namespace to retrieve some AWS-specific metadata
Franz Glasner <fzglas.hg@dom66.de>
parents: 250
diff changeset
277 else:
da1596034954 Implemented an "AWS" namespace to retrieve some AWS-specific metadata
Franz Glasner <fzglas.hg@dom66.de>
parents: 250
diff changeset
278 add_varns("AWS", aws._awslookup)