19 type_name, unescape, unic)
21 from .splitter
import VariableSplitter
40 def replace_list(self, items, replace_until=None, ignore_errors=False):
41 items = list(items
or [])
42 if replace_until
is not None:
44 return list(self.
_replace_list_replace_list(items, ignore_errors))
51 while len(replaced) < replace_until
and items:
52 replaced.extend(self.
_replace_list_replace_list([items.pop(0)], ignore_errors))
53 if len(replaced) > replace_until:
54 replaced[replace_until:] = [
escape(item)
55 for item
in replaced[replace_until:]]
56 return replaced + items
74 if splitter.is_list_variable():
87 return self.
_replace_scalar_replace_scalar(item, ignore_errors=ignore_errors)
92 if not splitter.identifier:
94 if not splitter.is_variable():
95 return self.
_replace_string_replace_string(item, splitter, ignore_errors)
104 return not (
is_string(item)
and '{' in item)
112 return self.
_replace_string_replace_string(string, ignore_errors=ignore_errors)
117 return ''.join(self.
_yield_replaced_yield_replaced(string, splitter, ignore_errors))
120 while splitter.identifier:
121 yield unescape(string[:splitter.start])
125 if not ignore_errors:
127 value = string[splitter.start:splitter.end]
129 string = string[splitter.end:]
134 if splitter.identifier
not in '$@&%':
136 name = splitter.get_replaced_variable(self)
138 for item
in splitter.items:
140 name =
'%s[%s]' % (name, item)
148 raise VariableError(
"Variable '%s' is %s, not list or dictionary, "
149 "and thus accessing item '%s' from it is not "
154 value = splitter.get_replaced_variable(self)
155 LOGGER.warn(
"Syntax '%s' is reserved for future use. Please "
156 "escape it like '\\%s'." % (value, value))
164 raise VariableError(
"List '%s' used with invalid index '%s'."
167 return variable[index]
175 if index.count(
':') > 2
or not support_slice:
177 return slice(*[
int(i)
if i
else None for i
in index.split(
':')])
186 except TypeError
as err:
187 raise VariableError(
"Dictionary '%s' used with invalid key: %s"
Used when no keyword is found or there is more than one match.
def _yield_replaced(self, string, splitter, ignore_errors=False)
def replace_string(self, string, ignore_errors=False)
Replaces variables from a string.
def __init__(self, variables)
def _get_reserved_variable(self, splitter)
def _replace_list_until(self, items, replace_until, ignore_errors)
def _parse_list_variable_index(self, index, support_slice=True)
def _replace_string(self, string, splitter=None, ignore_errors=False)
def _cannot_have_variables(self, item)
def _replace_scalar(self, item, splitter=None, ignore_errors=False)
def _get_variable_item(self, name, variable, item)
def _get_variable(self, splitter)
def _get_list_variable_item(self, name, variable, index)
def _replace_list_item(self, item, ignore_errors)
def replace_scalar(self, item, ignore_errors=False)
Replaces variables from a scalar item.
def replace_list(self, items, replace_until=None, ignore_errors=False)
Replaces variables from a list of items.
def _get_dict_variable_item(self, name, variable, key)
def _replace_list(self, items, ignore_errors)