
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__       (       ):




			"""simple docstring"""


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





class 			_lowerCAmelCase      (			__a ):




				def __init__(      self       ,       _UpperCamelCase  )       ->   List[Any]:
							lowerCAmelCase_      			=			lock_file
							return None




				def __str__(      self  )       ->   List[Any]:
							lowerCAmelCase_      			=			f"""The file lock '{self.lock_file}' could not be acquired."""
							return temp





class 			_lowerCAmelCase      :




				def __init__(      self       ,       _UpperCamelCase  )       ->   str:
							lowerCAmelCase_      			=			lock
							return None




				def __enter__(      self  )       ->   List[Any]:
							return self.lock




				def __exit__(      self       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase  )       ->   Optional[Any]:
							self.lock.release()
							return None





class 			_lowerCAmelCase      :




				def __init__(      self       ,       _UpperCamelCase       ,       _UpperCamelCase=-1       ,       _UpperCamelCase=None  )       ->   str:
							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(_UpperCamelCase       ,       _UpperCamelCase  )
							# 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   __a		(      self  )       ->   Union[str, Any]:
							return self._lock_file




				@property
				def   __a		(      self  )       ->   Any:
							return self._timeout




				@timeout.setter
				def   __a		(      self       ,       _UpperCamelCase  )       ->   Union[str, Any]:
							lowerCAmelCase_      			=			float(_UpperCamelCase  )
							return None




				def   __a		(      self  )       ->   Optional[int]:
							raise NotImplementedError()




				def   __a		(      self  )       ->   int:
							raise NotImplementedError()




				@property
				def   __a		(      self  )       ->   Dict:
							return self._lock_file_fd is not None




				def   __a		(      self       ,       _UpperCamelCase=None       ,       _UpperCamelCase=0.05  )       ->   Union[str, Any]:
							# 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(_UpperCamelCase  )
							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   __a		(      self       ,       _UpperCamelCase=False  )       ->   Dict:
							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  )       ->   List[str]:
							self.acquire()
							return self




				def __exit__(      self       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase  )       ->   List[str]:
							self.release()
							return None




				def __del__(      self  )       ->   Union[str, Any]:
							self.release(force=_UpperCamelCase  )
							return None




				def   __a		(      self       ,       _UpperCamelCase       ,       _UpperCamelCase  )       ->   str:
							lowerCAmelCase_      			=			os.path.basename(_UpperCamelCase  )
							if len(_UpperCamelCase  ) > max_length and max_length > 0:
										lowerCAmelCase_      			=			os.path.dirname(_UpperCamelCase  )
										lowerCAmelCase_      			=			str(hash(_UpperCamelCase  )  )
										lowerCAmelCase_      			=			filename[: max_length - len(_UpperCamelCase  ) - 8] + "..." + hashed_filename + ".lock"
										return os.path.join(_UpperCamelCase       ,       _UpperCamelCase  )
							else:
										return path





class 			_lowerCAmelCase      (			__a ):




				def __init__(      self       ,       _UpperCamelCase       ,       _UpperCamelCase=-1       ,       _UpperCamelCase=None  )       ->   Tuple:
							from .file_utils import relative_to_absolute_path

							super().__init__(_UpperCamelCase       ,       timeout=_UpperCamelCase       ,       max_filename_length=_UpperCamelCase  )
							lowerCAmelCase_      			=			"\\\\?\\" + relative_to_absolute_path(self.lock_file  )




				def   __a		(      self  )       ->   int:
							lowerCAmelCase_      			=			os.O_RDWR | os.O_CREAT | os.O_TRUNC

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




				def   __a		(      self  )       ->   Union[str, Any]:
							lowerCAmelCase_      			=			self._lock_file_fd
							lowerCAmelCase_      			=			None
							msvcrt.locking(_UpperCamelCase       ,       msvcrt.LK_UNLCK       ,       1  )
							os.close(_UpperCamelCase  )

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





class 			_lowerCAmelCase      (			__a ):




				def __init__(      self       ,       _UpperCamelCase       ,       _UpperCamelCase=-1       ,       _UpperCamelCase=None  )       ->   Optional[Any]:
							lowerCAmelCase_      			=			os.statvfs(os.path.dirname(_UpperCamelCase  )  ).f_namemax
							super().__init__(_UpperCamelCase       ,       timeout=_UpperCamelCase       ,       max_filename_length=_UpperCamelCase  )




				def   __a		(      self  )       ->   List[str]:
							lowerCAmelCase_      			=			os.O_RDWR | os.O_CREAT | os.O_TRUNC
							lowerCAmelCase_      			=			os.open(self._lock_file       ,       _UpperCamelCase  )

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




				def   __a		(      self  )       ->   Union[str, Any]:
							# 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(_UpperCamelCase       ,       fcntl.LOCK_UN  )
							os.close(_UpperCamelCase  )
							return None





class 			_lowerCAmelCase      (			__a ):




				def   __a		(      self  )       ->   Any:
							lowerCAmelCase_      			=			os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
							try:
										lowerCAmelCase_      			=			os.open(self._lock_file       ,       _UpperCamelCase  )
							except OSError:
										pass
							else:
										lowerCAmelCase_      			=			fd
							return None




				def   __a		(      self  )       ->   Dict:
							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_torch_available,
)


_A     =  {
    "configuration_wav2vec2": ["WAV_2_VEC_2_PRETRAINED_CONFIG_ARCHIVE_MAP", "Wav2Vec2Config"],
    "feature_extraction_wav2vec2": ["Wav2Vec2FeatureExtractor"],
    "processing_wav2vec2": ["Wav2Vec2Processor"],
    "tokenization_wav2vec2": ["Wav2Vec2CTCTokenizer", "Wav2Vec2Tokenizer"],
}


try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A     =  [
			    "WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST",
			    "Wav2Vec2ForAudioFrameClassification",
			    "Wav2Vec2ForCTC",
			    "Wav2Vec2ForMaskedLM",
			    "Wav2Vec2ForPreTraining",
			    "Wav2Vec2ForSequenceClassification",
			    "Wav2Vec2ForXVector",
			    "Wav2Vec2Model",
			    "Wav2Vec2PreTrainedModel",
			]

try:
			if not is_tf_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A     =  [
			    "TF_WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST",
			    "TFWav2Vec2ForCTC",
			    "TFWav2Vec2Model",
			    "TFWav2Vec2PreTrainedModel",
			    "TFWav2Vec2ForSequenceClassification",
			]

try:
			if not is_flax_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A     =  [
			    "FlaxWav2Vec2ForCTC",
			    "FlaxWav2Vec2ForPreTraining",
			    "FlaxWav2Vec2Model",
			    "FlaxWav2Vec2PreTrainedModel",
			]


if TYPE_CHECKING:
			from .configuration_wavaveca import WAV_2_VEC_2_PRETRAINED_CONFIG_ARCHIVE_MAP, WavaVecaConfig
			from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
			from .processing_wavaveca import WavaVecaProcessor
			from .tokenization_wavaveca import WavaVecaCTCTokenizer, WavaVecaTokenizer

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_wavaveca import (
						    WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST,
						    WavaVecaForAudioFrameClassification,
						    WavaVecaForCTC,
						    WavaVecaForMaskedLM,
						    WavaVecaForPreTraining,
						    WavaVecaForSequenceClassification,
						    WavaVecaForXVector,
						    WavaVecaModel,
						    WavaVecaPreTrainedModel,
						)

			try:
						if not is_tf_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tf_wavaveca import (
						    TF_WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFWavaVecaForCTC,
						    TFWavaVecaForSequenceClassification,
						    TFWavaVecaModel,
						    TFWavaVecaPreTrainedModel,
						)

			try:
						if not is_flax_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tf_wavaveca import (
						    FlaxWavaVecaForCTC,
						    FlaxWavaVecaForPreTraining,
						    FlaxWavaVecaModel,
						    FlaxWavaVecaPreTrainedModel,
						)


else:
			import sys

			_A     =  _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



