<commit_before>import requests
import yaml
from collections import OrderedDict

from shellfoundry.models.shell_template import ShellTemplate

TEMPLATES_YML = 'https://raw.github.com/QualiSystems/shellfoundry/master/templates.yml'


class TemplateRetriever(object):
    def get_templates(self):
        """
        :return: Dictionary of shellfoundry.ShellTemplate
        """
        response = self._get_templates_from_github()
        config = yaml.load(response)
        if not config or 'templates' not in config:
            return []

        templatesdic = OrderedDict()
        for template in config['templates']:
            templatesdic[template['name']] = ShellTemplate(
                template['name'],
                template['description'],
                template['repository'],
                template['params'])

        return templatesdic

    @staticmethod
    def _get_templates_from_github():
        return requests.get(TEMPLATES_YML).text


class FilteredTemplateRetriever(object):
    def __init__(self, template_type, template_retriever=None):
        self.template_type = template_type
        self.template_retriever = template_retriever or TemplateRetriever()

    def get_templates(self):
        templates = self.template_retriever.get_templates()
        if self.template_type is None or self.template_type == 'all':
            return templates
        return OrderedDict((k, v) for k, v in templates.iteritems() if self._filter(k))

    def _filter(self, template_name):
        if self.template_type == 'tosca':
            return self._filter_out_legacy_template(template_name)
        return self._filter_out_tosca_template(template_name)

    def _filter_out_legacy_template(self, template_name):<commit_msg>increasing max retires<commit_after>import requests
import yaml
from collections import OrderedDict

from shellfoundry.models.shell_template import ShellTemplate

TEMPLATES_YML = 'https://raw.github.com/QualiSystems/shellfoundry/master/templates.yml'


class TemplateRetriever(object):
    def get_templates(self):
        """
        :return: Dictionary of shellfoundry.ShellTemplate
        """
        response = self._get_templates_from_github()
        config = yaml.load(response)
        if not config or 'templates' not in config:
            return []

        templatesdic = OrderedDict()
        for template in config['templates']:
            templatesdic[template['name']] = ShellTemplate(
                template['name'],
                template['description'],
                template['repository'],
                template['params'])

        return templatesdic

    @staticmethod
    def _get_templates_from_github():
        session = requests.Session()
        session.mount('https://', requests.adapters.HTTPAdapter(max_retries=5))
        return session.get(TEMPLATES_YML).text


class FilteredTemplateRetriever(object):
    def __init__(self, template_type, template_retriever=None):
        self.template_type = template_type
        self.template_retriever = template_retriever or TemplateRetriever()

    def get_templates(self):
        templates = self.template_retriever.get_templates()
        if self.template_type is None or self.template_type == 'all':
            return templates
        return OrderedDict((k, v) for k, v in templates.iteritems() if self._filter(k))

    def _filter(self, template_name):
        if self.template_type == 'tosca':
            return self._filter_out_legacy_template(template_name)
        return self._filter_out_tosca_template(template_name)

    def _filter_out_legacy_template(self, template_name):
{'fraction_non_alphanumeric': 0.08877860490763717, 'fraction_numerical': 0.00027570995312930797, 'mean_word_length': 3.0855855855855854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, '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': '2548899', 'n_tokens_mistral': 1003, 'n_tokens_neox': 969, 'n_words': 209}