# Path: pytablereader/_validator.py
# class FileValidator(BaseValidator):
#     """
#     Validator class for file data source.
#     """
# 
#     @property
#     def source_type(self):
#         return SourceType.FILE
# 
#     def validate(self):
#         try:
#             pv.validate_filepath(self.source, platform="auto")
#         except pv.ValidationError as e:
#             raise InvalidFilePathError(e)
# 
#         if os.path.isfile(self.source) or is_fifo(self.source):
#             return
# 
#         raise OSError("file not found")
# 
# class TextValidator(BaseValidator):
#     """
#     Validator class for text object data source.
#     """
# 
#     @property
#     def source_type(self):
#         return SourceType.TEXT
# 
#     def validate(self):
#         if typepy.is_null_string(self.source):
#             raise DataError("data source is empty")
# 
# Path: pytablereader/csv/core.py
# class CsvTableFileLoader(CsvTableLoader):
#     """
#     A file loader class to extract tabular data from CSV files.
# 
#     :param str file_path: Path to the loading CSV file.
# 
#     .. py:attribute:: table_name
# 
#         Table name string. Defaults to ``%(filename)s``.
# 
#     :Examples:
#         :ref:`example-csv-table-loader`
#     """
# 
#     def __init__(self, file_path, quoting_flags=None, type_hints=None, type_hint_rules=None):
#         super().__init__(file_path, quoting_flags, type_hints, type_hint_rules)
# 
#         self._validator = FileValidator(file_path)
#         self._logger = FileSourceLogger(self)
# 
#     def load(self):
#         """
#         Extract tabular data as |TableData| instances from a CSV file.
#         |load_source_desc_file|
# 
#         :return:
#             Loaded table data.
#             |load_table_name_desc|
# 
#             ===================  ========================================
#             Format specifier     Value after the replacement
#             ===================  ========================================
#             ``%(filename)s``     |filename_desc|
#             ``%(format_name)s``  ``"csv"``
#             ``%(format_id)s``    |format_id_desc|
#             ``%(global_id)s``    |global_id|
#             ===================  ========================================
#         :rtype: |TableData| iterator
#         :raises pytablereader.DataError:
#             If the CSV data is invalid.
# 
#         .. seealso::
#             :py:func:`csv.reader`
#         """
# 
#         self._validate()
#         self._logger.logging_load()
#         self.encoding = get_file_encoding(self.source, self.encoding)
# 
#         self._csv_reader = csv.reader(
#             open(self.source, encoding=self.encoding),
#             delimiter=self.delimiter,
#             quotechar=self.quotechar,
#             strict=True,
#             skipinitialspace=True,
#         )
# 
#         formatter = CsvTableFormatter(self._to_data_matrix())
#         formatter.accept(self)
# 
#         return formatter.to_table_data()
# 
#     def _get_default_table_name_template(self):
#         return tnt.FILENAME
# 
# class CsvTableTextLoader(CsvTableLoader):
#     """
#     A text loader class to extract tabular data from CSV text data.
# 
#     :param str text: CSV text to load.
# 
#     .. py:attribute:: table_name
# 
#         Table name string. Defaults to ``%(format_name)s%(format_id)s``.
# 
#     :Examples:
#         :ref:`example-csv-table-loader`
#     """
# 
#     def __init__(self, text, quoting_flags=None, type_hints=None, type_hint_rules=None):
#         super().__init__(text, quoting_flags, type_hints, type_hint_rules)
# 
#         self._validator = TextValidator(text)
#         self._logger = TextSourceLogger(self)
# 
#     def load(self):
#         """
#         Extract tabular data as |TableData| instances from a CSV text object.
#         |load_source_desc_text|
# 
#         :return:
#             Loaded table data.
#             |load_table_name_desc|
# 
#             ===================  ========================================
#             Format specifier     Value after the replacement
#             ===================  ========================================
#             ``%(filename)s``     ``""``
#             ``%(format_name)s``  ``"csv"``
#             ``%(format_id)s``    |format_id_desc|
#             ``%(global_id)s``    |global_id|
#             ===================  ========================================
#         :rtype: |TableData| iterator
#         :raises pytablereader.DataError:
#             If the CSV data is invalid.
# 
#         .. seealso::
#             :py:func:`csv.reader`
#         """
# 
#         self._validate()
#         self._logger.logging_load()
# 
#         self._csv_reader = csv.reader(
#             io.StringIO(self.source.strip()),
#             delimiter=self.delimiter,
#             quotechar=self.quotechar,
#             strict=True,
#             skipinitialspace=True,
#         )
#         formatter = CsvTableFormatter(self._to_data_matrix())
#         formatter.accept(self)
# 
#         return formatter.to_table_data()
# 
#     def _get_default_table_name_template(self):
#         return f"{tnt.FORMAT_NAME:s}{tnt.FORMAT_ID:s}"


from .._validator import FileValidator, TextValidator
from ..csv.core import CsvTableFileLoader, CsvTableTextLoader
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""



class TsvTableFileLoader(CsvTableFileLoader):
    """
    Tab separated values (TSV) format file loader class.

    :param str file_path: Path to the loading TSV file.

    .. py:attribute:: table_name

        Table name string. Defaults to ``%(filename)s``.
    """

    @property
    def format_name(self):
        return "tsv"

    def __init__(self, file_path, quoting_flags=None, type_hints=None, type_hint_rules=None):
        super().__init__(file_path, quoting_flags, type_hints, type_hint_rules)

        self.delimiter = "\t"


# Path: pytablereader/_validator.py
# class FileValidator(BaseValidator):
#     """
#     Validator class for file data source.
#     """
# 
#     @property
#     def source_type(self):
#         return SourceType.FILE
# 
#     def validate(self):
#         try:
#             pv.validate_filepath(self.source, platform="auto")
#         except pv.ValidationError as e:
#             raise InvalidFilePathError(e)
# 
#         if os.path.isfile(self.source) or is_fifo(self.source):
#             return
# 
#         raise OSError("file not found")
# 
# class TextValidator(BaseValidator):
#     """
#     Validator class for text object data source.
#     """
# 
#     @property
#     def source_type(self):
#         return SourceType.TEXT
# 
#     def validate(self):
#         if typepy.is_null_string(self.source):
#             raise DataError("data source is empty")
# 
# Path: pytablereader/csv/core.py
# class CsvTableFileLoader(CsvTableLoader):
#     """
#     A file loader class to extract tabular data from CSV files.
# 
#     :param str file_path: Path to the loading CSV file.
# 
#     .. py:attribute:: table_name
# 
#         Table name string. Defaults to ``%(filename)s``.
# 
#     :Examples:
#         :ref:`example-csv-table-loader`
#     """
# 
#     def __init__(self, file_path, quoting_flags=None, type_hints=None, type_hint_rules=None):
#         super().__init__(file_path, quoting_flags, type_hints, type_hint_rules)
# 
#         self._validator = FileValidator(file_path)
#         self._logger = FileSourceLogger(self)
# 
#     def load(self):
#         """
#         Extract tabular data as |TableData| instances from a CSV file.
#         |load_source_desc_file|
# 
#         :return:
#             Loaded table data.
#             |load_table_name_desc|
# 
#             ===================  ========================================
#             Format specifier     Value after the replacement
#             ===================  ========================================
#             ``%(filename)s``     |filename_desc|
#             ``%(format_name)s``  ``"csv"``
#             ``%(format_id)s``    |format_id_desc|
#             ``%(global_id)s``    |global_id|
#             ===================  ========================================
#         :rtype: |TableData| iterator
#         :raises pytablereader.DataError:
#             If the CSV data is invalid.
# 
#         .. seealso::
#             :py:func:`csv.reader`
#         """
# 
#         self._validate()
#         self._logger.logging_load()
#         self.encoding = get_file_encoding(self.source, self.encoding)
# 
#         self._csv_reader = csv.reader(
#             open(self.source, encoding=self.encoding),
#             delimiter=self.delimiter,
#             quotechar=self.quotechar,
#             strict=True,
#             skipinitialspace=True,
#         )
# 
#         formatter = CsvTableFormatter(self._to_data_matrix())
#         formatter.accept(self)
# 
#         return formatter.to_table_data()
# 
#     def _get_default_table_name_template(self):
#         return tnt.FILENAME
# 
# class CsvTableTextLoader(CsvTableLoader):
#     """
#     A text loader class to extract tabular data from CSV text data.
# 
#     :param str text: CSV text to load.
# 
#     .. py:attribute:: table_name
# 
#         Table name string. Defaults to ``%(format_name)s%(format_id)s``.
# 
#     :Examples:
#         :ref:`example-csv-table-loader`
#     """
# 
#     def __init__(self, text, quoting_flags=None, type_hints=None, type_hint_rules=None):
#         super().__init__(text, quoting_flags, type_hints, type_hint_rules)
# 
#         self._validator = TextValidator(text)
#         self._logger = TextSourceLogger(self)
# 
#     def load(self):
#         """
#         Extract tabular data as |TableData| instances from a CSV text object.
#         |load_source_desc_text|
# 
#         :return:
#             Loaded table data.
#             |load_table_name_desc|
# 
#             ===================  ========================================
#             Format specifier     Value after the replacement
#             ===================  ========================================
#             ``%(filename)s``     ``""``
#             ``%(format_name)s``  ``"csv"``
#             ``%(format_id)s``    |format_id_desc|
#             ``%(global_id)s``    |global_id|
#             ===================  ========================================
#         :rtype: |TableData| iterator
#         :raises pytablereader.DataError:
#             If the CSV data is invalid.
# 
#         .. seealso::
#             :py:func:`csv.reader`
#         """
# 
#         self._validate()
#         self._logger.logging_load()
# 
#         self._csv_reader = csv.reader(
#             io.StringIO(self.source.strip()),
#             delimiter=self.delimiter,
#             quotechar=self.quotechar,
#             strict=True,
#             skipinitialspace=True,
#         )
#         formatter = CsvTableFormatter(self._to_data_matrix())
#         formatter.accept(self)
# 
#         return formatter.to_table_data()
# 
#     def _get_default_table_name_template(self):
#         return f"{tnt.FORMAT_NAME:s}{tnt.FORMAT_ID:s}"


# Path: pytablereader/tsv/core.py
from .._validator import FileValidator, TextValidator
from ..csv.core import CsvTableFileLoader, CsvTableTextLoader

"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""



class TsvTableFileLoader(CsvTableFileLoader):
    """
    Tab separated values (TSV) format file loader class.

    :param str file_path: Path to the loading TSV file.

    .. py:attribute:: table_name

        Table name string. Defaults to ``%(filename)s``.
    """

    @property
    def format_name(self):
        return "tsv"

    def __init__(self, file_path, quoting_flags=None, type_hints=None, type_hint_rules=None):
        super().__init__(file_path, quoting_flags, type_hints, type_hint_rules)

        self.delimiter = "\t"


        self._validator = FileValidator(file_path)