<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from copy import copy
import os

from collections import OrderedDict
from contextlib import contextmanager
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, FieldDoesNotExist
from django.template.loader import select_template
from django.utils import translation
from django.views.generic import TemplateView
from django.views.i18n import set_language


FALLBACK_LANGUAGE_CODE = getattr(settings, 'FALLBACK_LANGUAGE_CODE', 'en')


def _normalize_language_code(language_code):
    """
    Makes sure the language code is not an empty string.
    """
    return (
        language_code or
        translation.get_language() or
        settings.LANGUAGE_CODE or
        FALLBACK_LANGUAGE_CODE
    )


def get_language(language_code=None):
    return _normalize_language_code(language_code).split("-")[0]


def get_language_order(languages=None):
    """
    Returns a copy of settings.LANGUAGES with the active language at the first position.
    """
    languages = languages or list(OrderedDict(settings.LANGUAGES).keys())
    languages.insert(0, languages.pop(languages.index(get_language())))
    return languages


# TODO Deprecated 'fieldname' parameter, use 'field_name'
def lang_suffix(language_code=None, field_name=None, fieldname=None):
    """
    Returns the suffix appropriate for adding to field names for selecting
    the current language.

    If fieldname is given, returns the suffixed fieldname.
    """
    language_code = _normalize_language_code(language_code or get_language()).split("-")[0]
    return "{}_{}".format(field_name or fieldname or "", language_code)


class DirectTemplateView(TemplateView):
    extra_context = None

    def get_context_data(self, **kwargs):
        context = super(DirectTemplateView, self).get_context_data(**kwargs)
        if self.extra_context is not None:
            for key, value in self.extra_context.items():
                if callable(value):
                    context[key] = value()
                else:
                    context[key] = value
        return context


class I18nDirectTemplateView(DirectTemplateView):
    def get_template_names(self):
        t_name, t_ext = os.path.splitext(self.template_name)
        lang = translation.get_language()
        template_name = select_template((
            "%s.%s%s" % (t_name, lang, t_ext),
            self.template_name
        )).name
        return [template_name]


        ])
        return [template.template.name]
<commit_msg>Updated template class ussage in I18nDirectTemplateView.<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from copy import copy
import os

from collections import OrderedDict
from contextlib import contextmanager
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, FieldDoesNotExist
from django.template.loader import select_template
from django.utils import translation
from django.views.generic import TemplateView
from django.views.i18n import set_language


FALLBACK_LANGUAGE_CODE = getattr(settings, 'FALLBACK_LANGUAGE_CODE', 'en')


def _normalize_language_code(language_code):
    """
    Makes sure the language code is not an empty string.
    """
    return (
        language_code or
        translation.get_language() or
        settings.LANGUAGE_CODE or
        FALLBACK_LANGUAGE_CODE
    )


def get_language(language_code=None):
    return _normalize_language_code(language_code).split("-")[0]


def get_language_order(languages=None):
    """
    Returns a copy of settings.LANGUAGES with the active language at the first position.
    """
    languages = languages or list(OrderedDict(settings.LANGUAGES).keys())
    languages.insert(0, languages.pop(languages.index(get_language())))
    return languages


# TODO Deprecated 'fieldname' parameter, use 'field_name'
def lang_suffix(language_code=None, field_name=None, fieldname=None):
    """
    Returns the suffix appropriate for adding to field names for selecting
    the current language.

    If fieldname is given, returns the suffixed fieldname.
    """
    language_code = _normalize_language_code(language_code or get_language()).split("-")[0]
    return "{}_{}".format(field_name or fieldname or "", language_code)


class DirectTemplateView(TemplateView):
    extra_context = None

    def get_context_data(self, **kwargs):
        context = super(DirectTemplateView, self).get_context_data(**kwargs)
        if self.extra_context is not None:
            for key, value in self.extra_context.items():
                if callable(value):
                    context[key] = value()
                else:
                    context[key] = value
        return context


class I18nDirectTemplateView(DirectTemplateView):
    def get_template_names(self):
        t_name, t_ext = os.path.splitext(self.template_name)
        lang = translation.get_language()
        template = select_template([
            "%s.%s%s" % (t_name, lang, t_ext),
            self.template_name
        ])
        return [template.template.name]

{'fraction_non_alphanumeric': 0.08707482993197278, 'fraction_numerical': 0.003498542274052478, 'mean_word_length': 3.4477095937770095, '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': '2945571', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1428, 'n_words': 380}