<commit_before>import re
from django.conf import settings
from django.template import Library, TemplateSyntaxError
from sorl.thumbnail import default
from sorl.thumbnail.images import DummyImageFile
from sorl.thumbnail.templatetags.thumbnail import ThumbnailNode


register = Library()

kw_pat = re.compile(r'^(?P<key>[\w]+)=(?P<value>.+)$')


class UseThumbnailNode(ThumbnailNode):
    error_msg = 'Syntax error. Expected: ' \
                '``usethumbnail source thumbname as var``'

    def __init__(self, parser, token):
        bits = token.split_contents()
        if len(bits) != 5 or bits[-2] != 'as':
            raise TemplateSyntaxError(self.error_msg)
        self.file_ = parser.compile_filter(bits[1])
        self.geometry = parser.compile_filter(bits[2])
        self.options = {}
        self.as_var = bits[-1]
        self.nodelist_file = parser.parse(('empty', 'endusethumbnail',))
        if parser.next_token().contents == 'empty':
            self.nodelist_empty = parser.parse(('endusethumbnail',))
            parser.delete_first_token()

    def _render(self, context):
        file_ = self.file_.resolve(context)
        geometry, options = file_.field.thumbs.get(geometry)
        thumbnail = get_thumbnail(file_, geometry, **options)

        if not thumbnail or (isinstance(thumbnail, DummyImageFile) and
                             self.nodelist_empty):
            if self.nodelist_empty:
                return self.nodelist_empty.render(context)
            else:
                return ''

        if self.as_var:
            context.push()
            context[self.as_var] = thumbnail
            output = self.nodelist_file.render(context)
            context.pop()
        else:
            output = thumbnail.url

        return output

    def __repr__(self):
        return "<UseThumbnailNode>"


@register.tag
def usethumbnail(parser, token):
    return UseThumbnailNode(parser, token)<commit_msg>Bug fix for templatetag<commit_after>import re
from django.conf import settings
from django.template import Library, TemplateSyntaxError
from sorl.thumbnail import default
from sorl.thumbnail.images import DummyImageFile
from sorl.thumbnail.templatetags.thumbnail import ThumbnailNode


register = Library()

kw_pat = re.compile(r'^(?P<key>[\w]+)=(?P<value>.+)$')


class UseThumbnailNode(ThumbnailNode):
    error_msg = 'Syntax error. Expected: ' \
                '``usethumbnail source thumbname as var``'

    def __init__(self, parser, token):
        bits = token.split_contents()
        if len(bits) != 5 or bits[-2] != 'as':
            raise TemplateSyntaxError(self.error_msg)
        self.file_ = parser.compile_filter(bits[1])
        self.geometry = parser.compile_filter(bits[2])
        self.options = {}
        self.as_var = bits[-1]
        self.nodelist_file = parser.parse(('empty', 'endusethumbnail',))
        if parser.next_token().contents == 'empty':
            self.nodelist_empty = parser.parse(('endusethumbnail',))
            parser.delete_first_token()

    def _render(self, context):
        file_ = self.file_.resolve(context)
        geometry = self.geometry.resolve(context)
        geometry, options = file_.field.thumbs.get(geometry)
        thumbnail = get_thumbnail(file_, geometry, **options)

        if not thumbnail or (isinstance(thumbnail, DummyImageFile) and
                             self.nodelist_empty):
            if self.nodelist_empty:
                return self.nodelist_empty.render(context)
            else:
                return ''

        if self.as_var:
            context.push()
            context[self.as_var] = thumbnail
            output = self.nodelist_file.render(context)
            context.pop()
        else:
            output = thumbnail.url

        return output

    def __repr__(self):
        return "<UseThumbnailNode>"


@register.tag
def usethumbnail(parser, token):
    return UseThumbnailNode(parser, token)
{'fraction_non_alphanumeric': 0.10882800608828005, 'fraction_numerical': 0.0025367833587011668, 'mean_word_length': 2.5618789521228544, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3624073', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1136, 'n_words': 240}