


'''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    (    lowercase			):





  """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			,  UpperCamelCase = ""			,  UpperCamelCase = None			,  UpperCamelCase = None			,  **UpperCamelCase     ):







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






  @classmethod
  def   snake_case		(    cls			,  UpperCamelCase     ):







   """simple docstring"""
   # compressed file paths are always relative to the archive root
   return super()._strip_protocol(UpperCamelCase     ).lstrip("/"     )






  def   snake_case		(    self     ):







   """simple docstring"""
   if self.dir_cache is None:
    lowerCamelCase_      =  {**self.file.fs.info(self.file.path     ), "name": self.uncompressed_name}
    lowerCamelCase_      =  {f["name"]: f}






  def   snake_case		(    self			,  UpperCamelCase     ):







   """simple docstring"""
   return self.file.open().read()







  def   snake_case		(    self			,  UpperCamelCase			,  UpperCamelCase = "rb"			,  UpperCamelCase=None			,  UpperCamelCase=True			,  UpperCamelCase=None			,  **UpperCamelCase			,  ):







   """simple docstring"""
   lowerCamelCase_      =  self._strip_protocol(UpperCamelCase     )
   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    (    lowercase			):





  """simple docstring"""




  _lowerCamelCase		    =  "bz2"
  _lowerCamelCase		    =  "bz2"
  _lowerCamelCase		    =  ".bz2"





class      snake_case    (    lowercase			):





  """simple docstring"""




  _lowerCamelCase		    =  "gzip"
  _lowerCamelCase		    =  "gzip"
  _lowerCamelCase		    =  ".gz"





class      snake_case    (    lowercase			):





  """simple docstring"""




  _lowerCamelCase		    =  "lz4"
  _lowerCamelCase		    =  "lz4"
  _lowerCamelCase		    =  ".lz4"





class      snake_case    (    lowercase			):





  """simple docstring"""




  _lowerCamelCase		    =  "xz"
  _lowerCamelCase		    =  "xz"
  _lowerCamelCase		    =  ".xz"





class      snake_case    (    lowercase			):





  """simple docstring"""




  _lowerCamelCase		    =  "zstd"
  _lowerCamelCase		    =  "zstd"
  _lowerCamelCase		    =  ".zst"






  def __init__(    self			,  UpperCamelCase			,  UpperCamelCase = "rb"			,  UpperCamelCase = None			,  UpperCamelCase = None			,  UpperCamelCase = DEFAULT_BLOCK_SIZE			,  **UpperCamelCase			,  ):







   """simple docstring"""
   super().__init__(
       fo=UpperCamelCase			,  mode=UpperCamelCase			,  target_protocol=UpperCamelCase			,  target_options=UpperCamelCase			,  block_size=UpperCamelCase			,  **UpperCamelCase			,  )
   # 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
   lowerCamelCase_      =  self.file.__enter__





   class      snake_case    :





     """simple docstring"""




     def __init__(    self			,  UpperCamelCase     ):







      """simple docstring"""
      lowerCamelCase_      =  file_






     def __enter__(    self     ):







      """simple docstring"""
      self._file.__enter__()
      return self






     def __exit__(    self			,  *UpperCamelCase			,  **UpperCamelCase     ):







      """simple docstring"""
      self._file.__exit__(*UpperCamelCase			,  **UpperCamelCase     )






     def __iter__(    self     ):







      """simple docstring"""
      return iter(self._file     )






     def   snake_case		(    self     ):







      """simple docstring"""
      return next(self._file     )







     def __getattr__(    self			,  UpperCamelCase     ):







      """simple docstring"""
      return getattr(self._file			,  UpperCamelCase     )

   def fixed_enter(*UpperCamelCase			,  **UpperCamelCase     ):
    return WrappedFile(_enter(*UpperCamelCase			,  **UpperCamelCase     )     )

   lowerCamelCase_      =  fixed_enter





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__A				={'''configuration_xglm''': ['''XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''XGLMConfig''']}

try:
			if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			__A				=['''XGLMTokenizer''']

try:
			if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			__A				=['''XGLMTokenizerFast''']

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			__A				=[
			    '''XGLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''XGLMForCausalLM''',
			    '''XGLMModel''',
			    '''XGLMPreTrainedModel''',
			]


try:
			if not is_flax_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			__A				=[
			    '''FlaxXGLMForCausalLM''',
			    '''FlaxXGLMModel''',
			    '''FlaxXGLMPreTrainedModel''',
			]


try:
			if not is_tf_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			__A				=[
			    '''TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''TFXGLMForCausalLM''',
			    '''TFXGLMModel''',
			    '''TFXGLMPreTrainedModel''',
			]


if TYPE_CHECKING:
			from .configuration_xglm import XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XGLMConfig

			try:
						if not is_sentencepiece_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_xglm import XGLMTokenizer

			try:
						if not is_tokenizers_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_xglm_fast import XGLMTokenizerFast

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_xglm import XGLM_PRETRAINED_MODEL_ARCHIVE_LIST, XGLMForCausalLM, XGLMModel, XGLMPreTrainedModel

			try:
						if not is_flax_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_flax_xglm import FlaxXGLMForCausalLM, FlaxXGLMModel, FlaxXGLMPreTrainedModel

			try:
						if not is_tf_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tf_xglm import (
						    TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFXGLMForCausalLM,
						    TFXGLMModel,
						    TFXGLMPreTrainedModel,
						)


else:
			import sys

			__A				=_LazyModule(__name__, globals()['''__file__'''], _import_structure)


