<commit_before>"""Template tags for emoticons app"""
import os
import binascii

from django import template
from django.utils.safestring import mark_safe
from django.utils.html import conditional_escape

from emoticons.settings import EMOTICONS_REGEXP
from emoticons.settings import EMOTICONS_DIRECTORY

register = template.Library()

EMOTICON_TEMPLATE = template.loader.get_template('emoticons/emoticon.html')


def replace_emoticons(content):
    """
    Replace the emoticons string by HTML images.
    """
    for emoticon, name, image in EMOTICONS_REGEXP:
        if emoticon.search(content):
            context = template.Context({
                'name': name,
                'code': binascii.hexlify(name),
                'image': os.path.join(EMOTICONS_DIRECTORY, image)})
            emoticon_html = EMOTICON_TEMPLATE.render(context).strip()
            content = emoticon.sub(emoticon_html, content)
    return content<commit_msg>Encode the name variable for having a buffer interface in Python 3<commit_after>"""Template tags for emoticons app"""
import os
import binascii

from django import template
from django.utils.safestring import mark_safe
from django.utils.html import conditional_escape

from emoticons.settings import EMOTICONS_REGEXP
from emoticons.settings import EMOTICONS_DIRECTORY

register = template.Library()

EMOTICON_TEMPLATE = template.loader.get_template('emoticons/emoticon.html')


def replace_emoticons(content):
    """
    Replace the emoticons string by HTML images.
    """
    for emoticon, name, image in EMOTICONS_REGEXP:
        if emoticon.search(content):
            context = template.Context({
                'name': name,
                'code': binascii.hexlify(name.encode('utf-8')),
                'image': os.path.join(EMOTICONS_DIRECTORY, image)})
            emoticon_html = EMOTICON_TEMPLATE.render(context).strip()
            content = emoticon.sub(emoticon_html, content)
    return content
{'fraction_non_alphanumeric': 0.08686765457332651, 'fraction_numerical': 0.001021972406745018, 'mean_word_length': 3.511520737327189, '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': '2478777', 'n_tokens_mistral': 584, 'n_tokens_neox': 566, 'n_words': 142}