$39 GRAYBYTE WORDPRESS FILE MANAGER $79

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/setoptconf/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/setoptconf//datatype.py
from .exception import DataTypeError


__all__ = ("DataType", "String", "Integer", "Float", "Boolean", "List", "Choice")


class DataType(object):
    def sanitize(self, value):
        raise NotImplementedError()

    def is_valid(self, value):
        try:
            self.sanitize(value)
        except DataTypeError:
            return False
        else:
            return True


class String(DataType):
    def sanitize(self, value):
        return None if value is None else str(value)


class Integer(DataType):
    def sanitize(self, value):
        if value is not None:
            try:
                value = int(value)
            except:
                raise DataTypeError('"%s" is not valid Integer' % value)
        return value


class Float(DataType):
    def sanitize(self, value):
        if value is not None:
            try:
                value = float(value)
            except:
                raise DataTypeError('"%s" is not valid Float' % value)
        return value


class Boolean(DataType):
    TRUTHY_STRINGS = ("Y", "YES", "T", "TRUE", "ON", "1")
    FALSY_STRINGS = ("", "N", "NO", "F", "FALSE", "OFF", "0")

    def sanitize(self, value):
        if value is None or isinstance(value, bool):
            return value

        if isinstance(value, int):
            return True if value else False

        if isinstance(value, str) and value:
            value = value.strip().upper()
            if value in self.TRUTHY_STRINGS:
                return True
            elif value in self.FALSY_STRINGS:
                return False
            else:
                raise DataTypeError('Could not coerce "%s" to a Boolean' % (value,))

        return True if value else False


class List(DataType):
    def __init__(self, subtype):
        super(List, self).__init__()
        if isinstance(subtype, DataType):
            self.subtype = subtype
        elif isinstance(subtype, type) and issubclass(subtype, DataType):
            self.subtype = subtype()
        else:
            raise TypeError("subtype must be a DataType")

    def sanitize(self, value):
        if value is None:
            return value

        if not isinstance(value, (list, tuple)):
            value = [value]

        value = [self.subtype.sanitize(v) for v in value]

        return value


class Choice(DataType):
    def __init__(self, choices, subtype=None):
        super(Choice, self).__init__()

        subtype = subtype or String()
        if isinstance(subtype, DataType):
            self.subtype = subtype
        elif isinstance(subtype, type) and issubclass(subtype, DataType):
            self.subtype = subtype()
        else:
            raise TypeError("subtype must be a DataType")

        self.choices = choices

    def sanitize(self, value):
        if value is None:
            return value

        value = self.subtype.sanitize(value)

        if value not in self.choices:
            raise DataTypeError(
                '"%s" is not one of (%s)'
                % (value, ", ".join([repr(c) for c in self.choices]))
            )

        return value

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
17 Dec 2025 3.08 AM
root / root
0755
__pycache__
--
14 Aug 2025 9.24 PM
root / root
0755
source
--
14 Aug 2025 9.24 PM
root / root
0755
__init__.py
0.184 KB
17 Apr 2025 8.10 PM
root / root
0644
config.py
2.29 KB
17 Apr 2025 8.10 PM
root / root
0644
datatype.py
3.033 KB
17 Apr 2025 8.10 PM
root / root
0644
exception.py
0.363 KB
17 Apr 2025 8.10 PM
root / root
0644
manager.py
1.096 KB
17 Apr 2025 8.10 PM
root / root
0644
setting.py
1.669 KB
17 Apr 2025 8.10 PM
root / root
0644
util.py
0.235 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF