<commit_before># encoding: utf-8

"""
.. codeauthor:: <NAME> <<EMAIL>>
"""

from __future__ import absolute_import, unicode_literals

import typepy
from pytablereader import DataError
from tabledata import TableData

from .._constant import TableNameTemplate as tnt
from ..formatter import TableFormatter


class SqliteTableFormatter(TableFormatter):
    def __init__(self, source_data):
        super(SqliteTableFormatter, self).__init__(source_data)

        self.__table_name = None

        if typepy.is_null_string(source_data):
            raise DataError

    def to_table_data(self):
        from simplesqlite import SimpleSQLite
        from simplesqlite.query import AttrList

        con = SimpleSQLite(self._source_data, "r")

        for table in con.fetch_table_names():
            self.__table_name = table

            attr_name_list = con.fetch_attr_names(table)
            data_matrix = con.select(select=AttrList(attr_name_list), table_name=table).fetchall()

            yield TableData(
                table,
                attr_name_list,
                data_matrix,
                dp_extractor=self._loader.dp_extractor,
                type_hints=self._loader.type_hints,
            )

    def _make_table_name(self):
        return self._loader._expand_table_name_format(
            self._loader._get_basic_tablename_keyvalue_mapping() + [(tnt.KEY, self.__table_name)]
        )
<commit_msg>Refactor: rename a local variable<commit_after># encoding: utf-8

"""
.. codeauthor:: <NAME> <<EMAIL>>
"""

from __future__ import absolute_import, unicode_literals

import typepy
from pytablereader import DataError
from tabledata import TableData

from .._constant import TableNameTemplate as tnt
from ..formatter import TableFormatter


class SqliteTableFormatter(TableFormatter):
    def __init__(self, source_data):
        super(SqliteTableFormatter, self).__init__(source_data)

        self.__table_name = None

        if typepy.is_null_string(source_data):
            raise DataError

    def to_table_data(self):
        from simplesqlite import SimpleSQLite
        from simplesqlite.query import AttrList

        con = SimpleSQLite(self._source_data, "r")

        for table in con.fetch_table_names():
            self.__table_name = table

            attr_names = con.fetch_attr_names(table)
            data_matrix = con.select(select=AttrList(attr_names), table_name=table).fetchall()

            yield TableData(
                table,
                attr_names,
                data_matrix,
                dp_extractor=self._loader.dp_extractor,
                type_hints=self._loader.type_hints,
            )

    def _make_table_name(self):
        return self._loader._expand_table_name_format(
            self._loader._get_basic_tablename_keyvalue_mapping() + [(tnt.KEY, self.__table_name)]
        )

{'fraction_non_alphanumeric': 0.0780812324929972, 'fraction_numerical': 0.0007002801120448179, 'mean_word_length': 2.715214564369311, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2994353', 'n_tokens_mistral': 844, 'n_tokens_neox': 806, 'n_words': 168}