Exemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        def get_argument_dict(args, kwargs):
            if len(args) == 1 and not kwargs:
                # User can also pass in a dict for their settings
                # Note: you could do that anyway, with the ** syntax
                return args[0]
            return kwargs

        self.__name__ = "{}.{}".format(self.__module__, self.__class__.__name__)

        settings = self.flatten_settings(self.settings)

        sm = KeyConstraintDict(settings, self.required)
        settings_source = get_argument_dict(args, kwargs)

        protected = self.get_protected_settings(settings_source)
        settings_source.update(protected)

        try:
            sm.update(settings_source)
        except KeyError as exc:
            raise ConfigKeyError(type(self).__name__, key=exc.args[0]) from exc

        try:
            self.__dict__.update(sm)
        except KeyConstraintDict.MissingKeys as exc:
            raise ConfigMissingError(
                type(self).__name__, missing=exc.keys) from exc

        self.logger = logging.getLogger(self.__name__)
        self.logger.setLevel(self.log_level)
        self.init()
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        def get_argument_dict(args, kwargs):
            if len(args) == 1 and not kwargs:
                # User can also pass in a dict for their settings
                # Note: you could do that anyway, with the ** syntax
                return args[0]
            return kwargs

        self.settings = self.flatten_settings(self.settings)

        sm = KeyConstraintDict(self.settings, self.required)
        settings_source = get_argument_dict(args, kwargs)

        try:
            sm.update(settings_source)
        except KeyError as exc:
            raise ConfigKeyError(type(self).__name__, key=exc.args[0]) from exc

        try:
            self.__dict__.update(sm)
        except KeyConstraintDict.MissingKeys as exc:
            raise ConfigMissingError(
                type(self).__name__, missing=exc.keys) from exc

        self.__name__ = "{}.{}".format(
            self.__module__, self.__class__.__name__)

        self.init()
Exemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        def get_argument_dict(args, kwargs):
            if len(args) == 1 and not kwargs:
                # User can also pass in a dict for their settings
                # Note: you could do that anyway, with the ** syntax
                return args[0]
            return kwargs

        self.__name__ = "{}.{}".format(self.__module__, self.__class__.__name__)

        settings = self.flatten_settings(self.settings)

        sm = KeyConstraintDict(settings, self.required)
        settings_source = get_argument_dict(args, kwargs)

        protected = self.get_protected_settings(settings_source)
        settings_source.update(protected)

        try:
            sm.update(settings_source)
        except KeyError as exc:
            raise ConfigKeyError(type(self).__name__, key=exc.args[0]) from exc

        try:
            self.__dict__.update(sm)
        except KeyConstraintDict.MissingKeys as exc:
            raise ConfigMissingError(
                type(self).__name__, missing=exc.keys) from exc

        if self.__name__.startswith("i3pystatus"):
            self.logger = logging.getLogger(self.__name__)
        else:
            self.logger = logging.getLogger("i3pystatus." + self.__name__)
        self.logger.setLevel(self.log_level)
        self.init()
Exemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        def get_argument_dict(args, kwargs):
            if len(args) == 1 and not kwargs:
                # User can also pass in a dict for their settings
                # Note: you could do that anyway, with the ** syntax
                return args[0]
            return kwargs

        def merge_with_parents_settings():
            settings = tuple()
            # getmro returns base classes according to Method Resolution Order
            for cls in inspect.getmro(self.__class__):
                if hasattr(cls, "settings"):
                    settings = settings + cls.settings
            return settings

        self.__name__ = "{}.{}".format(
            self.__module__, self.__class__.__name__)

        settings = merge_with_parents_settings()
        settings = self.flatten_settings(settings)

        sm = KeyConstraintDict(settings, self.required)
        settings_source = get_argument_dict(args, kwargs)

        protected = self.get_protected_settings(settings_source)
        settings_source.update(protected)

        try:
            sm.update(settings_source)
        except KeyError as exc:
            raise ConfigKeyError(type(self).__name__, key=exc.args[0]) from exc

        try:
            self.__dict__.update(sm)
        except KeyConstraintDict.MissingKeys as exc:
            raise ConfigMissingError(
                type(self).__name__, missing=exc.keys) from exc

        self.logger = logging.getLogger(self.__name__)
        self.logger.setLevel(self.log_level)
        self.init()