<commit_before>from django.http import HttpResponse
from exceptions import APIForbiddenException

FORMAT_PATTERN = "(\.(?P<emitter_format>.+))?"

class HttpResponseNotImplemented(HttpResponse):
    def __init__(self):
        super(HttpResponseNotImplemented, self).__init__(content='Not Implemented', content_type='text/plain', status=501)

DEFAULT_API_PREFIX = '/api'
DEFAULT_API_FORMATS = ('json', 'xml',)
DEFAULT_NONAPI_FORMATS = ('html',)

def default_formatter(request, *args, **kwargs):
    is_api = request.path.lower().startswith(DEFAULT_API_PREFIX)
    format = kwargs.get('emitter_format', None)
    if not format:
        if is_api:
            default = DEFAULT_API_FORMATS[0]
        else:
            default = DEFAULT_NONAPI_FORMATS[0]
        format = request.GET.get('format', default)
    
    if is_api:
        if format not in DEFAULT_API_FORMATS:
            raise APIForbiddenException(message="Format forbidden here: %s" % format)
    elif format not in DEFAULT_NONAPI_FORMATS:
        raise APIForbiddenException(message="Format forbidden here: %s" % format)
    return format
<commit_msg>Fixing pattern to restrict it to alphanumeric characters.<commit_after>from django.http import HttpResponse
from exceptions import APIForbiddenException

FORMAT_PATTERN = "(\.(?P<emitter_format>\w+))?"

class HttpResponseNotImplemented(HttpResponse):
    def __init__(self):
        super(HttpResponseNotImplemented, self).__init__(content='Not Implemented', content_type='text/plain', status=501)

DEFAULT_API_PREFIX = '/api'
DEFAULT_API_FORMATS = ('json', 'xml',)
DEFAULT_NONAPI_FORMATS = ('html',)

def default_formatter(request, *args, **kwargs):
    is_api = request.path.lower().startswith(DEFAULT_API_PREFIX)
    format = kwargs.get('emitter_format', None)
    if not format:
        if is_api:
            default = DEFAULT_API_FORMATS[0]
        else:
            default = DEFAULT_NONAPI_FORMATS[0]
        format = request.GET.get('format', default)
    if is_api:
        if format not in DEFAULT_API_FORMATS:
            raise APIForbiddenException(message="Format forbidden here: %s" % format)
    elif format not in DEFAULT_NONAPI_FORMATS:
        raise APIForbiddenException(message="Format forbidden here: %s" % format)
    return format

{'fraction_non_alphanumeric': 0.1052863436123348, 'fraction_numerical': 0.004405286343612335, 'mean_word_length': 4.138009049773756, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3989376', 'n_tokens_mistral': 676, 'n_tokens_neox': 668, 'n_words': 155}