






import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


_a      	=  {
    '''debug''': logging.DEBUG,
    '''info''': logging.INFO,
    '''warning''': logging.WARNING,
    '''error''': logging.ERROR,
    '''critical''': logging.CRITICAL,
}

_a      	=  logging.WARNING


def __A    (      )->  Tuple:





						"""simple docstring"""



						_UpperCAmelCase									=			os.getenv('DATASETS_VERBOSITY' ,		__lowerCAmelCase	)
						if env_level_str:
												if env_level_str in log_levels:
																		return log_levels[env_level_str]
												else:
																		logging.getLogger().warning(
																		    F"""Unknown option DATASETS_VERBOSITY={env_level_str}, """
																		    F"""has to be one of: { ", ".join(log_levels.keys()	) }"""	)
						return _default_log_level


def __A    (      )->  str:





						"""simple docstring"""



						return __name__.split('.'	)[0]


def __A    (      )->  logging.Logger:





						"""simple docstring"""



						return logging.getLogger(_get_library_name()	)


def __A    (      )->  None:





						"""simple docstring"""



						_UpperCAmelCase									=			_get_library_root_logger()
						library_root_logger.setLevel(_get_default_logging_level()	)


def __A    (      )->  None:





						"""simple docstring"""



						_UpperCAmelCase									=			_get_library_root_logger()
						library_root_logger.setLevel(logging.NOTSET	)


def __A    (      __lowerCAmelCase = None	)->  logging.Logger:





						"""simple docstring"""



						if name is None:
												_UpperCAmelCase									=			_get_library_name()
						return logging.getLogger(__lowerCAmelCase	)


def __A    (      )->  int:





						"""simple docstring"""



						return _get_library_root_logger().getEffectiveLevel()


def __A    (      __lowerCAmelCase	)->  None:





						"""simple docstring"""



						_get_library_root_logger().setLevel(__lowerCAmelCase	)


def __A    (      )->  Dict:





						"""simple docstring"""



						return set_verbosity(__lowerCAmelCase	)


def __A    (      )->  Optional[int]:





						"""simple docstring"""



						return set_verbosity(__lowerCAmelCase	)


def __A    (      )->  Tuple:





						"""simple docstring"""



						return set_verbosity(__lowerCAmelCase	)


def __A    (      )->  Optional[int]:





						"""simple docstring"""



						return set_verbosity(__lowerCAmelCase	)


def __A    (      )->  None:





						"""simple docstring"""



						_UpperCAmelCase									=			False


def __A    (      )->  None:





						"""simple docstring"""



						_UpperCAmelCase									=			True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()





class __lowerCamelCase :





	"""simple docstring"""






	def __init__(							self       ,    *UpperCAmelCase       ,    **UpperCAmelCase    ):  # pylint: disable=unused-argument
							"""simple docstring"""







							_UpperCAmelCase									=			args[0] if args else None

	def __iter__(							self    ):
							"""simple docstring"""







							return iter(self._iterator    )

	def __getattr__(							self       ,    UpperCAmelCase    ):
							"""simple docstring"""







							def empty_fn(*UpperCAmelCase       ,    **UpperCAmelCase    ):  # pylint: disable=unused-argument
													return

							return empty_fn

	def __enter__(							self    ):
							"""simple docstring"""







							return self

	def __exit__(							self       ,    UpperCAmelCase       ,    UpperCAmelCase       ,    UpperCAmelCase    ):
							"""simple docstring"""







							return



_a      	=  True





class __lowerCamelCase :





	"""simple docstring"""






	def __call__(							self       ,    *UpperCAmelCase       ,    UpperCAmelCase=False       ,    **UpperCAmelCase    ):
							"""simple docstring"""







							if _tqdm_active and not disable:
													return tqdm_lib.tqdm(*UpperCAmelCase       ,    **UpperCAmelCase    )
							else:
													return EmptyTqdm(*UpperCAmelCase       ,    **UpperCAmelCase    )

	def        UpperCamelCase    (							self       ,    *UpperCAmelCase       ,    **UpperCAmelCase    ):
							"""simple docstring"""







							_UpperCAmelCase									=			None
							if _tqdm_active:
													return tqdm_lib.tqdm.set_lock(*UpperCAmelCase       ,    **UpperCAmelCase    )

	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							if _tqdm_active:
													return tqdm_lib.tqdm.get_lock()



_a      	=  _tqdm_cls()


def __A    (      )->  bool:





						"""simple docstring"""



						global _tqdm_active
						return bool(_tqdm_active	)


def __A    (      )->  Dict:





						"""simple docstring"""



						global _tqdm_active
						_UpperCAmelCase									=			True


def __A    (      )->  str:





						"""simple docstring"""



						global _tqdm_active
						_UpperCAmelCase									=			False








import enum
import os
from hashlib import shaaaa
from typing import Optional

from .. import config
from .logging import get_logger


_a      	=  get_logger(__name__)





class __lowerCamelCase (      enum.Enum):





	"""simple docstring"""






	UpperCamelCase__								=      "all_checks"
	UpperCamelCase__								=      "basic_checks"
	UpperCamelCase__								=      "no_checks"





class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""









def __A    (      __lowerCAmelCase ,		__lowerCAmelCase ,		__lowerCAmelCase=None	)->  str:





						"""simple docstring"""



						if expected_checksums is None:
												logger.info('Unable to verify checksums.'	)
												return
						if len(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	) > 0:
												raise ExpectedMoreDownloadedFiles(str(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	)	)
						if len(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	) > 0:
												raise UnexpectedDownloadedFile(str(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	)	)
						_UpperCAmelCase									=			[url for url in expected_checksums if expected_checksums[url] != recorded_checksums[url]]
						_UpperCAmelCase									=			' for ' + verification_name if verification_name is not None else ''
						if len(__lowerCAmelCase	) > 0:
												raise NonMatchingChecksumError(
												    F"""Checksums didn't match{for_verification_name}:\n"""
												    F"""{bad_urls}\n"""
												    'Set `verification_mode=\'no_checks\'` to skip checksums verification and ignore this error'	)
						logger.info('All the checksums matched successfully' + for_verification_name	)





class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""









def __A    (      __lowerCAmelCase ,		__lowerCAmelCase	)->  int:





						"""simple docstring"""



						if expected_splits is None:
												logger.info('Unable to verify splits sizes.'	)
												return
						if len(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	) > 0:
												raise ExpectedMoreSplits(str(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	)	)
						if len(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	) > 0:
												raise UnexpectedSplits(str(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	)	)
						_UpperCAmelCase									=			[
						    {'expected': expected_splits[name], 'recorded': recorded_splits[name]}
						    for name in expected_splits
						    if expected_splits[name].num_examples != recorded_splits[name].num_examples
						]
						if len(__lowerCAmelCase	) > 0:
												raise NonMatchingSplitsSizesError(str(__lowerCAmelCase	)	)
						logger.info('All the splits matched successfully.'	)


def __A    (      __lowerCAmelCase ,		__lowerCAmelCase = True	)->  dict:





						"""simple docstring"""



						if record_checksum:
												_UpperCAmelCase									=			shaaaa()
												with open(__lowerCAmelCase ,		'rb'	) as f:
																		for chunk in iter(lambda: f.read(1 << 20	) ,		b''	):
																								m.update(__lowerCAmelCase	)
																		_UpperCAmelCase									=			m.hexdigest()
						else:
												_UpperCAmelCase									=			None
						return {"num_bytes": os.path.getsize(__lowerCAmelCase	), "checksum": checksum}


def __A    (      __lowerCAmelCase	)->  List[str]:





						"""simple docstring"""



						if dataset_size and config.IN_MEMORY_MAX_SIZE:
												return dataset_size < config.IN_MEMORY_MAX_SIZE
						else:
												return False
