<commit_before>import urllib
from django import template
from django.conf import settings

register = template.Library()


@register.simple_tag
def convert_url(request, sourceurl, format='pdf'):
    fullurl = request.build_absolute_uri(sourceurl)
    conversion_url = "%s?url=%s&to=%s" % (settings.CONVERSION_SERVER,
                                          urllib.quote(fullurl),
                                          format)
    return conversion_url
<commit_msg>Support conversion format as extension, instead of mimetype<commit_after>import urllib
from mimetypes import types_map

from django import template
from django.conf import settings


register = template.Library()


@register.simple_tag
def convert_url(request, sourceurl, format='pdf'):
    if '/' not in format:
        extension = '.' + format if not format.startswith('.') else format
        format = types_map[extension]
    fullurl = request.build_absolute_uri(sourceurl)
    conversion_url = "%s?url=%s&to=%s" % (settings.CONVERSION_SERVER,
                                          urllib.quote(fullurl),
                                          format)
    return conversion_url

{'fraction_non_alphanumeric': 0.08714408973252805, 'fraction_numerical': 0.0, 'mean_word_length': 2.558282208588957, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4883595', 'n_tokens_mistral': 296, 'n_tokens_neox': 292, 'n_words': 76}