From: Rob van der Linde Date: Thu, 5 Oct 2023 01:30:20 +0000 (+1300) Subject: python: move Validator base class and ValidationError to getopt X-Git-Tag: talloc-2.4.2~1140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc513a82a6a2795b22820146ca583cbe169a7499;p=thirdparty%2Fsamba.git python: move Validator base class and ValidationError to getopt It makes more sense for these to exist in the top package, because they are used by SambaOption. validators.py can still exist in netcmd, just not the base class and exception. Signed-off-by: Rob van der Linde Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/getopt.py b/python/samba/getopt.py index ea1f338d04c..04cae4cce78 100644 --- a/python/samba/getopt.py +++ b/python/samba/getopt.py @@ -22,6 +22,7 @@ __docformat__ = "restructuredText" import optparse import os import sys +from abc import ABCMeta, abstractmethod from copy import copy from samba.credentials import ( @@ -74,6 +75,17 @@ def check_bytes(option, opt, value): raise optparse.OptionValueError(msg) +class ValidationError(Exception): + pass + + +class Validator(metaclass=ABCMeta): + + @abstractmethod + def __call__(self, field, value): + pass + + class SambaOption(optparse.Option): ATTRS = optparse.Option.ATTRS + ["validators"] TYPES = optparse.Option.TYPES + ("bytes",) diff --git a/python/samba/netcmd/validators.py b/python/samba/netcmd/validators.py index c8c5697d23f..5690341df5b 100644 --- a/python/samba/netcmd/validators.py +++ b/python/samba/netcmd/validators.py @@ -20,18 +20,7 @@ # along with this program. If not, see . # -from abc import ABCMeta, abstractmethod - - -class ValidationError(Exception): - pass - - -class Validator(metaclass=ABCMeta): - - @abstractmethod - def __call__(self, field, value): - pass +from samba.getopt import Validator, ValidationError class Range(Validator):