






'''simple docstring'''

import os
from typing import Optional

import fsspec
from fsspec.archive import AbstractArchiveFileSystem
from fsspec.utils import DEFAULT_BLOCK_SIZE





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


   def __init__(   self				:	Dict   ,		__lowerCAmelCase				:	Any = ""   ,		__lowerCAmelCase				:	Dict = None   ,		__lowerCAmelCase				:	Union[str, Any] = None   ,		**__lowerCAmelCase				:	Tuple)      ->					Tuple:
         super().__init__(self   ,		**__lowerCAmelCase)
         # always open as "rb" since fsspec can then use the TextIOWrapper to make it work for "r" mode
         lowercase_     =      fsspec.open(
             __lowerCAmelCase   ,		mode="rb"   ,		protocol=__lowerCAmelCase   ,		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 {})   ,		)
         lowercase_     =      os.path.basename(self.file.path.split("::")[0])
         lowercase_     =      (
             self.compressed_name[: self.compressed_name.rindex(".")]
             if """.""" in self.compressed_name
             else self.compressed_name
         )
         lowercase_     =      None


   @classmethod
   def __UpperCAmelCase       (   cls				:	int   ,		__lowerCAmelCase				:	Optional[int])      ->					str:
         # compressed file paths are always relative to the archive root
         return super()._strip_protocol(__lowerCAmelCase).lstrip("/")


   def __UpperCAmelCase       (   self				:	Union[str, Any])      ->					Any:
         if self.dir_cache is None:
               lowercase_     =      {**self.file.fs.info(self.file.path), """name""": self.uncompressed_name}
               lowercase_     =      {f["""name"""]: f}


   def __UpperCAmelCase       (   self				:	str   ,		__lowerCAmelCase				:	Tuple)      ->					int:
         return self.file.open().read()


   def __UpperCAmelCase       (   self				:	Tuple   ,		__lowerCAmelCase				:	List[Any]   ,		__lowerCAmelCase				:	Any = "rb"   ,		__lowerCAmelCase				:	Union[str, Any]=None   ,		__lowerCAmelCase				:	int=True   ,		__lowerCAmelCase				:	Union[str, Any]=None   ,		**__lowerCAmelCase				:	List[Any]   ,		)      ->					Optional[int]:
         lowercase_     =      self._strip_protocol(__lowerCAmelCase)
         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 							lowercase						(						A_ ):
   lowerCamelCase_    					='''bz2'''
   lowerCamelCase_    					='''bz2'''
   lowerCamelCase_    					='''.bz2'''





class 							lowercase						(						A_ ):
   lowerCamelCase_    					='''gzip'''
   lowerCamelCase_    					='''gzip'''
   lowerCamelCase_    					='''.gz'''





class 							lowercase						(						A_ ):
   lowerCamelCase_    					='''lz4'''
   lowerCamelCase_    					='''lz4'''
   lowerCamelCase_    					='''.lz4'''





class 							lowercase						(						A_ ):
   lowerCamelCase_    					='''xz'''
   lowerCamelCase_    					='''xz'''
   lowerCamelCase_    					='''.xz'''





class 							lowercase						(						A_ ):
   lowerCamelCase_    					='''zstd'''
   lowerCamelCase_    					='''zstd'''
   lowerCamelCase_    					='''.zst'''


   def __init__(   self				:	List[str]   ,		__lowerCAmelCase				:	Union[str, Any]   ,		__lowerCAmelCase				:	int = "rb"   ,		__lowerCAmelCase				:	str = None   ,		__lowerCAmelCase				:	Dict = None   ,		__lowerCAmelCase				:	Dict = DEFAULT_BLOCK_SIZE   ,		**__lowerCAmelCase				:	List[str]   ,		)      ->					Optional[int]:
         super().__init__(
             fo=__lowerCAmelCase   ,		mode=__lowerCAmelCase   ,		target_protocol=__lowerCAmelCase   ,		target_options=__lowerCAmelCase   ,		block_size=__lowerCAmelCase   ,		**__lowerCAmelCase   ,		)
         # 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
         lowercase_     =      self.file.__enter__





         class 							lowercase						:


            def __init__(   self				:	Any   ,		__lowerCAmelCase				:	Optional[Any])      ->					Optional[int]:
                  lowercase_     =      file_


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


            def __exit__(   self				:	str   ,		*__lowerCAmelCase				:	List[str]   ,		**__lowerCAmelCase				:	List[str])      ->					Any:
                  self._file.__exit__(*__lowerCAmelCase   ,		**__lowerCAmelCase)


            def __iter__(   self				:	Tuple)      ->					Union[str, Any]:
                  return iter(self._file)


            def __UpperCAmelCase       (   self				:	Union[str, Any])      ->					List[str]:
                  return next(self._file)


            def __getattr__(   self				:	List[Any]   ,		__lowerCAmelCase				:	List[str])      ->					str:
                  return getattr(self._file   ,		__lowerCAmelCase)

         def fixed_enter(*__lowerCAmelCase				:	Optional[Any]   ,		**__lowerCAmelCase				:	int):
               return WrappedFile(_enter(*__lowerCAmelCase   ,		**__lowerCAmelCase))

         lowercase_     =      fixed_enter







'''simple docstring'''

from typing import Callable, Optional

from .. import Features
from ..packaged_modules.generator.generator import Generator
from .abc import AbstractDatasetInputStream





class 							lowercase						(						__lowerCamelCase ):


   def __init__(   self				:	str   ,		__lowerCAmelCase				:	Callable   ,		__lowerCAmelCase				:	Optional[Features] = None   ,		__lowerCAmelCase				:	str = None   ,		__lowerCAmelCase				:	bool = False   ,		__lowerCAmelCase				:	bool = False   ,		__lowerCAmelCase				:	Optional[dict] = None   ,		__lowerCAmelCase				:	Optional[int] = None   ,		**__lowerCAmelCase				:	Union[str, Any]   ,		)      ->					List[Any]:
         super().__init__(
             features=__lowerCAmelCase   ,		cache_dir=__lowerCAmelCase   ,		keep_in_memory=__lowerCAmelCase   ,		streaming=__lowerCAmelCase   ,		num_proc=__lowerCAmelCase   ,		**__lowerCAmelCase   ,		)
         lowercase_     =      Generator(
             cache_dir=__lowerCAmelCase   ,		features=__lowerCAmelCase   ,		generator=__lowerCAmelCase   ,		gen_kwargs=__lowerCAmelCase   ,		**__lowerCAmelCase   ,		)


   def __UpperCAmelCase       (   self				:	Optional[int])      ->					List[str]:
         # Build iterable dataset
         if self.streaming:
               lowercase_     =      self.builder.as_streaming_dataset(split="train")
         # Build regular (map-style) dataset
         else:
               lowercase_     =      None
               lowercase_     =      None
               lowercase_     =      None
               lowercase_     =      None

               self.builder.download_and_prepare(
                   download_config=__lowerCAmelCase   ,		download_mode=__lowerCAmelCase   ,		verification_mode=__lowerCAmelCase   ,		base_path=__lowerCAmelCase   ,		num_proc=self.num_proc   ,		)
               lowercase_     =      self.builder.as_dataset(
                   split="train"   ,		verification_mode=__lowerCAmelCase   ,		in_memory=self.keep_in_memory)
         return dataset






