<commit_before>import uuid

from django import forms
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from .models import UploadedFile
from . import settings as upload_settings


class UploadedFileForm(forms.ModelForm):

    ERRORS = {
        'max_filesize': _('The file is bigger than the maximum size allowed.'),
    }

    class Meta:
        model = UploadedFile
        fields = ('file',)

    def clean_file(self):
        data = self.cleaned_data['file']
        # Change the name of the file to something unguessable
        # Construct the new name as <unique-hex>-<original>.<ext>
        data.name = u'%s-%s' % (uuid.uuid4().hex, data.name)

        max_upload_size = getattr(settings, 'AJAX_UPLOAD_MAX_FILESIZE', upload_settings.DEFAULT_MAX_FILESIZE)
        if 0 < max_upload_size < data.size:
            raise forms.ValidationError(self.ERRORS['max_filesize'])

        return data<commit_msg>limit length of generated filenames<commit_after>import uuid
import os

from django import forms
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from .models import UploadedFile
from . import settings as upload_settings


class UploadedFileForm(forms.ModelForm):

    ERRORS = {
        'max_filesize': _('The file is bigger than the maximum size allowed.'),
    }

    class Meta:
        model = UploadedFile
        fields = ('file',)

    def clean_file(self):
        data = self.cleaned_data['file']
        # Change the name of the file to something unguessable
        # Construct the new name as <unique-hex>-<original>.<ext>
        original_name, ext = os.path.splitext(data.name)
        data.name = u'%s-%s%s' % (uuid.uuid4().hex, original_name[:32], ext[:4])

        max_upload_size = getattr(settings, 'AJAX_UPLOAD_MAX_FILESIZE', upload_settings.DEFAULT_MAX_FILESIZE)
        if 0 < max_upload_size < data.size:
            raise forms.ValidationError(self.ERRORS['max_filesize'])

        return data
{'fraction_non_alphanumeric': 0.09457441513190643, 'fraction_numerical': 0.003484320557491289, 'mean_word_length': 3.1875, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '5407106', 'n_tokens_mistral': 613, 'n_tokens_neox': 599, 'n_words': 165}