<commit_before>"Wrapper for loading templates from storage of some sort (e.g. files or db)"
import template
from template_file import load_template_source

class ExtendsError(Exception):
    pass

def get_template(template_name):
    """
    Returns a compiled template.Template object for the given template name,
    handling template inheritance recursively.
    """
    return get_template_from_string(load_template_source(template_name))

def get_template_from_string(source):
    """
    Returns a compiled template.Template object for the given template code,
    handling template inheritance recursively.
    """
    return template.Template(source)

def render_to_string(template_name, dictionary=None, context_instance=None):
    """
    Loads the given template_name and renders it with the given dictionary as
    context. Returns a string.
    """
    dictionary = dictionary or {}
    t = get_template(template_name)
    if context_instance:
        context_instance.update(dictionary)
    else:
        context_instance = template.Context(dictionary)
    return t.render(context_instance)

def select_template(template_name_list):
    "Given a list of template names, returns the first that can be loaded."<commit_msg>Fixed #546 - render_to_string and render_to_response may now take lists of templates and use select_template instead of get_template.  Thanks, hugo<commit_after>"Wrapper for loading templates from storage of some sort (e.g. files or db)"
import template
from template_file import load_template_source

class ExtendsError(Exception):
    pass

def get_template(template_name):
    """
    Returns a compiled template.Template object for the given template name,
    handling template inheritance recursively.
    """
    return get_template_from_string(load_template_source(template_name))

def get_template_from_string(source):
    """
    Returns a compiled template.Template object for the given template code,
    handling template inheritance recursively.
    """
    return template.Template(source)

def render_to_string(template_name, dictionary=None, context_instance=None):
    """
    Loads the given template_name and renders it with the given dictionary as
    context. The template_name may be a string to load a single template using
    get_template, or it may be a tuple to use select_template to find one of
    the templates in the list.  Returns a string. 
    """
    dictionary = dictionary or {}
    if isinstance(template_name, (list, tuple)):
        t = select_template(template_name)
    else:
        t = get_template(template_name)
    if context_instance:
        context_instance.update(dictionary)
    else:
        context_instance = template.Context(dictionary)
    return t.render(context_instance)

def select_template(template_name_list):
    "Given a list of template names, returns the first that can be loaded."
{'fraction_non_alphanumeric': 0.06345353675450763, 'fraction_numerical': 0.0010402219140083217, 'mean_word_length': 4.161001788908766, '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': '4714198', 'n_tokens_mistral': 750, 'n_tokens_neox': 734, 'n_words': 267}