

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        SCREAMING_SNAKE_CASE__	(  )  ->					str:
	global _logger
	__lowerCamelCase    :    Any 	=			_logger or logging.getLogger(__name__      )
	return _logger






class 	A_		(						SCREAMING_SNAKE_CASE    ):
							def __init__(		self		:      Dict       ,SCREAMING_SNAKE_CASE__		:      Any):
								__lowerCamelCase    :    Optional[Any] 	=			lock_file
								return None


							def __str__(		self		:      List[str]):
								__lowerCamelCase    :    int 	=			F"The file lock \'{self.lock_file}\' could not be acquired."
								return temp






class 	A_		:
							def __init__(		self		:      Optional[Any]       ,SCREAMING_SNAKE_CASE__		:      str):
								__lowerCamelCase    :    Union[str, Any] 	=			lock
								return None
							def __enter__(		self		:      Optional[Any]):
								return self.lock


							def __exit__(		self		:      Any       ,SCREAMING_SNAKE_CASE__		:      List[str]       ,SCREAMING_SNAKE_CASE__		:      Optional[int]       ,SCREAMING_SNAKE_CASE__		:      int):
								self.lock.release()
								return None






class 	A_		:
							def __init__(		self		:      List[str]       ,SCREAMING_SNAKE_CASE__		:      List[Any]       ,SCREAMING_SNAKE_CASE__		:      Union[str, Any]=-1       ,SCREAMING_SNAKE_CASE__		:      Optional[int]=None):
								__lowerCamelCase    :    Dict 	=			max_filename_length if max_filename_length is not None else 2_5_5
								# Hash the filename if it's too long
								__lowerCamelCase    :    Any 	=			self.hash_filename_if_too_long(SCREAMING_SNAKE_CASE__       ,SCREAMING_SNAKE_CASE__)
								# The path to the lock file.
								__lowerCamelCase    :    int 	=			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    :    List[str] 	=			None

								# The default timeout value.
								__lowerCamelCase    :    Optional[Any] 	=			timeout

								# We use this lock primarily for the lock counter.
								__lowerCamelCase    :    Any 	=			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    :    str 	=			0
								return None
							@property
							def    lowerCAmelCase					(		self		:      List[str]):
								return self._lock_file
							@property
							def    lowerCAmelCase					(		self		:      Any):
								return self._timeout
							@timeout.setter
							def    lowerCAmelCase					(		self		:      List[str]       ,SCREAMING_SNAKE_CASE__		:      Dict):
								__lowerCamelCase    :    Optional[Any] 	=			float(SCREAMING_SNAKE_CASE__)
								return None
							def    lowerCAmelCase					(		self		:      str):
								raise NotImplementedError()
							def    lowerCAmelCase					(		self		:      Any):
								raise NotImplementedError()
							@property
							def    lowerCAmelCase					(		self		:      Optional[int]):
								return self._lock_file_fd is not None
							def    lowerCAmelCase					(		self		:      Tuple       ,SCREAMING_SNAKE_CASE__		:      Tuple=None       ,SCREAMING_SNAKE_CASE__		:      Optional[int]=0.05):
								# Use the default timeout, if no timeout is provided.
								if timeout is None:
									__lowerCamelCase    :    Optional[Any] 	=			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    :    Dict 	=			id(self)
								__lowerCamelCase    :    Any 	=			self._lock_file
								__lowerCamelCase    :    List[Any] 	=			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(SCREAMING_SNAKE_CASE__)
								except:  # noqa
									# Something did go wrong, so decrement the counter.
									with self._thread_lock:
										__lowerCamelCase    :    Optional[Any] 	=			max(0       ,self._lock_counter - 1)

									raise
								return _Acquire_ReturnProxy(lock=self)
							def    lowerCAmelCase					(		self		:      Tuple       ,SCREAMING_SNAKE_CASE__		:      int=False):
								with self._thread_lock:
									if self.is_locked:
										self._lock_counter -= 1

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

											logger().debug(F"Attempting to release lock {lock_id} on {lock_filename}")
											self._release()
											__lowerCamelCase    :    List[str] 	=			0
											logger().debug(F"Lock {lock_id} released on {lock_filename}")

								return None
							def __enter__(		self		:      Optional[int]):
								self.acquire()
								return self
							def __exit__(		self		:      int       ,SCREAMING_SNAKE_CASE__		:      int       ,SCREAMING_SNAKE_CASE__		:      Union[str, Any]       ,SCREAMING_SNAKE_CASE__		:      Tuple):
								self.release()
								return None
							def __del__(		self		:      Optional[Any]):
								self.release(force=SCREAMING_SNAKE_CASE__)
								return None


							def    lowerCAmelCase					(		self		:      Union[str, Any]       ,SCREAMING_SNAKE_CASE__		:      Tuple       ,SCREAMING_SNAKE_CASE__		:      int):
								__lowerCamelCase    :    int 	=			os.path.basename(SCREAMING_SNAKE_CASE__)
								if len(SCREAMING_SNAKE_CASE__) > max_length and max_length > 0:
									__lowerCamelCase    :    Any 	=			os.path.dirname(SCREAMING_SNAKE_CASE__)
									__lowerCamelCase    :    Any 	=			str(hash(SCREAMING_SNAKE_CASE__))
									__lowerCamelCase    :    Dict 	=			filename[: max_length - len(SCREAMING_SNAKE_CASE__) - 8] + '''...''' + hashed_filename + '''.lock'''
									return os.path.join(SCREAMING_SNAKE_CASE__       ,SCREAMING_SNAKE_CASE__)
								else:
									return path






class 	A_		(						SCREAMING_SNAKE_CASE    ):
							def __init__(		self		:      Union[str, Any]       ,SCREAMING_SNAKE_CASE__		:      Union[str, Any]       ,SCREAMING_SNAKE_CASE__		:      List[Any]=-1       ,SCREAMING_SNAKE_CASE__		:      int=None):
								from .file_utils import relative_to_absolute_path

								super().__init__(SCREAMING_SNAKE_CASE__       ,timeout=SCREAMING_SNAKE_CASE__       ,max_filename_length=SCREAMING_SNAKE_CASE__)
								__lowerCamelCase    :    str 	=			'''\\\\?\\''' + relative_to_absolute_path(self.lock_file)
							def    lowerCAmelCase					(		self		:      Tuple):
								__lowerCamelCase    :    Any 	=			os.O_RDWR | os.O_CREAT | os.O_TRUNC

								try:
									__lowerCamelCase    :    Optional[Any] 	=			os.open(self._lock_file       ,SCREAMING_SNAKE_CASE__)
								except OSError:
									pass
								else:
									try:
										msvcrt.locking(SCREAMING_SNAKE_CASE__       ,msvcrt.LK_NBLCK       ,1)
									except OSError:
										os.close(SCREAMING_SNAKE_CASE__)
									else:
										__lowerCamelCase    :    Dict 	=			fd
								return None


							def    lowerCAmelCase					(		self		:      Dict):
								__lowerCamelCase    :    Optional[int] 	=			self._lock_file_fd
								__lowerCamelCase    :    Any 	=			None
								msvcrt.locking(SCREAMING_SNAKE_CASE__       ,msvcrt.LK_UNLCK       ,1)
								os.close(SCREAMING_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 	A_		(						SCREAMING_SNAKE_CASE    ):
							def __init__(		self		:      Optional[int]       ,SCREAMING_SNAKE_CASE__		:      str       ,SCREAMING_SNAKE_CASE__		:      Dict=-1       ,SCREAMING_SNAKE_CASE__		:      List[str]=None):
								__lowerCamelCase    :    Tuple 	=			os.statvfs(os.path.dirname(SCREAMING_SNAKE_CASE__)).f_namemax
								super().__init__(SCREAMING_SNAKE_CASE__       ,timeout=SCREAMING_SNAKE_CASE__       ,max_filename_length=SCREAMING_SNAKE_CASE__)
							def    lowerCAmelCase					(		self		:      Any):
								__lowerCamelCase    :    Optional[Any] 	=			os.O_RDWR | os.O_CREAT | os.O_TRUNC
								__lowerCamelCase    :    Union[str, Any] 	=			os.open(self._lock_file       ,SCREAMING_SNAKE_CASE__)

								try:
									fcntl.flock(SCREAMING_SNAKE_CASE__       ,fcntl.LOCK_EX | fcntl.LOCK_NB)
								except OSError:
									os.close(SCREAMING_SNAKE_CASE__)
								else:
									__lowerCamelCase    :    List[str] 	=			fd
								return None


							def    lowerCAmelCase					(		self		:      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    :    List[str] 	=			self._lock_file_fd
								__lowerCamelCase    :    List[Any] 	=			None
								fcntl.flock(SCREAMING_SNAKE_CASE__       ,fcntl.LOCK_UN)
								os.close(SCREAMING_SNAKE_CASE__)
								return None






class 	A_		(						SCREAMING_SNAKE_CASE    ):
							def    lowerCAmelCase					(		self		:      Tuple):
								__lowerCamelCase    :    Tuple 	=			os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
								try:
									__lowerCamelCase    :    Optional[Any] 	=			os.open(self._lock_file       ,SCREAMING_SNAKE_CASE__)
								except OSError:
									pass
								else:
									__lowerCamelCase    :    int 	=			fd
								return None


							def    lowerCAmelCase					(		self		:      List[str]):
								os.close(self._lock_file_fd)
								__lowerCamelCase    :    Optional[Any] 	=			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_torch_available


a		={
    """configuration_bigbird_pegasus""": [
        """BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """BigBirdPegasusConfig""",
        """BigBirdPegasusOnnxConfig""",
    ],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					a		=[
					    """BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """BigBirdPegasusForCausalLM""",
					    """BigBirdPegasusForConditionalGeneration""",
					    """BigBirdPegasusForQuestionAnswering""",
					    """BigBirdPegasusForSequenceClassification""",
					    """BigBirdPegasusModel""",
					    """BigBirdPegasusPreTrainedModel""",
					]


if TYPE_CHECKING:
					from .configuration_bigbird_pegasus import (
					    BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP,
					    BigBirdPegasusConfig,
					    BigBirdPegasusOnnxConfig,
					)

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_bigbird_pegasus import (
										    BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST,
										    BigBirdPegasusForCausalLM,
										    BigBirdPegasusForConditionalGeneration,
										    BigBirdPegasusForQuestionAnswering,
										    BigBirdPegasusForSequenceClassification,
										    BigBirdPegasusModel,
										    BigBirdPegasusPreTrainedModel,
										)


else:
					import sys

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




