"""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		(    __snake_case ):







				"""simple docstring"""






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





				def __init__(      self							:							List[str]      ,    _A							:							str = ""      ,    _A							:							Optional[str] = None      ,    _A							:							Optional[dict] = None      ,    **_A							:							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		:						List[Any]			  =    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		:						Union[str, Any]			  =    os.path.basename(self.file.path.split("""::""")[0])
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    (
											    self.compressed_name[: self.compressed_name.rindex(""".""")]
											    if """.""" in self.compressed_name
											    else self.compressed_name
											)
											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    None





				@classmethod
				def 		_lowerCAmelCase		(      cls							:							Any      ,    _A							:							Tuple):



											"""simple docstring"""







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





				def 		_lowerCAmelCase		(      self							:							Optional[Any]):



											"""simple docstring"""







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





				def 		_lowerCAmelCase		(      self							:							Optional[int]      ,    _A							:							str):



											"""simple docstring"""







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





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



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						int			  =    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		(    __snake_case ):







				"""simple docstring"""






				a			=						"bz2"
				a			=						"bz2"
				a			=						".bz2"




class  _snake_case		(    __snake_case ):







				"""simple docstring"""






				a			=						"gzip"
				a			=						"gzip"
				a			=						".gz"




class  _snake_case		(    __snake_case ):







				"""simple docstring"""






				a			=						"lz4"
				a			=						"lz4"
				a			=						".lz4"




class  _snake_case		(    __snake_case ):







				"""simple docstring"""






				a			=						"xz"
				a			=						"xz"
				a			=						".xz"




class  _snake_case		(    __snake_case ):







				"""simple docstring"""






				a			=						"zstd"
				a			=						"zstd"
				a			=						".zst"





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



											"""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[int]			  =    self.file.__enter__




											class  _snake_case		:







															"""simple docstring"""






															def __init__(      self							:							Tuple      ,    _A							:							str):



																						"""simple docstring"""







																						_SCREAMING_SNAKE_CASE		:						Tuple			  =    file_





															def __enter__(      self							:							Optional[Any]):



																						"""simple docstring"""







																						self._file.__enter__()
																						return self





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



																						"""simple docstring"""







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





															def __iter__(      self							:							int):



																						"""simple docstring"""







																						return iter(self._file)





															def 		_lowerCAmelCase		(      self							:							Optional[Any]):



																						"""simple docstring"""







																						return next(self._file)





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



																						"""simple docstring"""







																						return getattr(self._file      ,    _A)

											def fixed_enter(*_A							:							Tuple      ,    **_A							:							Any):
																		return WrappedFile(_enter(*_A      ,    **_A))

											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    fixed_enter



"""simple docstring"""





import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding




class  _snake_case		(    __snake_case ):







				"""simple docstring"""






				a			=						["image_processor", "tokenizer"]
				a			=						"ChineseCLIPImageProcessor"
				a			=						("BertTokenizer", "BertTokenizerFast")





				def __init__(      self							:							Dict      ,    _A							:							Tuple=None      ,    _A							:							List[Any]=None      ,    **_A							:							int):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Tuple			  =    None
											if "feature_extractor" in kwargs:
																		warnings.warn(
																		    """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
																		    """ instead."""      ,    _A      ,    )
																		_SCREAMING_SNAKE_CASE		:						str			  =    kwargs.pop("""feature_extractor""")

											_SCREAMING_SNAKE_CASE		:						int			  =    image_processor if image_processor is not None else feature_extractor
											if image_processor is None:
																		raise ValueError("""You need to specify an `image_processor`.""")
											if tokenizer is None:
																		raise ValueError("""You need to specify a `tokenizer`.""")

											super().__init__(_A      ,    _A)
											_SCREAMING_SNAKE_CASE		:						Dict			  =    self.image_processor





				def __call__(      self							:							Optional[int]      ,    _A							:							Optional[Any]=None      ,    _A							:							Any=None      ,    _A							:							Tuple=None      ,    **_A							:							int):



											"""simple docstring"""







											if text is None and images is None:
																		raise ValueError("""You have to specify either text or images. Both cannot be none.""")

											if text is not None:
																		_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    self.tokenizer(_A      ,    return_tensors=_A      ,    **_A)

											if images is not None:
																		_SCREAMING_SNAKE_CASE		:						List[Any]			  =    self.image_processor(_A      ,    return_tensors=_A      ,    **_A)

											if text is not None and images is not None:
																		_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    image_features.pixel_values
																		return encoding
											elif text is not None:
																		return encoding
											else:
																		return BatchEncoding(data=dict(**_A)      ,    tensor_type=_A)





				def 		_lowerCAmelCase		(      self							:							str      ,    *_A							:							Any      ,    **_A							:							Any):



											"""simple docstring"""







											return self.tokenizer.batch_decode(*_A      ,    **_A)





				def 		_lowerCAmelCase		(      self							:							Union[str, Any]      ,    *_A							:							List[Any]      ,    **_A							:							Any):



											"""simple docstring"""







											return self.tokenizer.decode(*_A      ,    **_A)





				@property
				def 		_lowerCAmelCase		(      self							:							str):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    self.tokenizer.model_input_names
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    self.image_processor.model_input_names
											return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))





				@property
				def 		_lowerCAmelCase		(      self							:							List[str]):



											"""simple docstring"""







											warnings.warn(
											    """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""      ,    _A      ,    )
											return self.image_processor_class


