


import os
from typing import Optional

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







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


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


      @classmethod
      def 				__lowerCamelCase	(							cls							,  SCREAMING_SNAKE_CASE__						):
            # compressed file paths are always relative to the archive root
            return super()._strip_protocol(__lowercase						).lstrip('''/'''						)


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


      def 				__lowerCamelCase	(							self							,  SCREAMING_SNAKE_CASE__						):
            return self.file.open().read()






      def 				__lowerCamelCase	(							self							,  SCREAMING_SNAKE_CASE__							,  SCREAMING_SNAKE_CASE__ = "rb"							,  SCREAMING_SNAKE_CASE__=None							,  SCREAMING_SNAKE_CASE__=True							,  SCREAMING_SNAKE_CASE__=None							,  **SCREAMING_SNAKE_CASE__							,  ):
            lowercase	:      Optional[int]          =						self._strip_protocol(__lowercase						)
            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  __SCREAMING_SNAKE_CASE      (	__lowerCamelCase      ):
      A :							Optional[Any]										=   """bz2"""
      A :							Any										=   """bz2"""
      A :							int										=   """.bz2"""







class  __SCREAMING_SNAKE_CASE      (	__lowerCamelCase      ):
      A :							Optional[Any]										=   """gzip"""
      A :							Optional[int]										=   """gzip"""
      A :							Dict										=   """.gz"""







class  __SCREAMING_SNAKE_CASE      (	__lowerCamelCase      ):
      A :							int										=   """lz4"""
      A :							Any										=   """lz4"""
      A :							Union[str, Any]										=   """.lz4"""







class  __SCREAMING_SNAKE_CASE      (	__lowerCamelCase      ):
      A :							int										=   """xz"""
      A :							Optional[int]										=   """xz"""
      A :							str										=   """.xz"""







class  __SCREAMING_SNAKE_CASE      (	__lowerCamelCase      ):
      A :							str										=   """zstd"""
      A :							int										=   """zstd"""
      A :							Any										=   """.zst"""


      def __init__(							self							,  SCREAMING_SNAKE_CASE__							,  SCREAMING_SNAKE_CASE__ = "rb"							,  SCREAMING_SNAKE_CASE__ = None							,  SCREAMING_SNAKE_CASE__ = None							,  SCREAMING_SNAKE_CASE__ = DEFAULT_BLOCK_SIZE							,  **SCREAMING_SNAKE_CASE__							,  ):
            super().__init__(
                fo=__lowercase							,  mode=__lowercase							,  target_protocol=__lowercase							,  target_options=__lowercase							,  block_size=__lowercase							,  **__lowercase							,  )
            # 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	:      Tuple          =						self.file.__enter__







            class  __SCREAMING_SNAKE_CASE      :


                  def __init__(							self							,  SCREAMING_SNAKE_CASE__						):
                        lowercase	:      List[Any]          =						file_


                  def __enter__(							self						):
                        self._file.__enter__()
                        return self


                  def __exit__(							self							,  *SCREAMING_SNAKE_CASE__							,  **SCREAMING_SNAKE_CASE__						):
                        self._file.__exit__(*__lowercase							,  **__lowercase						)


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


                  def 				__lowerCamelCase	(							self						):
                        return next(self._file						)






                  def __getattr__(							self							,  SCREAMING_SNAKE_CASE__						):
                        return getattr(self._file							,  __lowercase						)

            def fixed_enter(*SCREAMING_SNAKE_CASE__							,  **SCREAMING_SNAKE_CASE__						):
                  return WrappedFile(_enter(*__lowercase							,  **__lowercase						)						)

            lowercase	:      Optional[Any]          =						fixed_enter






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


A__								=						{
    '''configuration_ctrl''': ['''CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''CTRLConfig'''],
    '''tokenization_ctrl''': ['''CTRLTokenizer'''],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				A__								=						[
				    '''CTRL_PRETRAINED_MODEL_ARCHIVE_LIST''',
				    '''CTRLForSequenceClassification''',
				    '''CTRLLMHeadModel''',
				    '''CTRLModel''',
				    '''CTRLPreTrainedModel''',
				]

try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				A__								=						[
				    '''TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST''',
				    '''TFCTRLForSequenceClassification''',
				    '''TFCTRLLMHeadModel''',
				    '''TFCTRLModel''',
				    '''TFCTRLPreTrainedModel''',
				]


if TYPE_CHECKING:
				from .configuration_ctrl import CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP, CTRLConfig
				from .tokenization_ctrl import CTRLTokenizer

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_ctrl import (
								    CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
								    CTRLForSequenceClassification,
								    CTRLLMHeadModel,
								    CTRLModel,
								    CTRLPreTrainedModel,
								)

				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_tf_ctrl import (
								    TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
								    TFCTRLForSequenceClassification,
								    TFCTRLLMHeadModel,
								    TFCTRLModel,
								    TFCTRLPreTrainedModel,
								)

else:
				import sys

				A__								=						_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

