"""simple docstring"""






import os
from typing import Optional

import fsspec
from fsspec.archive import AbstractArchiveFileSystem
from fsspec.utils import DEFAULT_BLOCK_SIZE
class        snake_case (				__SCREAMING_SNAKE_CASE       ):




     """simple docstring"""

     snake_case__       					=				''
     snake_case__       					=				(
         None  # protocol passed in prefix to the url. ex: "gzip", for gzip://file.txt::http://foo.bar/file.txt.gz
     )
     snake_case__       					=				None  # compression type in fsspec. ex: "gzip"
     snake_case__       					=				None  # extension of the filename to strip. ex: "".gz" to get file.txt from file.txt.gz







     def __init__(       self     :			List[Any]					,lowerCamelCase__     :			Any = ""					,lowerCamelCase__     :			Tuple = None					,lowerCamelCase__     :			Optional[int] = None					,**lowerCamelCase__     :			str    ):
         super().__init__(self					,**_a    )
         # always open as "rb" since fsspec can then use the TextIOWrapper to make it work for "r" mode
         UpperCAmelCase__    =							fsspec.open(
             _a					,mode='rb'					,protocol=_a					,compression=self.compression					,client_kwargs={
                 'requote_redirect_url': False,  # see https://github.com/huggingface/datasets/pull/5459
                 'trust_env': True,  # Enable reading proxy env variables.
                 **(target_options or {}).pop('client_kwargs'					,{}    ),  # To avoid issues if it was already passed.
             }					,**(target_options or {})					,)
         UpperCAmelCase__    =							os.path.basename(self.file.path.split('::'    )[0]    )
         UpperCAmelCase__    =							(
             self.compressed_name[: self.compressed_name.rindex('.'    )]
             if '.' in self.compressed_name
             else self.compressed_name
         )
         UpperCAmelCase__    =							None







     @classmethod
     def 	__lowerCAmelCase		(       cls     :			Tuple					,lowerCamelCase__     :			Union[str, Any]    ):
         # compressed file paths are always relative to the archive root
         return super()._strip_protocol(_a    ).lstrip('/'    )







     def 	__lowerCAmelCase		(       self     :			Optional[Any]    ):
         if self.dir_cache is None:
             UpperCAmelCase__    =							{**self.file.fs.info(self.file.path    ), 'name': self.uncompressed_name}
             UpperCAmelCase__    =							{f['name']: f}







     def 	__lowerCAmelCase		(       self     :			Union[str, Any]					,lowerCamelCase__     :			str    ):
         return self.file.open().read()







     def 	__lowerCAmelCase		(       self     :			Tuple					,lowerCamelCase__     :			List[Any]					,lowerCamelCase__     :			Dict = "rb"					,lowerCamelCase__     :			int=None					,lowerCamelCase__     :			int=True					,lowerCamelCase__     :			List[str]=None					,**lowerCamelCase__     :			List[Any]					,):
         UpperCAmelCase__    =							self._strip_protocol(_a    )
         if mode != "rb":
             raise ValueError(f'''Tried to read with mode {mode} on file {self.file.path} opened with mode \'rb\''''    )
         return self.file.open()






class        snake_case (				__SCREAMING_SNAKE_CASE       ):




     """simple docstring"""

     snake_case__       					=				'bz2'
     snake_case__       					=				'bz2'
     snake_case__       					=				'.bz2'






class        snake_case (				__SCREAMING_SNAKE_CASE       ):




     """simple docstring"""

     snake_case__       					=				'gzip'
     snake_case__       					=				'gzip'
     snake_case__       					=				'.gz'






class        snake_case (				__SCREAMING_SNAKE_CASE       ):




     """simple docstring"""

     snake_case__       					=				'lz4'
     snake_case__       					=				'lz4'
     snake_case__       					=				'.lz4'






class        snake_case (				__SCREAMING_SNAKE_CASE       ):




     """simple docstring"""

     snake_case__       					=				'xz'
     snake_case__       					=				'xz'
     snake_case__       					=				'.xz'






class        snake_case (				__SCREAMING_SNAKE_CASE       ):




     """simple docstring"""

     snake_case__       					=				'zstd'
     snake_case__       					=				'zstd'
     snake_case__       					=				'.zst'







     def __init__(       self     :			Optional[Any]					,lowerCamelCase__     :			Any					,lowerCamelCase__     :			Dict = "rb"					,lowerCamelCase__     :			List[str] = None					,lowerCamelCase__     :			List[Any] = None					,lowerCamelCase__     :			str = DEFAULT_BLOCK_SIZE					,**lowerCamelCase__     :			List[Any]					,):
         super().__init__(
             fo=_a					,mode=_a					,target_protocol=_a					,target_options=_a					,block_size=_a					,**_a					,)
         # We need to wrap the zstd decompressor to avoid this error in fsspec==2021.7.0 and zstandard==0.15.2:
         #
         # File "/Users/user/.virtualenvs/hf-datasets/lib/python3.7/site-packages/fsspec/core.py", line 145, in open
         #     out.close = close
         # AttributeError: 'zstd.ZstdDecompressionReader' object attribute 'close' is read-only
         #
         # see https://github.com/intake/filesystem_spec/issues/725
         UpperCAmelCase__    =							self.file.__enter__
         class        snake_case :




              """simple docstring"""

              def __init__(       self     :			List[str]					,lowerCamelCase__     :			Optional[int]    ):
                  UpperCAmelCase__    =							file_







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







              def __exit__(       self     :			Dict					,*lowerCamelCase__     :			List[Any]					,**lowerCamelCase__     :			Union[str, Any]    ):
                  self._file.__exit__(*_a					,**_a    )







              def __iter__(       self     :			Any    ):
                  return iter(self._file    )







              def 	__lowerCAmelCase		(       self     :			Any    ):
                  return next(self._file    )







              def __getattr__(       self     :			str					,lowerCamelCase__     :			Optional[Any]    ):
                  return getattr(self._file					,_a    )

         def fixed_enter(*lowerCamelCase__     :			Tuple					,**lowerCamelCase__     :			Tuple    ):
             return WrappedFile(_enter(*_a					,**_a    )    )

         UpperCAmelCase__    =							fixed_enter




"""simple docstring"""






import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
						import ctypes
						import msvcrt  # noqa
						class        snake_case (				ctypes.Structure       ):




											"""simple docstring"""

											snake_case__       					=				[("size", ctypes.c_int), ("visible", ctypes.c_byte)]



def 						a_		(      ):
				if os.name == "nt":
								UpperCAmelCase__    =							CursorInfo()
								UpperCAmelCase__    =							ctypes.windll.kernelaa.GetStdHandle(-1_1 )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(lowerCamelCase      ,    ctypes.byref(lowerCamelCase ) )
								UpperCAmelCase__    =							False
								ctypes.windll.kernelaa.SetConsoleCursorInfo(lowerCamelCase      ,    ctypes.byref(lowerCamelCase ) )
				elif os.name == "posix":
								sys.stdout.write('\033[?25l' )
								sys.stdout.flush()



def 						a_		(      ):
				if os.name == "nt":
								UpperCAmelCase__    =							CursorInfo()
								UpperCAmelCase__    =							ctypes.windll.kernelaa.GetStdHandle(-1_1 )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(lowerCamelCase      ,    ctypes.byref(lowerCamelCase ) )
								UpperCAmelCase__    =							True
								ctypes.windll.kernelaa.SetConsoleCursorInfo(lowerCamelCase      ,    ctypes.byref(lowerCamelCase ) )
				elif os.name == "posix":
								sys.stdout.write('\033[?25h' )
								sys.stdout.flush()







@contextmanager
def 						a_		(      ):
				try:
								hide_cursor()
								yield
				finally:
								show_cursor()



