Exemple #1
0
    def load_config_section(cls, manager, section, *args, **kwargs):
        """
        Load a new instance from a config section on behalf of a config loader.

        :param manager: An attila.configurations.ConfigManager instance.
        :param section: The name of the section being loaded.
        :return: An instance of this type.
        """
        verify_type(manager, ConfigManager)
        assert isinstance(manager, ConfigManager)

        verify_type(section, str, non_empty=True)

        server = manager.load_option(section, 'Server', str)
        port = manager.load_option(section, 'Port', int, None)
        # credential = manager.load_section(section, credentials.Credential)

        if port is not None:
            server = '%s:%s' % (server, port)

        return super().load_config_section(
            manager,
            section,
            *args,
            server=server,
            # credential=credential,
            **kwargs)
Exemple #2
0
    def load_config_section(cls, manager, section, *args, **kwargs):
        """
        Load a class instance from a config section.

        :param manager: A ConfigManager instance.
        :param section: The name of the section.
        :return: A new instance of this class.
        """
        verify_type(manager, ConfigManager)
        assert isinstance(manager, ConfigManager)
        verify_type(section, str, non_empty=True)

        path = manager.load_option(section, 'Path', Path)
        mode = manager.load_option(section, 'Mode', str, 'a')
        encoding = manager.load_option(section, 'Encoding', str, None)
        delay = manager.load_option(section, 'Delay', 'bool', False)

        return super().load_config_section(manager,
                                           section,
                                           *args,
                                           filename=str(abs(path)),
                                           mode=mode,
                                           encoding=encoding,
                                           delay=delay,
                                           **kwargs)
Exemple #3
0
    def __init__(self, server, initial_cwd=None):
        verify_type(server, str, non_empty=True)
        server, port = strings.split_port(server, DEFAULT_HTTPS_PORT)

        super().__init__(https_connection, initial_cwd)

        self._server = server
        self._port = port
Exemple #4
0
    def load_config_value(cls, manager, value, *args, **kwargs):
        """
        Load a class instance from the value of a config option.

        :param manager: A ConfigManager instance.
        :param value: The string value of the option.
        :return: A new instance of this class.
        """
        verify_type(value, str, non_empty=True)
        path = Path.load_config_value(manager, value, *args, **kwargs)
        return cls(*args, filename=str(abs(path)), **kwargs)
Exemple #5
0
    def load_config_section(cls, manager, section, *args, **kwargs):
        """
        Load a class instance from a config section.

        :param manager: A ConfigManager instance.
        :param section: The name of the section.
        :return: A new instance of this class.
        """
        verify_type(manager, ConfigManager)
        assert isinstance(manager, ConfigManager)
        verify_type(section, str, non_empty=True)

        host = manager.load_option(section, 'Host', str)
        verify_type(host, str, non_empty=True)

        host, port = split_port(host,
                                logging.handlers.DEFAULT_TCP_LOGGING_PORT)
        verify_type(host, str, non_empty=True)

        return super().load_config_section(manager,
                                           section,
                                           *args,
                                           host=host,
                                           port=port,
                                           **kwargs)
Exemple #6
0
    def load_config_value(cls, manager, value, *args, **kwargs):
        """
        Load a class instance from the value of a config option.

        :param manager: A ConfigManager instance.
        :param value: The string value of the option.
        :return: A new instance of this class.
        """
        verify_type(value, str, non_empty=True)

        host, port = split_port(value,
                                logging.handlers.DEFAULT_TCP_LOGGING_PORT)
        verify_type(host, str, non_empty=True)

        return cls(*args, host=host, port=port, **kwargs)
Exemple #7
0
    def load_config_section(cls, manager, section, *args, **kwargs):
        """
        Load a class instance from a config section.

        :param manager: A ConfigManager instance.
        :param section: The name of the section.
        :return: A new instance of this class.
        """
        verify_type(manager, ConfigManager)
        assert isinstance(manager, ConfigManager)
        verify_type(section, str, non_empty=True)

        format_string = manager.load_option(section, 'Format', str, None)
        date_format = manager.load_option(section, 'Date Format', str, None)
        style = manager.load_option(section, 'Style', str, '%')

        return cls(*args,
                   fmt=format_string,
                   datefmt=date_format,
                   style=style,
                   **kwargs)
Exemple #8
0
    def load_config_section(cls, manager, section, *args, **kwargs):
        """
        Load a class instance from a config section.

        :param manager: A ConfigManager instance.
        :param section: The name of the section.
        :return: A new instance of this class.
        """
        verify_type(manager, ConfigManager)
        assert isinstance(manager, ConfigManager)
        verify_type(section, str, non_empty=True)

        formatter = manager.load_option(section, 'Format', LogFormat, None)
        verify_type(formatter, LogFormat, allow_none=True)
        if formatter is None:
            formatter = LogFormat()

        level = manager.load_option(section, 'Level', 'log_level',
                                    logging.INFO)

        result = cls(*args, **kwargs)

        result.formatter = formatter
        result.level = level

        return result
Exemple #9
0
    def load_url(cls, manager, url):
        """
        Load a new Path instance from a URL string.

        The standard format for an HTTPS URL is "https://*****:*****@' not in netloc, "Embedded credentials not currently supported for HTTPS."

        # TODO: Support login credentials someday?
        # user, address = netloc.split('@')
        # # We do not permit passwords to be stored in plaintext in the parameter value.
        # assert ':' not in user

        address = netloc

        if ':' in address:
            server, port = address.split(':')
            port = int(port)
        else:
            server = address
            port = DEFAULT_HTTPS_PORT

        # credential_string = '%s@%s/https' % (user, server)
        # credential = manager.load_value(credential_string, credentials.Credential)

        return Path(path + '?' + query,
                    cls('%s:%s' % (server, port)).connect())
Exemple #10
0
    def load_config_section(cls, manager, section, *args, **kwargs):
        """
        Load a class instance from a config section.

        :param manager: A ConfigManager instance.
        :param section: The name of the section.
        :return: A new instance of this class.
        """
        verify_type(manager, ConfigManager)
        assert isinstance(manager, ConfigManager)
        verify_type(section, str, non_empty=True)

        name = manager.load_option(section, 'Name', str)
        verify_type(name, str, non_empty=True)

        level = manager.load_option(section, 'Level', 'log_level',
                                    logging.NOTSET)

        handlers = manager.load_option(section, 'Handlers', 'list')
        for index, handler_name in enumerate(handlers):
            handler = manager.load_section(handler_name)
            verify_type(handler, LogHandler)
            handlers[index] = handler

        if name == 'root':
            result = logging.root
        else:
            result = logging.getLogger(name)
            propagate = manager.load_option(section, 'Propagate', 'bool', True)
            result.propagate = propagate

        result.level = level

        for handler in handlers:
            result.addHandler(handler)

        return result