




import logging
import os
import threading
import time


try:
					import warnings
except ImportError:
					__A								=       None

try:
					import msvcrt
except ImportError:
					__A								=       None

try:
					import fcntl
except ImportError:
					__A								=       None


# Backward compatibility
# ------------------------------------------------
try:
					TimeoutError
except NameError:
					__A								=       OSError


# Data
# ------------------------------------------------
__A								=       [
    '''Timeout''',
    '''BaseFileLock''',
    '''WindowsFileLock''',
    '''UnixFileLock''',
    '''SoftFileLock''',
    '''FileLock''',
]

__A								=       '''3.0.12'''


__A								=       None







def      lowerCamelCase_						(			)	->			Optional[Any]:





				"""simple docstring"""


				global _logger
				__lowerCamelCase									=       _logger or logging.getLogger(__name__ )
				return _logger







class        __lowerCAmelCase					(			lowerCamelCase_					):

			"""simple docstring"""







			def __init__( self     ,		lowerCamelCase__				)       -> Optional[int]:



							'''simple docstring'''
							__lowerCamelCase									=       lock_file
							return None






			def __str__( self				)       -> str:



							'''simple docstring'''
							__lowerCamelCase									=       f"""The file lock \'{self.lock_file}\' could not be acquired."""
							return temp







class        __lowerCAmelCase					:

			"""simple docstring"""







			def __init__( self     ,		lowerCamelCase__				)       -> Optional[int]:



							'''simple docstring'''
							__lowerCamelCase									=       lock
							return None


			def __enter__( self				)       -> Tuple:



							'''simple docstring'''
							return self.lock






			def __exit__( self     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__				)       -> Optional[Any]:



							'''simple docstring'''
							self.lock.release()
							return None







class        __lowerCAmelCase					:

			"""simple docstring"""







			def __init__( self     ,		lowerCamelCase__     ,		lowerCamelCase__=-1     ,		lowerCamelCase__=None				)       -> List[str]:



							'''simple docstring'''
							__lowerCamelCase									=       max_filename_length if max_filename_length is not None else 255
							# Hash the filename if it's too long
							__lowerCamelCase									=       self.hash_filename_if_too_long(snake_case__     ,		snake_case__				)
							# The path to the lock file.
							__lowerCamelCase									=       lock_file

							# The file descriptor for the *_lock_file* as it is returned by the
							# os.open() function.
							# This file lock is only NOT None, if the object currently holds the
							# lock.
							__lowerCamelCase									=       None

							# The default timeout value.
							__lowerCamelCase									=       timeout

							# We use this lock primarily for the lock counter.
							__lowerCamelCase									=       threading.Lock()

							# The lock counter is used for implementing the nested locking
							# mechanism. Whenever the lock is acquired, the counter is increased and
							# the lock is only released, when this value is 0 again.
							__lowerCamelCase									=       0
							return None


			@property
			def  lowercase_       ( self				)       -> List[Any]:



							'''simple docstring'''
							return self._lock_file


			@property
			def  lowercase_       ( self				)       -> Union[str, Any]:



							'''simple docstring'''
							return self._timeout


			@timeout.setter
			def  lowercase_       ( self     ,		lowerCamelCase__				)       -> Optional[Any]:



							'''simple docstring'''
							__lowerCamelCase									=       float(snake_case__				)
							return None


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



							'''simple docstring'''
							raise NotImplementedError()


			def  lowercase_       ( self				)       -> Optional[int]:



							'''simple docstring'''
							raise NotImplementedError()


			@property
			def  lowercase_       ( self				)       -> Optional[int]:



							'''simple docstring'''
							return self._lock_file_fd is not None


			def  lowercase_       ( self     ,		lowerCamelCase__=None     ,		lowerCamelCase__=0.05				)       -> Dict:



							'''simple docstring'''
							# Use the default timeout, if no timeout is provided.
							if timeout is None:
											__lowerCamelCase									=       self.timeout

							# Increment the number right at the beginning.
							# We can still undo it, if something fails.
							with self._thread_lock:
											self._lock_counter += 1

							__lowerCamelCase									=       id(self				)
							__lowerCamelCase									=       self._lock_file
							__lowerCamelCase									=       time.time()
							try:
											while True:
															with self._thread_lock:
																			if not self.is_locked:
																							logger().debug(f"""Attempting to acquire lock {lock_id} on {lock_filename}"""				)
																							self._acquire()

															if self.is_locked:
																			logger().debug(f"""Lock {lock_id} acquired on {lock_filename}"""				)
																			break
															elif timeout >= 0 and time.time() - start_time > timeout:
																			logger().debug(f"""Timeout on acquiring lock {lock_id} on {lock_filename}"""				)
																			raise Timeout(self._lock_file				)
															else:
																			logger().debug(
																			    f"""Lock {lock_id} not acquired on {lock_filename}, waiting {poll_intervall} seconds ..."""				)
																			time.sleep(snake_case__				)
							except:  # noqa
											# Something did go wrong, so decrement the counter.
											with self._thread_lock:
															__lowerCamelCase									=       max(0     ,		self._lock_counter - 1				)

											raise
							return _Acquire_ReturnProxy(lock=self				)


			def  lowercase_       ( self     ,		lowerCamelCase__=False				)       -> Optional[Any]:



							'''simple docstring'''
							with self._thread_lock:
											if self.is_locked:
															self._lock_counter -= 1

															if self._lock_counter == 0 or force:
																			__lowerCamelCase									=       id(self				)
																			__lowerCamelCase									=       self._lock_file

																			logger().debug(f"""Attempting to release lock {lock_id} on {lock_filename}"""				)
																			self._release()
																			__lowerCamelCase									=       0
																			logger().debug(f"""Lock {lock_id} released on {lock_filename}"""				)

							return None


			def __enter__( self				)       -> Tuple:



							'''simple docstring'''
							self.acquire()
							return self


			def __exit__( self     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__				)       -> List[str]:



							'''simple docstring'''
							self.release()
							return None


			def __del__( self				)       -> Union[str, Any]:



							'''simple docstring'''
							self.release(force=snake_case__				)
							return None






			def  lowercase_       ( self     ,		lowerCamelCase__     ,		lowerCamelCase__				)       -> Optional[int]:



							'''simple docstring'''
							__lowerCamelCase									=       os.path.basename(snake_case__				)
							if len(snake_case__				) > max_length and max_length > 0:
											__lowerCamelCase									=       os.path.dirname(snake_case__				)
											__lowerCamelCase									=       str(hash(snake_case__				)				)
											__lowerCamelCase									=       filename[: max_length - len(snake_case__				) - 8] + '...' + hashed_filename + '.lock'
											return os.path.join(snake_case__     ,		snake_case__				)
							else:
											return path







class        __lowerCAmelCase					(			lowerCamelCase_					):

			"""simple docstring"""







			def __init__( self     ,		lowerCamelCase__     ,		lowerCamelCase__=-1     ,		lowerCamelCase__=None				)       -> List[str]:



							'''simple docstring'''
							from .file_utils import relative_to_absolute_path

							super().__init__(snake_case__     ,		timeout=snake_case__     ,		max_filename_length=snake_case__				)
							__lowerCamelCase									=       '\\\\?\\' + relative_to_absolute_path(self.lock_file				)


			def  lowercase_       ( self				)       -> Union[str, Any]:



							'''simple docstring'''
							__lowerCamelCase									=       os.O_RDWR | os.O_CREAT | os.O_TRUNC

							try:
											__lowerCamelCase									=       os.open(self._lock_file     ,		snake_case__				)
							except OSError:
											pass
							else:
											try:
															msvcrt.locking(snake_case__     ,		msvcrt.LK_NBLCK     ,		1				)
											except OSError:
															os.close(snake_case__				)
											else:
															__lowerCamelCase									=       fd
							return None






			def  lowercase_       ( self				)       -> str:



							'''simple docstring'''
							__lowerCamelCase									=       self._lock_file_fd
							__lowerCamelCase									=       None
							msvcrt.locking(snake_case__     ,		msvcrt.LK_UNLCK     ,		1				)
							os.close(snake_case__				)

							try:
											os.remove(self._lock_file				)
							# Probably another instance of the application
							# that acquired the file lock.
							except OSError:
											pass
							return None







class        __lowerCAmelCase					(			lowerCamelCase_					):

			"""simple docstring"""







			def __init__( self     ,		lowerCamelCase__     ,		lowerCamelCase__=-1     ,		lowerCamelCase__=None				)       -> Dict:



							'''simple docstring'''
							__lowerCamelCase									=       os.statvfs(os.path.dirname(snake_case__				)				).f_namemax
							super().__init__(snake_case__     ,		timeout=snake_case__     ,		max_filename_length=snake_case__				)


			def  lowercase_       ( self				)       -> int:



							'''simple docstring'''
							__lowerCamelCase									=       os.O_RDWR | os.O_CREAT | os.O_TRUNC
							__lowerCamelCase									=       os.open(self._lock_file     ,		snake_case__				)

							try:
											fcntl.flock(snake_case__     ,		fcntl.LOCK_EX | fcntl.LOCK_NB				)
							except OSError:
											os.close(snake_case__				)
							else:
											__lowerCamelCase									=       fd
							return None






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



							'''simple docstring'''
							# Do not remove the lockfile:
							#
							#   https://github.com/benediktschmitt/py-filelock/issues/31
							#   https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition
							__lowerCamelCase									=       self._lock_file_fd
							__lowerCamelCase									=       None
							fcntl.flock(snake_case__     ,		fcntl.LOCK_UN				)
							os.close(snake_case__				)
							return None







class        __lowerCAmelCase					(			lowerCamelCase_					):

			"""simple docstring"""







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



							'''simple docstring'''
							__lowerCamelCase									=       os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
							try:
											__lowerCamelCase									=       os.open(self._lock_file     ,		snake_case__				)
							except OSError:
											pass
							else:
											__lowerCamelCase									=       fd
							return None






			def  lowercase_       ( self				)       -> Union[str, Any]:



							'''simple docstring'''
							os.close(self._lock_file_fd				)
							__lowerCamelCase									=       None

							try:
											os.remove(self._lock_file				)
							# The file is already deleted and that's what we want.
							except OSError:
											pass
							return None




__A								=       None

if msvcrt:
					__A								=       WindowsFileLock
elif fcntl:
					__A								=       UnixFileLock
else:
					__A								=       SoftFileLock

					if warnings is not None:
										warnings.warn("only soft file lock is available")








from typing import TYPE_CHECKING

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


UpperCamelCase__ :   Optional[Any]						=							{
    '''configuration_whisper''': ['''WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''WhisperConfig''', '''WhisperOnnxConfig'''],
    '''feature_extraction_whisper''': ['''WhisperFeatureExtractor'''],
    '''processing_whisper''': ['''WhisperProcessor'''],
    '''tokenization_whisper''': ['''WhisperTokenizer'''],
}

try:
						if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						UpperCamelCase__ :   str						=							['''WhisperTokenizerFast''']

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						UpperCamelCase__ :   List[Any]						=							[
						    '''WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''WhisperForConditionalGeneration''',
						    '''WhisperModel''',
						    '''WhisperPreTrainedModel''',
						    '''WhisperForAudioClassification''',
						]

try:
						if not is_tf_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						UpperCamelCase__ :   Tuple						=							[
						    '''TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''TFWhisperForConditionalGeneration''',
						    '''TFWhisperModel''',
						    '''TFWhisperPreTrainedModel''',
						]

try:
						if not is_flax_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						UpperCamelCase__ :   List[str]						=							[
						    '''FlaxWhisperForConditionalGeneration''',
						    '''FlaxWhisperModel''',
						    '''FlaxWhisperPreTrainedModel''',
						    '''FlaxWhisperForAudioClassification''',
						]


if TYPE_CHECKING:
						from .configuration_whisper import WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP, WhisperConfig, WhisperOnnxConfig
						from .feature_extraction_whisper import WhisperFeatureExtractor
						from .processing_whisper import WhisperProcessor
						from .tokenization_whisper import WhisperTokenizer

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_whisper_fast import WhisperTokenizerFast

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_whisper import (
												    WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    WhisperForAudioClassification,
												    WhisperForConditionalGeneration,
												    WhisperModel,
												    WhisperPreTrainedModel,
												)

						try:
												if not is_tf_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_tf_whisper import (
												    TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    TFWhisperForConditionalGeneration,
												    TFWhisperModel,
												    TFWhisperPreTrainedModel,
												)

						try:
												if not is_flax_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_flax_whisper import (
												    FlaxWhisperForAudioClassification,
												    FlaxWhisperForConditionalGeneration,
												    FlaxWhisperModel,
												    FlaxWhisperPreTrainedModel,
												)

else:
						import sys

						UpperCamelCase__ :   Optional[Any]						=							_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



