<commit_before>import requests
import json
import yaml


class ConfigClient(object):
    """Sets up the default configuration for the CellBase client"""
    def __init__(self, config_fpath=None):
        # Default config params
        self._hosts = ['bioinfo.hpc.cam.ac.uk:80/cellbase',
                       'bioinfodev.hpc.cam.ac.uk:80/cellbase-4.5.0-beta']
        self._config = {
            'host': self._get_available_host(),
            'version': 'v4',
            'species': 'hsapiens',
        }

        # If config file is provided, override default config params
        if config_fpath is not None:
            self._override_config_params(config_fpath)

    def _override_config_params(self, config_fpath):
        """Overrides config params if config file is provided"""
        config_fhand = open(config_fpath, 'r')

        config_dict = None
        if config_fpath.endswith('.yml') or config_fpath.endswith('.yaml'):
            config_dict = yaml.safe_load(config_fhand)

        if config_fpath.endswith('.json'):
            config_dict = json.loads(config_fhand.read())

        if config_dict is not None:
            if 'host' in config_dict['rest']:
                self._hosts = config_dict['rest']['hosts']
                self._config['host'] = self._get_available_host()
            if 'version' in config_dict:
                self._config['version'] = config_dict['version']
            if 'species' in config_dict:
                self._config['species'] = config_dict['species']

        config_fhand.close()

    def _get_available_host(self):
        """Returns the first available host"""
        available_host = None
        for host in self._hosts:
            try:
                r = requests.head('http://' + host)
                if r.status_code == 302:  # Found
                    available_host = host
                    break
            except requests.ConnectionError:
                pass

        if available_host is None:
            msg = 'No available host found'
            raise ConnectionError(msg)
        else:
            return available_host

    @property
    def version(self):
        return self._config['version']

    @version.setter
    def version(self, new_version):
        self._config['version'] = new_version

    @property
    def host(self):
        return self._config['host']

    @host.setter
    def host(self, new_host):
            self._config['host'] = new_host

    @property
    def species(self):
        return self._config['species']

    @species.setter
    def species(self, new_species):
            self._config['species'] = new_species

    @property
    def configuration(self):
        return self._config
<commit_msg>Fixed bug where config file info was not retrieved correctly<commit_after>import requests
import json
import yaml


class ConfigClient(object):
    """Sets up the default configuration for the CellBase client"""
    def __init__(self, config_fpath=None):
        # Default config params
        self._hosts = ['bioinfo.hpc.cam.ac.uk:80/cellbase',
                       'bioinfodev.hpc.cam.ac.uk:80/cellbase-4.5.0-beta']
        self._config = {
            'host': self._get_available_host(),
            'version': 'v4',
            'species': 'hsapiens',
        }

        # If config file is provided, override default config params
        if config_fpath is not None:
            self._override_config_params(config_fpath)

    def _override_config_params(self, config_fpath):
        """Overrides config params if config file is provided"""
        config_fhand = open(config_fpath, 'r')

        config_dict = None
        if config_fpath.endswith('.yml') or config_fpath.endswith('.yaml'):
            config_dict = yaml.safe_load(config_fhand)

        if config_fpath.endswith('.json'):
            config_dict = json.loads(config_fhand.read())

        if config_dict is not None:
            if 'hosts' in config_dict['rest']:
                self._hosts = config_dict['rest']['hosts']
                self._config['host'] = self._get_available_host()
            if 'version' in config_dict:
                self._config['version'] = config_dict['version']
            if 'species' in config_dict:
                self._config['species'] = config_dict['species']

        config_fhand.close()

    def _get_available_host(self):
        """Returns the first available host"""
        available_host = None
        for host in self._hosts:
            try:
                r = requests.head('http://' + host)
                if r.status_code == 302:  # Found
                    available_host = host
                    break
            except requests.ConnectionError:
                pass

        if available_host is None:
            msg = 'No available host found'
            raise ConnectionError(msg)
        else:
            return available_host

    @property
    def version(self):
        return self._config['version']

    @version.setter
    def version(self, new_version):
        self._config['version'] = new_version

    @property
    def host(self):
        return self._config['host']

    @host.setter
    def host(self, new_host):
            self._config['host'] = new_host

    @property
    def species(self):
        return self._config['species']

    @species.setter
    def species(self, new_species):
            self._config['species'] = new_species

    @property
    def configuration(self):
        return self._config

{'fraction_non_alphanumeric': 0.10258275736631503, 'fraction_numerical': 0.004001455074572572, 'mean_word_length': 2.0618040089086858, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1196850', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1477, 'n_words': 367}