




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


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

lowerCamelCase__			:       Union[str, Any]         =							logging.WARNING

def  UpperCAmelCase_							(				) ->			Any:
      SCREAMING_SNAKE_CASE_     						=      os.getenv('DATASETS_VERBOSITY'      ,      A__							)
      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  UpperCAmelCase_							(				) ->			Optional[Any]:
      return __name__.split('.'							)[0]

def  UpperCAmelCase_							(				) ->			Union[str, Any]:
      return logging.getLogger(_get_library_name()							)

def  UpperCAmelCase_							(				) ->			Any:
      SCREAMING_SNAKE_CASE_     						=      _get_library_root_logger()
      library_root_logger.setLevel(_get_default_logging_level()							)

def  UpperCAmelCase_							(				) ->			List[Any]:
      SCREAMING_SNAKE_CASE_     						=      _get_library_root_logger()
      library_root_logger.setLevel(logging.NOTSET							)

def  UpperCAmelCase_							(				__UpperCAmelCase						:     int = None							) ->			Optional[Any]:



      if name is None:
            SCREAMING_SNAKE_CASE_     						=      _get_library_name()
      return logging.getLogger(A__							)

def  UpperCAmelCase_							(				) ->			str:
      return _get_library_root_logger().getEffectiveLevel()

def  UpperCAmelCase_							(				__UpperCAmelCase						:     Tuple							) ->			List[str]:
      _get_library_root_logger().setLevel(A__							)

def  UpperCAmelCase_							(				) ->			Optional[int]:
      return set_verbosity(A__							)

def  UpperCAmelCase_							(				) ->			Tuple:
      return set_verbosity(A__							)

def  UpperCAmelCase_							(				) ->			str:
      return set_verbosity(A__							)

def  UpperCAmelCase_							(				) ->			Tuple:
      return set_verbosity(A__							)

def  UpperCAmelCase_							(				) ->			Dict:
      SCREAMING_SNAKE_CASE_     						=      False

def  UpperCAmelCase_							(				) ->			Union[str, Any]:
      SCREAMING_SNAKE_CASE_     						=      True


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





class 	lowerCamelCase_							:


 '''simple docstring'''







 def __init__(							self  :		Union[str, Any]    ,    *_lowerCAmelCase  :		Tuple    ,    **_lowerCAmelCase  :		Optional[int]						):  # pylint: disable=unused-argument
       SCREAMING_SNAKE_CASE_     						=      args[0] if args else None



 def __iter__(							self  :		Union[str, Any]						):
       return iter(self._iterator						)



 def __getattr__(							self  :		List[Any]    ,    _lowerCAmelCase  :		Union[str, Any]						):

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

       return empty_fn



 def __enter__(							self  :		List[str]						):
       return self




 def __exit__(							self  :		Optional[int]    ,    _lowerCAmelCase  :		Optional[Any]    ,    _lowerCAmelCase  :		Optional[Any]    ,    _lowerCAmelCase  :		List[str]						):
       return


lowerCamelCase__			:       Union[str, Any]         =							True





class 	lowerCamelCase_							:


 '''simple docstring'''







 def __call__(							self  :		str    ,    *_lowerCAmelCase  :		Tuple    ,    _lowerCAmelCase  :		Optional[Any]=False    ,    **_lowerCAmelCase  :		int						):
       if _tqdm_active and not disable:
             return tqdm_lib.tqdm(*lowercase__    ,    **lowercase__						)
       else:
             return EmptyTqdm(*lowercase__    ,    **lowercase__						)



 def 				lowerCAmelCase_  (							self  :		Optional[Any]    ,    *_lowerCAmelCase  :		List[str]    ,    **_lowerCAmelCase  :		int						):
       SCREAMING_SNAKE_CASE_     						=      None
       if _tqdm_active:
             return tqdm_lib.tqdm.set_lock(*lowercase__    ,    **lowercase__						)




 def 				lowerCAmelCase_  (							self  :		Any						):
       if _tqdm_active:
             return tqdm_lib.tqdm.get_lock()


lowerCamelCase__			:       Optional[Any]         =							_tqdm_cls()

def  UpperCAmelCase_							(				) ->			Union[str, Any]:
      global _tqdm_active
      return bool(_tqdm_active							)

def  UpperCAmelCase_							(				) ->			Tuple:
      global _tqdm_active
      SCREAMING_SNAKE_CASE_     						=      True





def  UpperCAmelCase_							(				) ->			Union[str, Any]:
      global _tqdm_active
      SCREAMING_SNAKE_CASE_     						=      False









from pathlib import PurePosixPath
from typing import Optional

import fsspec
from fsspec import AbstractFileSystem
from huggingface_hub.hf_api import DatasetInfo

from ..utils.file_utils import get_authentication_headers_for_url
from ..utils.hub import hf_hub_url





class 	lowerCamelCase_							(				_SCREAMING_SNAKE_CASE ):


 '''simple docstring'''







 lowercase_       =   ""
 lowercase_       =   "hf-legacy"  # "hf://"" is reserved for hffs



 def __init__(							self  :		Optional[int]    ,    _lowerCAmelCase  :		Optional[DatasetInfo] = None    ,    _lowerCAmelCase  :		Optional[str] = None    ,    **_lowerCAmelCase  :		int    ,    ):
       super().__init__(self    ,    **_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_     						=      repo_info
       SCREAMING_SNAKE_CASE_     						=      token
       SCREAMING_SNAKE_CASE_     						=      None



 def 				lowerCAmelCase_  (							self  :		Tuple						):
       if self.dir_cache is None:
             SCREAMING_SNAKE_CASE_     						=      {}
             for hf_file in self.repo_info.siblings:
                   # TODO(QL): add sizes
                   SCREAMING_SNAKE_CASE_     						=      {
                       'name': hf_file.rfilename,
                       'size': None,
                       'type': 'file',
                   }
                   self.dir_cache.update(
                       {
                           str(_lowerCAmelCase						): {'name': str(_lowerCAmelCase						), 'size': None, 'type': 'directory'}
                           for d in list(PurePosixPath(hf_file.rfilename						).parents						)[:-1]
                       }						)



 def 				lowerCAmelCase_  (							self  :		Optional[int]    ,    _lowerCAmelCase  :		str    ,    _lowerCAmelCase  :		str = "rb"    ,    **_lowerCAmelCase  :		Optional[Any]    ,    ):
       if not isinstance(self.repo_info    ,    _lowerCAmelCase						):
             raise NotImplementedError(F"Open is only implemented for dataset repositories, but got {self.repo_info}"						)
       SCREAMING_SNAKE_CASE_     						=      hf_hub_url(self.repo_info.id    ,    _lowerCAmelCase    ,    revision=self.repo_info.sha						)
       return fsspec.open(
           _lowerCAmelCase    ,    mode=_lowerCAmelCase    ,    headers=get_authentication_headers_for_url(_lowerCAmelCase    ,    use_auth_token=self.token						)    ,    client_kwargs={'trust_env': True}    ,    ).open()



 def 				lowerCAmelCase_  (							self  :		List[Any]    ,    _lowerCAmelCase  :		Any    ,    **_lowerCAmelCase  :		Dict						):
       self._get_dirs()
       SCREAMING_SNAKE_CASE_     						=      self._strip_protocol(_lowerCAmelCase						)
       if path in self.dir_cache:
             return self.dir_cache[path]
       else:
             raise FileNotFoundError(_lowerCAmelCase						)




 def 				lowerCAmelCase_  (							self  :		Optional[Any]    ,    _lowerCAmelCase  :		Any    ,    _lowerCAmelCase  :		Any=False    ,    **_lowerCAmelCase  :		str						):
       self._get_dirs()
       SCREAMING_SNAKE_CASE_     						=      PurePosixPath(path.strip('/'						)						)
       SCREAMING_SNAKE_CASE_     						=      {}
       for p, f in self.dir_cache.items():
             SCREAMING_SNAKE_CASE_     						=      PurePosixPath(p.strip('/'						)						)
             SCREAMING_SNAKE_CASE_     						=      p.parent
             if root == path:
                   SCREAMING_SNAKE_CASE_     						=      f
       SCREAMING_SNAKE_CASE_     						=      list(paths.values()						)
       if detail:
             return out
       else:
             return sorted(f['name'] for f in out						)