

import os
from typing import Optional

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


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






	@classmethod
	def    lowerCAmelCase_							(		cls					,UpperCamelCase       )						->    Optional[Any]:
					return super()._strip_protocol(UpperCamelCase       ).lstrip("/"       )






	def    lowerCAmelCase_							(		self       )						->    List[Any]:







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






	def    lowerCAmelCase_							(		self					,UpperCamelCase       )						->    Union[str, Any]:
					return self.file.open().read()






	def    lowerCAmelCase_							(		self					,UpperCamelCase					,UpperCamelCase = "rb"					,UpperCamelCase=None					,UpperCamelCase=True					,UpperCamelCase=None					,**UpperCamelCase					,)						->    str:
					snake_case__      :List[str]         =   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						(			_A ):
	_A          =   'bz2'
	_A          =   'bz2'
	_A          =   '.bz2'




class 					_snake_case						(			_A ):
	_A          =   'gzip'
	_A          =   'gzip'
	_A          =   '.gz'




class 					_snake_case						(			_A ):
	_A          =   'lz4'
	_A          =   'lz4'
	_A          =   '.lz4'




class 					_snake_case						(			_A ):
	_A          =   'xz'
	_A          =   'xz'
	_A          =   '.xz'




class 					_snake_case						(			_A ):
	_A          =   'zstd'
	_A          =   'zstd'
	_A          =   '.zst'






	def __init__(		self					,UpperCamelCase					,UpperCamelCase = "rb"					,UpperCamelCase = None					,UpperCamelCase = None					,UpperCamelCase = DEFAULT_BLOCK_SIZE					,**UpperCamelCase					,)						->    List[Any]:
					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
					snake_case__      :Dict         =   self.file.__enter__


					class 					_snake_case						:






						def __init__(		self					,UpperCamelCase       )						->    Tuple:
										snake_case__      :Union[str, Any]         =   file_






						def __enter__(		self       )						->    Any:
										self._file.__enter__()
										return self






						def __exit__(		self					,*UpperCamelCase					,**UpperCamelCase       )						->    Optional[Any]:
										self._file.__exit__(*UpperCamelCase					,**UpperCamelCase       )






						def __iter__(		self       )						->    Optional[int]:
										return iter(self._file       )






						def    lowerCAmelCase_							(		self       )						->    List[str]:
										return next(self._file       )






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

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

					snake_case__      :List[Any]         =   fixed_enter







from ...utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_torch_available,
    is_transformers_available,
)


try:
	if not (is_transformers_available() and is_torch_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
	from .multicontrolnet import MultiControlNetModel
	from .pipeline_controlnet import StableDiffusionControlNetPipeline
	from .pipeline_controlnet_imgaimg import StableDiffusionControlNetImgaImgPipeline
	from .pipeline_controlnet_inpaint import StableDiffusionControlNetInpaintPipeline


if is_transformers_available() and is_flax_available():
	from .pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline