diff options
author | Viacheslav Hletenko <v.gletenko@vyos.io> | 2023-03-06 18:16:45 +0000 |
---|---|---|
committer | Viacheslav Hletenko <v.gletenko@vyos.io> | 2023-03-06 18:16:45 +0000 |
commit | 045562e1d5c655622444c95df192f7e49cca2565 (patch) | |
tree | 995a52f372f7a236bbf7daea72cc81a3d2124da7 /python/vyos/template.py | |
parent | 14bca4e80c4d0773ada6862f732c2f1495594239 (diff) | |
download | vyos-1x-045562e1d5c655622444c95df192f7e49cca2565.tar.gz vyos-1x-045562e1d5c655622444c95df192f7e49cca2565.zip |
T5058: Extend template filter range_to_regex to allow list as arg
Extend template filter 'range_to_regex'
Allow list of ranges as argument
% range_to_regex(['11-12', '14-15'])
'(1[1-2]|1[4-5])'
Diffstat (limited to 'python/vyos/template.py')
-rw-r--r-- | python/vyos/template.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py index 6367f51e5..7f417992e 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -663,7 +663,21 @@ def nat_static_rule(rule_conf, rule_id, nat_type): @register_filter('range_to_regex') def range_to_regex(num_range): + """Convert range of numbers or list of ranges + to regex + + % range_to_regex('11-12') + '(1[1-2])' + % range_to_regex(['11-12', '14-15']) + '(1[1-2]|1[4-5])' + """ from vyos.range_regex import range_to_regex + if isinstance(num_range, list): + data = [] + for entry in num_range: + data.append(range_to_regex(entry)) + return f'({"|".join(data)})' + if '-' not in num_range: return num_range |