<commit_before>from django.core.exceptions import ObjectDoesNotExist
from django import oldforms
from django.core import validators
from django.db.models.fields import FileField, AutoField
from django.dispatch import dispatcher
from django.db.models import signals
from django.utils.functional import curry
from django.utils.datastructures import DotExpandedDict
from django.utils.text import capfirst
from django.utils.encoding import smart_str
from django.utils.translation import ugettext as _
import types

def add_manipulators(sender):
    cls = sender
    cls.add_to_class('AddManipulator', AutomaticAddManipulator)
    cls.add_to_class('ChangeManipulator', AutomaticChangeManipulator)

dispatcher.connect(add_manipulators, signal=signals.class_prepared)

class ManipulatorDescriptor(object):
    # This class provides the functionality that makes the default model
    # manipulators (AddManipulator and ChangeManipulator) available via the
    # model class.
    def __init__(self, name, base):
        self.man = None # Cache of the manipulator class.
        self.name = name
        self.base = base

    def __get__(self, instance, model=None):
        if instance != None:
            raise AttributeError, "Manipulator cannot be accessed via instance"
        else:
            if not self.man:
                # Create a class that inherits from the "Manipulator" class
                # given in the model class (if specified) and the automatic
                # manipulator.
                bases = [self.base]
                if hasattr(model, 'Manipulator'):
                    bases = [model.Manipulator] + bases
                self.man = types.ClassType(self.name, tuple(bases), {})
                self.man._prepare(model)
            return self.man

class AutomaticManipulator(oldforms.Manipulator):
    def _prepare(cls, model):
        cls.model = model
        cls.manager = model._default_manager
        cls.opts = model._meta
        for field_name_list in cls.opts.unique_together:
            setattr(cls, 'isUnique%s' % '_'.join(field_name_list), curry(manipulator_validator_unique_together, field_name_list, cls.opts))
        for f in cls.opts.fields:
            if f.unique_for_date:
                setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_date), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_date), cls.opts, 'date'))
            if f.unique_for_month:
                setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_month), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_month), cls.opts, 'month'))
            if f.unique_for_year:
                setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_year), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_year), cls.opts, 'year'))
    _prepare = classmethod(_prepare)

    def contribute_to_class(cls, other_cls, name):
        setattr(other_cls, name, ManipulatorDescriptor(name, cls))
    contribute_to_class = classmethod(contribute_to_class)

    def __init__(self, follow=None):<commit_msg>Fixed #5444 -- Changed manipulator class construction to use type(), rather than types.ClassType(). Helps with Jython compatibility. Patch from <NAME>.<commit_after>from django.core.exceptions import ObjectDoesNotExist
from django import oldforms
from django.core import validators
from django.db.models.fields import FileField, AutoField
from django.dispatch import dispatcher
from django.db.models import signals
from django.utils.functional import curry
from django.utils.datastructures import DotExpandedDict
from django.utils.text import capfirst
from django.utils.encoding import smart_str
from django.utils.translation import ugettext as _

def add_manipulators(sender):
    cls = sender
    cls.add_to_class('AddManipulator', AutomaticAddManipulator)
    cls.add_to_class('ChangeManipulator', AutomaticChangeManipulator)

dispatcher.connect(add_manipulators, signal=signals.class_prepared)

class ManipulatorDescriptor(object):
    # This class provides the functionality that makes the default model
    # manipulators (AddManipulator and ChangeManipulator) available via the
    # model class.
    def __init__(self, name, base):
        self.man = None # Cache of the manipulator class.
        self.name = name
        self.base = base

    def __get__(self, instance, model=None):
        if instance != None:
            raise AttributeError, "Manipulator cannot be accessed via instance"
        else:
            if not self.man:
                # Create a class that inherits from the "Manipulator" class
                # given in the model class (if specified) and the automatic
                # manipulator.
                bases = [self.base]
                if hasattr(model, 'Manipulator'):
                    bases = [model.Manipulator] + bases
                self.man = type(self.name, tuple(bases), {})
                self.man._prepare(model)
            return self.man

class AutomaticManipulator(oldforms.Manipulator):
    def _prepare(cls, model):
        cls.model = model
        cls.manager = model._default_manager
        cls.opts = model._meta
        for field_name_list in cls.opts.unique_together:
            setattr(cls, 'isUnique%s' % '_'.join(field_name_list), curry(manipulator_validator_unique_together, field_name_list, cls.opts))
        for f in cls.opts.fields:
            if f.unique_for_date:
                setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_date), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_date), cls.opts, 'date'))
            if f.unique_for_month:
                setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_month), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_month), cls.opts, 'month'))
            if f.unique_for_year:
                setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_year), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_year), cls.opts, 'year'))
    _prepare = classmethod(_prepare)

    def contribute_to_class(cls, other_cls, name):
        setattr(other_cls, name, ManipulatorDescriptor(name, cls))
    contribute_to_class = classmethod(contribute_to_class)

    def __init__(self, follow=None):
{'fraction_non_alphanumeric': 0.08885732323232323, 'fraction_numerical': 0.0006313131313131314, 'mean_word_length': 3.284651791751183, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '5373513', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1860, 'n_words': 457}