VaKeR CYBER ARMY
Logo of a company Server : Apache
System : Linux host44.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64
User : vapecompany ( 2719)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /opt/cloudlinux/venv/lib/python3.11/site-packages/setoptconf/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/setoptconf/config.py
from .exception import MissingRequiredError, ReadOnlyError


__all__ = ("Configuration",)


class Configuration:
    def __init__(self, settings, parent=None):
        self.__dict__["_parent"] = parent

        self.__dict__["_settings"] = {}
        for setting in settings:
            self._settings[setting.name] = setting

    def validate_setting(self, name):
        if name in self._settings:
            setting = self._settings[name]
            if setting.required and not setting.established:
                if self._parent:
                    self._parent.validate_setting(name)
                else:
                    raise MissingRequiredError(name)
        elif self._parent:
            self._parent.validate_setting(name)
        else:
            raise AttributeError('No such setting "%s"' % name)

    def validate(self):
        for name in self:
            self.validate_setting(name)

    def __getattr__(self, name):
        if name in self._settings:
            if self._settings[name].established:
                return self._settings[name].value
            elif self._parent:
                return getattr(self._parent, name)
            else:
                return self._settings[name].default
        elif self._parent:
            return getattr(self._parent, name)
        else:
            raise AttributeError('No such setting "%s"' % name)

    def __getitem__(self, key):
        return getattr(self, key)

    def __setattr__(self, name, value):
        raise ReadOnlyError("Cannot change the value of settings")

    def __setitem__(self, key, value):
        setattr(self, key, value)

    def __delattr__(self, name):
        raise ReadOnlyError("Cannot delete settings")

    def __delitem__(self, key):
        delattr(self, key)

    def __iter__(self):
        all_names = set(self._settings.keys())
        if self._parent:
            all_names.update(iter(self._parent))
        return iter(all_names)

    def __len__(self):
        return len(list(iter(self)))

    def __contains__(self, item):
        return item in list(iter(self))

    def __str__(self):  # pragma: no cover
        return "Configuration(%s)" % (
            ", ".join([u"%s=%s" % (name, repr(self[name])) for name in self])
        )

    def __repr__(self):  # pragma: no cover
        return "<%s>" % str(self)

VaKeR 2022