@staticmethod
def _validate_config(config):
    """Validate that the provided configurtion is valid.

        Each dictionary in the configuration list must have the following
        mandatory entries :
            {label: {host(string), port(int), dbpath(string|list of strings)}}
        It can also contain 1 optional key:
            {read_preference(string)}

        Args:
            config: the list of configurations provided at instantiation

        Raises:
            TypeError: a fault in the configurations is found
        """
    if not isinstance(config, list):
        raise TypeError('Config must be a list')
    for config_dict in config:
        if not isinstance(config_dict, dict):
            raise TypeError('Config must be a list of dictionaries')
        label = config_dict.keys()[0]
        cfg = config_dict[label]
        if not isinstance(cfg, dict):
            raise TypeError('Config structure is broken')
        if 'host' not in cfg:
            raise TypeError('Config entries must have a value for host')
        if not isinstance(cfg['host'], str) and not isinstance(cfg['host'],
            list):
            raise TypeError('Host must be a string or a list.')
        if 'port' not in cfg:
            raise TypeError('Config entries must have a value for port')
        if not isinstance(cfg['port'], int):
            raise TypeError('Port must be an int')
        if 'dbpath' not in cfg:
            raise TypeError('Config entries must have a value for dbpath')
        if not isinstance(cfg['dbpath'], str):
            if not isinstance(cfg['dbpath'], list):
                raise TypeError(
                    'Dbpath must either a string or a list of strings')
            for dbpath in cfg['dbpath']:
                if not isinstance(dbpath, str):
                    raise TypeError(
                        'Dbpath must either a string or a list of strings')
        if 'read_preference' in cfg and not isinstance(cfg[
            'read_preference'], str):
            raise TypeError('Read_preference must be a string')
        if 'replicaSet' in cfg and not isinstance(cfg['replicaSet'], str):
            raise TypeError('replicaSet must be a string')
