Index: univention-config-registry/python/univention/config_registry/handler.py =================================================================== --- univention-config-registry/python/univention/config_registry/handler.py (Revision 35626) +++ univention-config-registry/python/univention/config_registry/handler.py (Arbeitskopie) @@ -47,8 +47,8 @@ __all__ = ['ConfigHandlers'] VARIABLE_PATTERN = re.compile('@%@([^@]+)@%@') -VARIABLE_TOKEN = re.compile('@%@') -EXECUTE_TOKEN = re.compile('@!@') +VARIABLE_TOKEN = re.compile('@%@.*?@%@') +EXECUTE_TOKEN = re.compile('@!@.*?@!@', re.MULTILINE | re.DOTALL) WARNING_PATTERN = re.compile('(UCRWARNING|BCWARNING|UCRWARNING_ASCII)=(.+)') INFO_DIR = '/etc/univention/templates/info' @@ -75,44 +75,43 @@ def run_filter(template, directory, srcfiles=set(), opts=dict()): """Process a template file: susbstitute variables.""" - while True: - i = VARIABLE_TOKEN.finditer(template) - try: - start = i.next() - end = i.next() - name = template[start.end():end.start()] + out = [] + lastPos = 0 + for i in VARIABLE_TOKEN.finditer(template): + name = template[i.start()+3:i.start()-3] - if name in directory: - value = directory[name] + if name in directory: + value = directory[name] + else: + match = WARNING_PATTERN.match(name) + if match: + mode, prefix = match.groups() + if mode == "UCRWARNING_ASCII": + value = warning_string(prefix, srcfiles=srcfiles, + enforce_ascii=True) + else: + value = warning_string(prefix, srcfiles=srcfiles) else: - match = WARNING_PATTERN.match(name) - if match: - mode, prefix = match.groups() - if mode == "UCRWARNING_ASCII": - value = warning_string(prefix, srcfiles=srcfiles, - enforce_ascii=True) - else: - value = warning_string(prefix, srcfiles=srcfiles) - else: - value = '' + value = '' - if isinstance(value, (list, tuple)): - value = value[0] - template = template[:start.start()] + value + template[end.end():] - except StopIteration: - break + if isinstance(value, (list, tuple)): + value = value[0] - while True: - i = EXECUTE_TOKEN.finditer(template) - try: - start = i.next() - end = i.next() + out.append(template[lastPos:i.start()]) + out.append(value) + lastPos = i.end() - proc = subprocess.Popen((__PYTHON_EXECUTABLE,), - stdin=subprocess.PIPE, stdout=subprocess.PIPE, - close_fds=True) - child_stdin, child_stdout = proc.stdin, proc.stdout - child_stdin.write('''\ + out.append(template[lastPos:]) + template = ''.join(out) + + out = [] + lastPos = 0 + for i in EXECUTE_TOKEN.finditer(template): + proc = subprocess.Popen((__PYTHON_EXECUTABLE,), + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + close_fds=True) + child_stdin, child_stdout = proc.stdin, proc.stdout + child_stdin.write('''\ # -*- coding: utf-8 -*- import univention.config_registry configRegistry = univention.config_registry.ConfigRegistry() @@ -120,15 +119,18 @@ # for compatibility baseConfig = configRegistry ''') - child_stdin.write(template[start.end():end.start()]) - child_stdin.close() - value = child_stdout.read() - child_stdout.close() - template = template[:start.start()] + value + template[end.end():] + child_stdin.write(template[i.start()+3:i.end()-3]) + child_stdin.close() + value = child_stdout.read() + child_stdout.close() - except StopIteration: - break + out.append(template[lastPos:i.start()]) + out.append(value) + lastPos = i.end() + out.append(template[lastPos:]) + template = ''.join(out) + return template