<commit_before>import datetime
import os

import filer.models.clipboardmodels
from filer.utils.files import get_valid_filename

from django.core.files.uploadedfile import UploadedFile
from django.utils.encoding import force_unicode, smart_str


def by_date(instance, filename):
    datepart = force_unicode(datetime.datetime.now().strftime(smart_str("%Y/%m/%d")))
    return os.path.join(datepart, get_valid_filename(filename))


class prefixed_factory(object):
    def __init__(self, upload_to, prefix):
        self.upload_to = upload_to
        self.prefix = prefix

    def __call__(self, instance, filename):
        if callable(self.upload_to):
            upload_to_str = self.upload_to(instance, filename)
        else:
            upload_to_str = self.upload_to
        if not self.prefix:
            return upload_to_str
        return os.path.join(self.prefix, upload_to_str)


def _is_in_memory(file_):
    return isinstance(file_, UploadedFile)


def _construct_logical_folder_path(filer_file):
    return os.path.join(*(folder.name for folder in filer_file.logical_path))


def _goes_to_clipboard(instance):
    return instance.folder is None or (
        _is_in_memory(instance.file.file) and instance.pk is None)


def by_path(instance, filename):
    if _goes_to_clipboard(instance):
        return os.path.join(
            filer.models.clipboardmodels.Clipboard.folder_name,
            instance.owner.username,
            filename)
    else:<commit_msg>* there is no need to access the actual file if the file is already saved in the DB; this fix will make less IOErrors for filer files that have corrupted files or don't have a file at all<commit_after>import datetime
import os

import filer.models.clipboardmodels
from filer.utils.files import get_valid_filename

from django.core.files.uploadedfile import UploadedFile
from django.utils.encoding import force_unicode, smart_str


def by_date(instance, filename):
    datepart = force_unicode(datetime.datetime.now().strftime(smart_str("%Y/%m/%d")))
    return os.path.join(datepart, get_valid_filename(filename))


class prefixed_factory(object):
    def __init__(self, upload_to, prefix):
        self.upload_to = upload_to
        self.prefix = prefix

    def __call__(self, instance, filename):
        if callable(self.upload_to):
            upload_to_str = self.upload_to(instance, filename)
        else:
            upload_to_str = self.upload_to
        if not self.prefix:
            return upload_to_str
        return os.path.join(self.prefix, upload_to_str)


def _is_in_memory(file_):
    return isinstance(file_, UploadedFile)


def _construct_logical_folder_path(filer_file):
    return os.path.join(*(folder.name for folder in filer_file.logical_path))


def _goes_to_clipboard(instance):
    return instance.folder is None or (
        instance.pk is None and _is_in_memory(instance.file.file))


def by_path(instance, filename):
    if _goes_to_clipboard(instance):
        return os.path.join(
            filer.models.clipboardmodels.Clipboard.folder_name,
            instance.owner.username,
            filename)
    else:
{'fraction_non_alphanumeric': 0.08354673495518566, 'fraction_numerical': 0.0, 'mean_word_length': 3.5224312590448625, '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': '7198821', 'n_tokens_mistral': 960, 'n_tokens_neox': 939, 'n_words': 223}