
import os
from typing import Optional

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





class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     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							:							str     ,						_A							:							str = ""     ,						_A							:							Optional[str] = None     ,						_A							:							Optional[dict] = None     ,						**_A							:							List[Any] ):







       """simple docstring"""




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



     @classmethod
     def  UpperCAmelCase__							(				cls							:							List[str]     ,						_A							:							Optional[int] ):







       """simple docstring"""




       return super()._strip_protocol(_A ).lstrip('''/''' )



     def  UpperCAmelCase__							(				self							:							List[Any] ):







       """simple docstring"""




       if self.dir_cache is None:
         __SCREAMING_SNAKE_CASE      :	List[str]					=		{**self.file.fs.info(self.file.path ), '''name''': self.uncompressed_name}
         __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		{f['''name''']: f}



     def  UpperCAmelCase__							(				self							:							Dict     ,						_A							:							str ):







       """simple docstring"""




       return self.file.open().read()




     def  UpperCAmelCase__							(				self							:							Any     ,						_A							:							str     ,						_A							:							str = "rb"     ,						_A							:							Tuple=None     ,						_A							:							Union[str, Any]=True     ,						_A							:							Dict=None     ,						**_A							:							List[Any]     ,						):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	str					=		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     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''bz2'''
     lowerCAmelCase_							   =			'''bz2'''
     lowerCAmelCase_							   =			'''.bz2'''






class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''gzip'''
     lowerCAmelCase_							   =			'''gzip'''
     lowerCAmelCase_							   =			'''.gz'''






class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''lz4'''
     lowerCAmelCase_							   =			'''lz4'''
     lowerCAmelCase_							   =			'''.lz4'''






class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''xz'''
     lowerCAmelCase_							   =			'''xz'''
     lowerCAmelCase_							   =			'''.xz'''






class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''zstd'''
     lowerCAmelCase_							   =			'''zstd'''
     lowerCAmelCase_							   =			'''.zst'''



     def __init__(				self							:							str     ,						_A							:							str     ,						_A							:							str = "rb"     ,						_A							:							Optional[str] = None     ,						_A							:							Optional[dict] = None     ,						_A							:							int = DEFAULT_BLOCK_SIZE     ,						**_A							:							str     ,						):







       """simple docstring"""




       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
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		self.file.__enter__





       class     __UpperCamelCase :






            """simple docstring"""







            def __init__(				self							:							int     ,						_A							:							Optional[Any] ):







              """simple docstring"""




              __SCREAMING_SNAKE_CASE      :	Tuple					=		file_



            def __enter__(				self							:							int ):







              """simple docstring"""




              self._file.__enter__()
              return self



            def __exit__(				self							:							Any     ,						*_A							:							int     ,						**_A							:							List[Any] ):







              """simple docstring"""




              self._file.__exit__(*_A     ,						**_A )



            def __iter__(				self							:							List[Any] ):







              """simple docstring"""




              return iter(self._file )



            def  UpperCAmelCase__							(				self							:							int ):







              """simple docstring"""




              return next(self._file )




            def __getattr__(				self							:							Dict     ,						_A							:							Optional[int] ):







              """simple docstring"""




              return getattr(self._file     ,						_A )

       def fixed_enter(*_A							:							List[str]     ,						**_A							:							str ):
         return WrappedFile(_enter(*_A     ,						**_A ) )

       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		fixed_enter





from ...configuration_utils import PretrainedConfig
from ...utils import logging


a      :  List[Any]			     =			logging.get_logger(__name__)







class 				_a				(   _lowerCAmelCase					):
			A      		=	'''timm_backbone'''

			def __init__(self,   SCREAMING_SNAKE_CASE_=None,   SCREAMING_SNAKE_CASE_=3,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=None,   **SCREAMING_SNAKE_CASE_,   )       ->   Tuple:
						super().__init__(**SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Dict							      =     backbone
						UpperCAmelCase_:		Optional[Any]							      =     num_channels
						UpperCAmelCase_:		Optional[Any]							      =     features_only
						UpperCAmelCase_:		Any							      =     use_pretrained_backbone
						UpperCAmelCase_:		List[str]							      =     True
						UpperCAmelCase_:		Union[str, Any]							      =     out_indices if out_indices is not None else (-1,)






