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


def is_dirty(old_model, new_model):
    for column in old_model.__table__.columns:
        column = column.name
        if getattr(old_model, column, None) != getattr(new_model, column, None):
            return True

    return False


def find_type(sqlalchemy_table_class, column_name):
    if hasattr(sqlalchemy_table_class, '__table__') \
            and column_name in sqlalchemy_table_class.__table__.c:
        return sqlalchemy_table_class.__table__.c[column_name].type
    for base in sqlalchemy_table_class.__bases__:
        return find_type(base, column_name)
    raise NameError(column_name)


def kw_to_sqlalchemy(sqlalchemy_table_cls, kw):
    sqlalchemy_table = sqlalchemy_table_cls()

    for column, value in kw.iteritems():
        try:
            column_type = find_type(sqlalchemy_table_cls, column).python_type
        except NameError:
            continue

        try:
            if not issubclass(type(value), column_type):
                if issubclass(column_type, bool):
                    column_value = True if value.lower() == 'true' else False
                else:
                    column_value = column_type(value)
            else:
                column_value = value
        except UnicodeEncodeError:
            column_value = unicode(value)
        finally:
            setattr(sqlalchemy_table, column, column_value)

    return sqlalchemy_table


def prepare_kw_for_address_update(kw):
    required_fields = ['address_is_valid', 'latitude', 'longitude',
                       'geolocation_is_valid']<commit_msg>Set the find_type function as a private one<commit_after># -*- coding: utf-8 -*-


def _find_type(sqlalchemy_table_class, column_name):
    if hasattr(sqlalchemy_table_class, '__table__') \
            and column_name in sqlalchemy_table_class.__table__.c:
        return sqlalchemy_table_class.__table__.c[column_name].type
    for base in sqlalchemy_table_class.__bases__:
        return _find_type(base, column_name)
    raise NameError(column_name)


def is_dirty(old_model, new_model):
    for column in old_model.__table__.columns:
        column = column.name
        if getattr(old_model, column, None) != getattr(new_model, column, None):
            return True

    return False


def kw_to_sqlalchemy(sqlalchemy_table_cls, kw):
    sqlalchemy_table = sqlalchemy_table_cls()

    for column, value in kw.iteritems():
        try:
            column_type = find_type(sqlalchemy_table_cls, column).python_type
        except NameError:
            continue

        try:
            if not issubclass(type(value), column_type):
                if issubclass(column_type, bool):
                    column_value = True if value.lower() == 'true' else False
                else:
                    column_value = column_type(value)
            else:
                column_value = value
        except UnicodeEncodeError:
            column_value = unicode(value)
        finally:
            setattr(sqlalchemy_table, column, column_value)

    return sqlalchemy_table


def prepare_kw_for_address_update(kw):
    required_fields = ['address_is_valid', 'latitude', 'longitude',
                       'geolocation_is_valid']
{'fraction_non_alphanumeric': 0.07849196538936959, 'fraction_numerical': 0.0006180469715698393, 'mean_word_length': 2.518478260869565, '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': '1872017', 'n_tokens_mistral': 986, 'n_tokens_neox': 931, 'n_words': 204}