<commit_before>from django import http


class LegacyRedirectMiddleware(object):
    def process_request(self, request):
        """Redirect legacy links to new ones

        Currently this middleware handles these types of legacy links:

        - /ak/?doc=osd.html -> /ak/osd/

        - /naujienos/?id=naujiena_1047 -> /naujienos/naujiena_1047/

        """
        if request.path == '/naujienos/' and 'id' in request.GET:
            url = '/naujienos/%s/' % request.GET['id']
        elif 'doc' in request.GET:
            doc = request.GET['doc']
            tail = doc[:-5] if doc.endswith('.html') else doc
            url = '%s%s/' % (request.path, tail)
        else:
            url = None
        return url and http.HttpResponsePermanentRedirect(url)<commit_msg>Readability counts<commit_after>from django import http


class LegacyRedirectMiddleware(object):
    def process_request(self, request):
        """Redirect legacy links to new ones

        Currently this middleware handles these types of legacy links:

        - /ak/?doc=osd.html -> /ak/osd/

        - /naujienos/?id=naujiena_1047 -> /naujienos/naujiena_1047/

        """
        if request.path == '/naujienos/' and 'id' in request.GET:
            url = '/naujienos/%s/' % request.GET['id']
        elif 'doc' in request.GET:
            doc = request.GET['doc']
            tail = doc[:-5] if doc.endswith('.html') else doc
            url = '%s%s/' % (request.path, tail)
        else:
            url = None

        if url:
            return http.HttpResponsePermanentRedirect(url)
        else:
            return None
{'fraction_non_alphanumeric': 0.12437810945273632, 'fraction_numerical': 0.011194029850746268, 'mean_word_length': 2.0358490566037735, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3682414', 'n_tokens_mistral': 517, 'n_tokens_neox': 488, 'n_words': 125}