# Path: subdownloader/util.py
# def asciify(data):
#     """
#     Limit the byte data string to only ascii characters and convert it to a string.
#     Non-representable characters are dropped.
#     :param data: byte data string to convert to ascii
#     :return: string
#     """
#     return ''.join(map(chr, filter(lambda x : x < 128, data)))


import itertools
import logging
    from langdetect import detect
    from langdetect.lang_detect_exception import LangDetectException
from subdownloader.util import asciify
        :param value: data known about the language as string
        :param xx: True if the value may be a locale
        :param xxx: True if the value may be a LanguageID
        :param locale: True if the value may be a locale
        :param name: True if the value may be a LanguageName
        :return: Language Instance if a matching Language was found
        """
        # Use 2 lists instead of dict ==> order known
        keys = ['ISO639', 'LanguageID', 'locale', 'LanguageName']
        truefalses = [xx, xxx, locale, name]
        value = value.lower().replace('-', '_')
        for key, doKey in zip(keys, truefalses):
            if doKey:
                try:
                    return cls._from_xyz(key, value)
                except NotALanguageException:
                    pass
        raise NotALanguageException(value, 'Illegal language "{}"'.format(value))

    @classmethod
    def from_file(cls, filepath, chunk_size=None):
        """
        Try do determine the language of a text file.
        :param filepath: string file path
        :param chunk_size: amount of bytes of file to read to determine language
        :return: Language instance if detection succeeded, otherwise return UnknownLanguage
        """
        log.debug('Language.from_file: "{}", chunk={} ...'.format(filepath, chunk_size))
        with filepath.open('rb') as f:
            data = f.read(-1 if chunk_size is None else chunk_size)

# Path: subdownloader/util.py
# def asciify(data):
#     """
#     Limit the byte data string to only ascii characters and convert it to a string.
#     Non-representable characters are dropped.
#     :param data: byte data string to convert to ascii
#     :return: string
#     """
#     return ''.join(map(chr, filter(lambda x : x < 128, data)))


# Path: subdownloader/languages/language.py
import itertools
import logging
    from langdetect import detect
    from langdetect.lang_detect_exception import LangDetectException
from subdownloader.util import asciify

        :param value: data known about the language as string
        :param xx: True if the value may be a locale
        :param xxx: True if the value may be a LanguageID
        :param locale: True if the value may be a locale
        :param name: True if the value may be a LanguageName
        :return: Language Instance if a matching Language was found
        """
        # Use 2 lists instead of dict ==> order known
        keys = ['ISO639', 'LanguageID', 'locale', 'LanguageName']
        truefalses = [xx, xxx, locale, name]
        value = value.lower().replace('-', '_')
        for key, doKey in zip(keys, truefalses):
            if doKey:
                try:
                    return cls._from_xyz(key, value)
                except NotALanguageException:
                    pass
        raise NotALanguageException(value, 'Illegal language "{}"'.format(value))

    @classmethod
    def from_file(cls, filepath, chunk_size=None):
        """
        Try do determine the language of a text file.
        :param filepath: string file path
        :param chunk_size: amount of bytes of file to read to determine language
        :return: Language instance if detection succeeded, otherwise return UnknownLanguage
        """
        log.debug('Language.from_file: "{}", chunk={} ...'.format(filepath, chunk_size))
        with filepath.open('rb') as f:
            data = f.read(-1 if chunk_size is None else chunk_size)

        data_ascii = asciify(data)