PHP 8.2.30
Preview: setting.py Size: 1.67 KB
/opt/cloudlinux/venv/lib64/python3.11/site-packages/setoptconf/setting.py

# pylint: disable=W0401,W0223

import re

from .datatype import *
from .exception import NamingError


__all__ = (
    "Setting",
    "StringSetting",
    "IntegerSetting",
    "FloatSetting",
    "BooleanSetting",
    "ListSetting",
    "ChoiceSetting",
)


class Setting(DataType):
    RE_NAME = re.compile(r"^[a-z](?:[a-z0-9]|[_](?![_]))*[a-z0-9]$")

    def __init__(self, name, default=None, required=False):
        if Setting.RE_NAME.match(name):
            self.name = name
        else:
            raise NamingError(name)

        self._value = None
        self.default = self.sanitize(default)
        self.required = required
        self.established = False

    @property
    def value(self):
        return self._value

    @value.setter
    def value(self, value):
        self._value = self.sanitize(value)
        self.established = True

    def __str__(self):  # pragma: no cover
        return unicode(self.name)

    def __repr__(self):  # pragma: no cover
        return "<%s(%s=%s)>" % (
            self.__class__.__name__,
            self.name,
            self.value if self.established else "",
        )


class StringSetting(Setting, String):
    pass


class IntegerSetting(Setting, Integer):
    pass


class FloatSetting(Setting, Float):
    pass


class BooleanSetting(Setting, Boolean):
    pass


class ListSetting(Setting, List):
    def __init__(self, name, subtype, **kwargs):
        List.__init__(self, subtype)
        Setting.__init__(self, name, **kwargs)


class ChoiceSetting(Setting, Choice):
    def __init__(self, name, choices, subtype=None, **kwargs):
        Choice.__init__(self, choices, subtype=subtype)
        Setting.__init__(self, name, **kwargs)

Directory Contents

Dirs: 2 × Files: 7

Name Size Perms Modified Actions
source DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
2.29 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.03 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
372 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.10 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.67 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
241 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
188 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).