Coverage for python/univention/config_registry/filters.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2026-09-11 14:11 +0000

1"""Univention Configuration Registry output filters.""" 

2# main configuration registry classes 

3# 

4# SPDX-FileCopyrightText: 2004-2026 Univention GmbH 

5# SPDX-License-Identifier: AGPL-3.0-only 

6 

7from univention.config_registry.misc import escape_value, key_shell_escape 

8 

9 

10try: 

11 from collections.abc import Iterable 

12 from typing import Any 

13except ImportError: # pragma: no cover 

14 pass 

15 

16__all__ = ['filter_keys_only', 'filter_shell', 'filter_sort'] 

17 

18 

19def filter_shell(args: Any, text: Iterable[str]) -> Iterable[str]: # pylint: disable-msg=W0613 

20 """ 

21 Filter output for shell: escape keys. 

22 

23 :param args: UNUSED. 

24 :param text: Text as list of lines. 

25 :returns: Filteres list of lines. 

26 """ 

27 out = [] 

28 for line in text: 

29 try: 

30 var, value = line.split(': ', 1) 

31 except ValueError: 

32 var = line 

33 value = '' 

34 out.append('%s=%s' % (key_shell_escape(var), escape_value(value))) 

35 return out 

36 

37 

38def filter_keys_only(args: Any, text: Iterable[str]) -> Iterable[str]: # pylint: disable-msg=W0613 

39 """ 

40 Filter output: strip values. 

41 

42 :param args: UNUSED. 

43 :param text: Text as list of lines. 

44 :returns: Filteres list of lines. 

45 """ 

46 out = [] 

47 for line in text: 

48 out.append(line.split(': ', 1)[0]) 

49 return out 

50 

51 

52def filter_sort(args: Any, text: Iterable[str]) -> Iterable[str]: # pylint: disable-msg=W0613 

53 """ 

54 Filter output: sort by key. 

55 

56 :param args: UNUSED. 

57 :param text: Text as list of lines. 

58 :returns: Filteres list of lines. 

59 """ 

60 return sorted(text)