<commit_before># -*- coding: utf-8 -*-

import simplejson as json
import arrow
import inflection
import inspect
import uuid
from warnings import warn
from six import add_metaclass
from collections import OrderedDict
from ..utils import basestring, deprecated
from ..exceptions.orm import MassAssignmentError, RelatedClassNotFound
from ..query import QueryBuilder
from .builder import Builder
from .collection import Collection
from .relations import (
    Relation, HasOne, HasMany, BelongsTo, BelongsToMany, HasManyThrough,
    MorphOne, MorphMany, MorphTo, MorphToMany
)
from .relations.wrapper import Wrapper, BelongsToManyWrapper
from .utils import mutator, accessor
from .scopes import Scope
from ..events import Event


class ModelRegister(dict):

    def __init__(self, *args, **kwargs):
        self.inverse = {}

        super(ModelRegister, self).__init__(*args, **kwargs)

    def __setitem__(self, key, value):
        super(ModelRegister, self).__setitem__(key, value)

        self.inverse[value] = key

    def __delitem__(self, key):
        del self.inverse[self[key]]

        super(ModelRegister, self).__delitem__(key)


class MetaModel(type):

    __register__ = {}

    def __init__(cls, *args, **kwargs):
        name = cls.__table__ or inflection.tableize(cls.__name__)
        cls._register[name] = cls

        super(MetaModel, cls).__init__(*args, **kwargs)

    def __getattr__(cls, item):
        try:
            return type.__getattribute__(cls, item)
        except AttributeError:
            query = cls.query()

            return getattr(query, item)


@add_metaclass(MetaModel)
class Model(object):

    __connection__ = None

    __table__ = None

    __primary_key__ = 'id'

    __incrementing__ = True

    __fillable__ = []
    __guarded__ = ['*']
    __unguarded__ = False

    __hidden__ = []
    __visible__ = []
    __appends__ = []

    __timestamps__ = True
    __dates__ = []

    __casts__ = {}

    __touches__ = []

    __morph_name__ = None

    _per_page = 15

    _with = []

    _booted = {}
    _global_scopes = {}
    _registered = []

    _accessor_cache = {}
    _mutator_cache = {}

    __resolver = None
    __columns__ = []

    __dispatcher__ = Event()
    __observables__ = []

    _register = ModelRegister()

    __attributes__ = {}

    many_methods = ['belongs_to_many', 'morph_to_many', 'morphed_by_many']

    CREATED_AT = 'created_at'
    UPDATED_AT = 'updated_at'

    def __init__(self, _attributes=None, **attributes):
        """
        :param attributes: The instance attributes
        """
        self._boot_if_not_booted()

        self._exists = False
        self._original = {}

        # Setting default attributes' values
        self._attributes = dict((k, v) for k, v in self.__attributes__.items())
        self._relations = {}

        self.sync_original()

        if _attributes is not None:
            attributes.update(_attributes)

        self.fill(**attributes)

    def _boot_if_not_booted(self):
        """
        Check if the model needs to be booted and if so, do it.
        """
        klass = self.__class__

        if not klass._booted.get(klass):
            klass._booted[klass] = True

            self._fire_model_event('booting')

            klass._boot()

            self._fire_model_event('booted')

    @classmethod
    def _boot(cls):
        """
        The booting method of the model.
        """
        cls._accessor_cache[cls] = {}
        cls._mutator_cache[cls] = {}

        for name, method in cls.__dict__.items():
            if isinstance(method, accessor):
                cls._accessor_cache[cls][method.attribute] = method
            elif isinstance(method, mutator):
                cls._mutator_cache[cls][method.attribute] = method

        cls._boot_mixins()
        cls._boot_columns()

    @classmethod
    def _boot_columns(cls):
        connection = cls.resolve_connection()
        columns = connection.get_schema_manager().list_table_columns(cls.__table__ or inflection.tableize(cls.__name__))
        cls.__columns__ = list(columns.keys())<commit_msg>Removing the _boot_columns() call to avoid an error.<commit_after># -*- coding: utf-8 -*-

import simplejson as json
import arrow
import inflection
import inspect
import uuid
from warnings import warn
from six import add_metaclass
from collections import OrderedDict
from ..utils import basestring, deprecated
from ..exceptions.orm import MassAssignmentError, RelatedClassNotFound
from ..query import QueryBuilder
from .builder import Builder
from .collection import Collection
from .relations import (
    Relation, HasOne, HasMany, BelongsTo, BelongsToMany, HasManyThrough,
    MorphOne, MorphMany, MorphTo, MorphToMany
)
from .relations.wrapper import Wrapper, BelongsToManyWrapper
from .utils import mutator, accessor
from .scopes import Scope
from ..events import Event


class ModelRegister(dict):

    def __init__(self, *args, **kwargs):
        self.inverse = {}

        super(ModelRegister, self).__init__(*args, **kwargs)

    def __setitem__(self, key, value):
        super(ModelRegister, self).__setitem__(key, value)

        self.inverse[value] = key

    def __delitem__(self, key):
        del self.inverse[self[key]]

        super(ModelRegister, self).__delitem__(key)


class MetaModel(type):

    __register__ = {}

    def __init__(cls, *args, **kwargs):
        name = cls.__table__ or inflection.tableize(cls.__name__)
        cls._register[name] = cls

        super(MetaModel, cls).__init__(*args, **kwargs)

    def __getattr__(cls, item):
        try:
            return type.__getattribute__(cls, item)
        except AttributeError:
            query = cls.query()

            return getattr(query, item)


@add_metaclass(MetaModel)
class Model(object):

    __connection__ = None

    __table__ = None

    __primary_key__ = 'id'

    __incrementing__ = True

    __fillable__ = []
    __guarded__ = ['*']
    __unguarded__ = False

    __hidden__ = []
    __visible__ = []
    __appends__ = []

    __timestamps__ = True
    __dates__ = []

    __casts__ = {}

    __touches__ = []

    __morph_name__ = None

    _per_page = 15

    _with = []

    _booted = {}
    _global_scopes = {}
    _registered = []

    _accessor_cache = {}
    _mutator_cache = {}

    __resolver = None
    __columns__ = []

    __dispatcher__ = Event()
    __observables__ = []

    _register = ModelRegister()

    __attributes__ = {}

    many_methods = ['belongs_to_many', 'morph_to_many', 'morphed_by_many']

    CREATED_AT = 'created_at'
    UPDATED_AT = 'updated_at'

    def __init__(self, _attributes=None, **attributes):
        """
        :param attributes: The instance attributes
        """
        self._boot_if_not_booted()

        self._exists = False
        self._original = {}

        # Setting default attributes' values
        self._attributes = dict((k, v) for k, v in self.__attributes__.items())
        self._relations = {}

        self.sync_original()

        if _attributes is not None:
            attributes.update(_attributes)

        self.fill(**attributes)

    def _boot_if_not_booted(self):
        """
        Check if the model needs to be booted and if so, do it.
        """
        klass = self.__class__

        if not klass._booted.get(klass):
            klass._booted[klass] = True

            self._fire_model_event('booting')

            klass._boot()

            self._fire_model_event('booted')

    @classmethod
    def _boot(cls):
        """
        The booting method of the model.
        """
        cls._accessor_cache[cls] = {}
        cls._mutator_cache[cls] = {}

        for name, method in cls.__dict__.items():
            if isinstance(method, accessor):
                cls._accessor_cache[cls][method.attribute] = method
            elif isinstance(method, mutator):
                cls._mutator_cache[cls][method.attribute] = method

        cls._boot_mixins()

    @classmethod
    def _boot_columns(cls):
        connection = cls.resolve_connection()
        columns = connection.get_schema_manager().list_table_columns(cls.__table__ or inflection.tableize(cls.__name__))
        cls.__columns__ = list(columns.keys())
{'fraction_non_alphanumeric': 0.10186426221518216, 'fraction_numerical': 0.0007310832216400634, 'mean_word_length': 2.617452622300573, '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': '2054151', 'n_tokens_mistral': 2501, 'n_tokens_neox': 2392, 'n_words': 573}