<commit_before>#import pytz
import six
import sqlalchemy as sa
from wtforms import Form
from wtforms.validators import (
    InputRequired, DataRequired, NumberRange, Length, Optional
)
from wtforms.form import FormMeta
from wtforms_components import (
    DateRange,
    Email,
    PhoneNumberField,
    SelectField,
    SelectMultipleField,
    Unique,
    TimeRange
)
from .utils import (
    is_date_column,
    is_scalar,
    null_or_int,
    null_or_unicode,
    ClassMap
)
from .exc import (
    AttributeTypeException,
    InvalidAttributeException,
    UnknownTypeException,
    UnknownConfigurationOption
)
from .fields import ModelFieldList, ModelFormField, CountryField
from .generator import FormGenerator


__all__ = (
    AttributeTypeException,
    CountryField,
    DateRange,
    InvalidAttributeException,
    ModelFieldList,
    ModelFormField,
    PhoneNumberField,
    SelectField,
    SelectMultipleField,
    Unique,
    UnknownTypeException,
    is_date_column,
    is_scalar,
    null_or_int,
    null_or_unicode,
)


__version__ = '0.12.5'


def model_form_meta_factory(base=FormMeta):
    """
    Create a new class usable as a metaclass for the
    :func:`model_form_factory`. You only need to concern yourself with this if
    you desire to have a custom metclass. Otherwise, a default class is
    created and is used as a metaclass on :func:`model_form_factory`.

    :param base: The base class to use for the meta class. This is an optional
                 parameter that defaults to :class:`.FormMeta`. If you want to
                 provide your own, your class must derive from this class and
                 not directly from ``type``.

    :return: A new class suitable as a metaclass for the actual model form.
             Therefore, it should be passed as the ``meta`` argument to
             :func:`model_form_factory`.

    Example usage:

    .. code-block:: python

        from wtforms.form import FormMeta


        class MyModelFormMeta(FormMeta):
            # do some metaclass magic here
            pass

        ModelFormMeta = model_form_meta_factory(MyModelFormMeta)
        ModelForm = model_form_factory(meta=ModelFormMeta)
    """

    class ModelFormMeta(base):
        """
        Meta class that overrides WTForms base meta class. The primary purpose
        of this class is allowing ModelForms use special configuration params
        under the 'Meta' class namespace.

        ModelForm classes inherit parent's Meta class properties.
        """
        def __init__(cls, *args, **kwargs):
            bases = []
            for class_ in cls.__mro__:
                if 'Meta' in class_.__dict__:
                    bases.append(getattr(class_, 'Meta'))

            cls.Meta = type('Meta', tuple(bases), {})

            base.__init__(cls, *args, **kwargs)

            if hasattr(cls.Meta, 'model') and cls.Meta.model:
                generator = cls.Meta.form_generator(cls)
                generator.create_form(cls)
    return ModelFormMeta

ModelFormMeta = model_form_meta_factory()


def model_form_factory(base=Form, meta=ModelFormMeta, **defaults):
    """
    Create a base class for all model forms to derive from.

    :param base: Class that should be used as a base for the returned class.
                 By default, this is WTForms's base class
                 :class:`wtforms.Form`.
<commit_msg>Fix py27 handling of meta class bases<commit_after>#import pytz
import six
import sqlalchemy as sa
from wtforms import Form
from wtforms.validators import (
    InputRequired, DataRequired, NumberRange, Length, Optional
)
from wtforms.form import FormMeta
from wtforms_components import (
    DateRange,
    Email,
    PhoneNumberField,
    SelectField,
    SelectMultipleField,
    Unique,
    TimeRange
)
from .utils import (
    is_date_column,
    is_scalar,
    null_or_int,
    null_or_unicode,
    ClassMap
)
from .exc import (
    AttributeTypeException,
    InvalidAttributeException,
    UnknownTypeException,
    UnknownConfigurationOption
)
from .fields import ModelFieldList, ModelFormField, CountryField
from .generator import FormGenerator


__all__ = (
    AttributeTypeException,
    CountryField,
    DateRange,
    InvalidAttributeException,
    ModelFieldList,
    ModelFormField,
    PhoneNumberField,
    SelectField,
    SelectMultipleField,
    Unique,
    UnknownTypeException,
    is_date_column,
    is_scalar,
    null_or_int,
    null_or_unicode,
)


__version__ = '0.12.5'


def model_form_meta_factory(base=FormMeta):
    """
    Create a new class usable as a metaclass for the
    :func:`model_form_factory`. You only need to concern yourself with this if
    you desire to have a custom metclass. Otherwise, a default class is
    created and is used as a metaclass on :func:`model_form_factory`.

    :param base: The base class to use for the meta class. This is an optional
                 parameter that defaults to :class:`.FormMeta`. If you want to
                 provide your own, your class must derive from this class and
                 not directly from ``type``.

    :return: A new class suitable as a metaclass for the actual model form.
             Therefore, it should be passed as the ``meta`` argument to
             :func:`model_form_factory`.

    Example usage:

    .. code-block:: python

        from wtforms.form import FormMeta


        class MyModelFormMeta(FormMeta):
            # do some metaclass magic here
            pass

        ModelFormMeta = model_form_meta_factory(MyModelFormMeta)
        ModelForm = model_form_factory(meta=ModelFormMeta)
    """

    class ModelFormMeta(base):
        """
        Meta class that overrides WTForms base meta class. The primary purpose
        of this class is allowing ModelForms use special configuration params
        under the 'Meta' class namespace.

        ModelForm classes inherit parent's Meta class properties.
        """
        def __init__(cls, *args, **kwargs):
            bases = []
            for class_ in cls.__mro__:
                if 'Meta' in class_.__dict__:
                    bases.append(getattr(class_, 'Meta'))

            if not object in bases:
                bases.append(object)

            cls.Meta = type('Meta', tuple(bases), {})

            base.__init__(cls, *args, **kwargs)

            if hasattr(cls.Meta, 'model') and cls.Meta.model:
                generator = cls.Meta.form_generator(cls)
                generator.create_form(cls)
    return ModelFormMeta

ModelFormMeta = model_form_meta_factory()


def model_form_factory(base=Form, meta=ModelFormMeta, **defaults):
    """
    Create a base class for all model forms to derive from.

    :param base: Class that should be used as a base for the returned class.
                 By default, this is WTForms's base class
                 :class:`wtforms.Form`.

{'fraction_non_alphanumeric': 0.06812227074235808, 'fraction_numerical': 0.001455604075691412, 'mean_word_length': 2.58798955613577, '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': '5909640', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1830, 'n_words': 628}