diff options
author | Christian Poessinger <christian@poessinger.com> | 2022-09-16 09:15:21 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2022-09-16 09:16:17 +0200 |
commit | 28573ffe4fd939a266006840f999c99babe89dce (patch) | |
tree | afd5f75f8ab82707e7a1b477edb1b671c84b57e3 /src/validators/range | |
parent | 7a2ad35ec8ecd84d162a3e5dc41b50f31d18dc10 (diff) | |
download | vyos-1x-28573ffe4fd939a266006840f999c99babe89dce.tar.gz vyos-1x-28573ffe4fd939a266006840f999c99babe89dce.zip |
xml: T4698: drop validator name="range" and replace it with numeric
After T4669 added support for range validation to the OCaml validator there is
no need to keep the slow Python validator in place.
Raplace all occurances of <validator name="range" argument="--min=1 --max=65535"/>
with <validator name="numeric" argument="--range 1-65535"/>.
Diffstat (limited to 'src/validators/range')
-rwxr-xr-x | src/validators/range | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/src/validators/range b/src/validators/range deleted file mode 100755 index d4c25f3c4..000000000 --- a/src/validators/range +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (C) 2021 VyOS maintainers and contributors -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 or later as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -import re -import sys -import argparse - -class MalformedRange(Exception): - pass - -def validate_range(value, min=None, max=None): - try: - lower, upper = re.match(r'^(\d+)-(\d+)$', value).groups() - - lower, upper = int(lower), int(upper) - - if int(lower) > int(upper): - raise MalformedRange("the lower bound exceeds the upper bound".format(value)) - - if min is not None: - if lower < min: - raise MalformedRange("the lower bound must not be less than {}".format(min)) - - if max is not None: - if upper > max: - raise MalformedRange("the upper bound must not be greater than {}".format(max)) - - except (AttributeError, ValueError): - raise MalformedRange("range syntax error") - -parser = argparse.ArgumentParser(description='Range validator.') -parser.add_argument('--min', type=int, action='store') -parser.add_argument('--max', type=int, action='store') -parser.add_argument('value', action='store') - -if __name__ == '__main__': - args = parser.parse_args() - - try: - validate_range(args.value, min=args.min, max=args.max) - except MalformedRange as e: - print("Incorrect range '{}': {}".format(args.value, e)) - sys.exit(1) |