<commit_before># encoding: utf-8

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

from __future__ import absolute_import, unicode_literals

import abc
import os
import stat
from errno import EBADF, ENAMETOOLONG, ENOENT, ENOTDIR

import pathvalidate as pv
import six
import typepy
from pytablereader import DataError
from six.moves.urllib.parse import urlparse

from ._constant import SourceType
from .error import InvalidFilePathError, UrlError


def is_fifo(file_path):
    try:
        return stat.S_ISFIFO(os.stat(file_path).st_mode)
    except OSError as e:
        if e.errno not in (EBADF, ENAMETOOLONG, ENOENT, ENOTDIR):
            raise

        return False
    except ValueError:
        return False


@six.add_metaclass(abc.ABCMeta)
class ValidatorInterface(object):
    """
    An interface class for data source validator.
    """

    @abc.abstractproperty
    def source_type(self):
        pass

    @abc.abstractmethod
    def validate(self):
        pass


class BaseValidator(ValidatorInterface):
    """
    An abstract base class for data source validator.
    """

    @property
    def source(self):
        return self.__source

    def __init__(self, source):
        self.__source = source


class NullValidator(BaseValidator):
    @property
    def source_type(self):
        return "null"

    def validate(self):
        pass


class FileValidator(BaseValidator):
    """
    Validator class for file data source.
    """

    @property
    def source_type(self):
        return SourceType.FILE

    def validate(self):
        try:
            pv.validate_file_path(self.source)
        except pv.NullNameError:
            raise InvalidFilePathError("file path is empty")
        except (ValueError, pv.InvalidCharError, pv.InvalidLengthError) as e:
            raise InvalidFilePathError(e)<commit_msg>Replace a deprecated function<commit_after># encoding: utf-8

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

from __future__ import absolute_import, unicode_literals

import abc
import os
import stat
from errno import EBADF, ENAMETOOLONG, ENOENT, ENOTDIR

import pathvalidate as pv
import six
import typepy
from pytablereader import DataError
from six.moves.urllib.parse import urlparse

from ._constant import SourceType
from .error import InvalidFilePathError, UrlError


def is_fifo(file_path):
    try:
        return stat.S_ISFIFO(os.stat(file_path).st_mode)
    except OSError as e:
        if e.errno not in (EBADF, ENAMETOOLONG, ENOENT, ENOTDIR):
            raise

        return False
    except ValueError:
        return False


@six.add_metaclass(abc.ABCMeta)
class ValidatorInterface(object):
    """
    An interface class for data source validator.
    """

    @abc.abstractproperty
    def source_type(self):
        pass

    @abc.abstractmethod
    def validate(self):
        pass


class BaseValidator(ValidatorInterface):
    """
    An abstract base class for data source validator.
    """

    @property
    def source(self):
        return self.__source

    def __init__(self, source):
        self.__source = source


class NullValidator(BaseValidator):
    @property
    def source_type(self):
        return "null"

    def validate(self):
        pass


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)
        except pv.NullNameError:
            raise InvalidFilePathError("file path is empty")
        except (ValueError, pv.InvalidCharError, pv.InvalidLengthError) as e:
            raise InvalidFilePathError(e)
{'fraction_non_alphanumeric': 0.08054421768707483, 'fraction_numerical': 0.0005442176870748299, 'mean_word_length': 2.8776371308016877, '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': '1851504', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1067, 'n_words': 308}