<commit_before>from django import template


class ComparisonNode(template.Node):
    def __init__(self, var1, var2, comparison, nodelist_true, nodelist_false):
        self.var1, self.var2 = var1, var2
        self.comparison = comparison
        self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false
    
    def render(self, context):
        # Resolving the variables to compare is a bit verbose,
        # but it has to be for this to work.
        try:
            # First, try to resolve as a template variable.
            var1 = template.resolve_variable(self.var1, context)
        except template.VariableDoesNotExist:
            # Maybe it's a number.
            if self.var1.isdigit():
                var1 = int(self.var1)
            # Not a variable or a number; keep it as-is.
            else:
                var1 = self.var1
        # And now we do it all over again for the second one.
        try:
            var2 = template.resolve_variable(self.var2, context)
        except template.VariableDoesNotExist:
            if self.var2.isdigit():
                var2 = int(self.var2)
            else:
                var2 = self.var2
        comparison = cmp(var1, var2)
        result_dict = {
            'less': comparison < 0,
            'less_or_equal': comparison <= 0,
            'greater_or_equal': comparison >= 0,
            'greater': comparison > 0
            }
        if result_dict[self.comparison]:
            return self.nodelist_true.render(context)
        else:
            return self.nodelist_false.render(context)


def do_comparison(parser, token):
    """
    Compares two values.
    
    Syntax::
    
        {% if_[comparison] [var1] [var2] %}<commit_msg>Remove superfluous 'else'<commit_after>from django import template


class ComparisonNode(template.Node):
    def __init__(self, var1, var2, comparison, nodelist_true, nodelist_false):
        self.var1, self.var2 = var1, var2
        self.comparison = comparison
        self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false
    
    def render(self, context):
        # Resolving the variables to compare is a bit verbose,
        # but it has to be for this to work.
        try:
            # First, try to resolve as a template variable.
            var1 = template.resolve_variable(self.var1, context)
        except template.VariableDoesNotExist:
            # Maybe it's a number.
            if self.var1.isdigit():
                var1 = int(self.var1)
            # Not a variable or a number; keep it as-is.
            else:
                var1 = self.var1
        # And now we do it all over again for the second one.
        try:
            var2 = template.resolve_variable(self.var2, context)
        except template.VariableDoesNotExist:
            if self.var2.isdigit():
                var2 = int(self.var2)
            else:
                var2 = self.var2
        comparison = cmp(var1, var2)
        result_dict = {
            'less': comparison < 0,
            'less_or_equal': comparison <= 0,
            'greater_or_equal': comparison >= 0,
            'greater': comparison > 0
            }
        if result_dict[self.comparison]:
            return self.nodelist_true.render(context)
        return self.nodelist_false.render(context)


def do_comparison(parser, token):
    """
    Compares two values.
    
    Syntax::
    
        {% if_[comparison] [var1] [var2] %}
{'fraction_non_alphanumeric': 0.08709490740740741, 'fraction_numerical': 0.016203703703703703, 'mean_word_length': 1.8665008291873963, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6929747', 'n_tokens_mistral': 1029, 'n_tokens_neox': 968, 'n_words': 273}