


'''simple docstring'''
import logging
import os
import threading
import time


try:
		import warnings
except ImportError:
		__snake_case							   =  None

try:
		import msvcrt
except ImportError:
		__snake_case							   =  None

try:
		import fcntl
except ImportError:
		__snake_case							   =  None


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


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

__snake_case							   =  '''3.0.12'''


__snake_case							   =  None


def     a   (    )						->			Tuple:



					'''simple docstring'''






					global _logger
					UpperCamelCase__     :Dict							      =				_logger or logging.getLogger(__name__     )
					return _logger
class      lowercase			(							A__      ):

		"""simple docstring"""

		def __init__(	self					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[Any]							      =				lock_file
							return None




		def __str__(	self							):

							'''simple docstring'''


							UpperCamelCase__     :Tuple							      =				F'''The file lock \'{self.lock_file}\' could not be acquired.'''
							return temp



class      lowercase			:

		"""simple docstring"""

		def __init__(	self					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :Union[str, Any]							      =				lock
							return None




		def __enter__(	self							):

							'''simple docstring'''


							return self.lock




		def __exit__(	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							self.lock.release()
							return None



class      lowercase			:

		"""simple docstring"""

		def __init__(	self					,     UpperCamelCase_					,     UpperCamelCase_=-1					,     UpperCamelCase_=None							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[int]							      =				max_filename_length if max_filename_length is not None else 255
							# Hash the filename if it's too long
							UpperCamelCase__     :Any							      =				self.hash_filename_if_too_long(UpperCamelCase_					,     UpperCamelCase_							)
							# The path to the lock file.
							UpperCamelCase__     :List[Any]							      =				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.
							UpperCamelCase__     :int							      =				None

							# The default timeout value.
							UpperCamelCase__     :Tuple							      =				timeout

							# We use this lock primarily for the lock counter.
							UpperCamelCase__     :List[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.
							UpperCamelCase__     :Union[str, Any]							      =				0
							return None




		@property
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							return self._lock_file




		@property
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							return self._timeout




		@timeout.setter
		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				float(UpperCamelCase_							)
							return None




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							raise NotImplementedError()




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							raise NotImplementedError()




		@property
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							return self._lock_file_fd is not None




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_=None					,     UpperCamelCase_=0.05							):

							'''simple docstring'''


							if timeout is None:
												UpperCamelCase__     :Tuple							      =				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

							UpperCamelCase__     :int							      =				id(self							)
							UpperCamelCase__     :Optional[int]							      =				self._lock_file
							UpperCamelCase__     :Tuple							      =				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:
																	UpperCamelCase__     :Dict							      =				max(0					,     self._lock_counter - 1							)

												raise
							return _Acquire_ReturnProxy(lock=self							)




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_=False							):

							'''simple docstring'''


							with self._thread_lock:
												if self.is_locked:
																	self._lock_counter -= 1

																	if self._lock_counter == 0 or force:
																						UpperCamelCase__     :List[str]							      =				id(self							)
																						UpperCamelCase__     :Optional[int]							      =				self._lock_file

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

							return None




		def __enter__(	self							):

							'''simple docstring'''


							self.acquire()
							return self




		def __exit__(	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							self.release()
							return None




		def __del__(	self							):

							'''simple docstring'''


							self.release(force=UpperCamelCase_							)
							return None




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :List[Any]							      =				os.path.basename(UpperCamelCase_							)
							if len(UpperCamelCase_							) > max_length and max_length > 0:
												UpperCamelCase__     :Union[str, Any]							      =				os.path.dirname(UpperCamelCase_							)
												UpperCamelCase__     :int							      =				str(hash(UpperCamelCase_							)							)
												UpperCamelCase__     :Optional[Any]							      =				filename[: max_length - len(UpperCamelCase_							) - 8] + '''...''' + hashed_filename + '''.lock'''
												return os.path.join(UpperCamelCase_					,     UpperCamelCase_							)
							else:
												return path



class      lowercase			(							A__      ):

		"""simple docstring"""

		def __init__(	self					,     UpperCamelCase_					,     UpperCamelCase_=-1					,     UpperCamelCase_=None							):

							'''simple docstring'''


							from .file_utils import relative_to_absolute_path

							super().__init__(UpperCamelCase_					,     timeout=UpperCamelCase_					,     max_filename_length=UpperCamelCase_							)
							UpperCamelCase__     :Any							      =				'''\\\\?\\''' + relative_to_absolute_path(self.lock_file							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[Any]							      =				os.O_RDWR | os.O_CREAT | os.O_TRUNC

							try:
												UpperCamelCase__     :int							      =				os.open(self._lock_file					,     UpperCamelCase_							)
							except OSError:
												pass
							else:
												try:
																	msvcrt.locking(UpperCamelCase_					,     msvcrt.LK_NBLCK					,     1							)
												except OSError:
																	os.close(UpperCamelCase_							)
												else:
																	UpperCamelCase__     :Any							      =				fd
							return None




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Dict							      =				self._lock_file_fd
							UpperCamelCase__     :List[str]							      =				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      lowercase			(							A__      ):

		"""simple docstring"""

		def __init__(	self					,     UpperCamelCase_					,     UpperCamelCase_=-1					,     UpperCamelCase_=None							):

							'''simple docstring'''


							UpperCamelCase__     :Any							      =				os.statvfs(os.path.dirname(UpperCamelCase_							)							).f_namemax
							super().__init__(UpperCamelCase_					,     timeout=UpperCamelCase_					,     max_filename_length=UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :List[Any]							      =				os.O_RDWR | os.O_CREAT | os.O_TRUNC
							UpperCamelCase__     :Optional[int]							      =				os.open(self._lock_file					,     UpperCamelCase_							)

							try:
												fcntl.flock(UpperCamelCase_					,     fcntl.LOCK_EX | fcntl.LOCK_NB							)
							except OSError:
												os.close(UpperCamelCase_							)
							else:
												UpperCamelCase__     :Optional[Any]							      =				fd
							return None




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :List[Any]							      =				self._lock_file_fd
							UpperCamelCase__     :Dict							      =				None
							fcntl.flock(UpperCamelCase_					,     fcntl.LOCK_UN							)
							os.close(UpperCamelCase_							)
							return None



class      lowercase			(							A__      ):

		"""simple docstring"""

		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Tuple							      =				os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
							try:
												UpperCamelCase__     :Optional[int]							      =				os.open(self._lock_file					,     UpperCamelCase_							)
							except OSError:
												pass
							else:
												UpperCamelCase__     :List[Any]							      =				fd
							return None




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							os.close(self._lock_file_fd							)
							UpperCamelCase__     :int							      =				None

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



__snake_case							   =  None

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

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



'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tokenizers_available,
    is_torch_available,
)


__snake_case							   =  {'''configuration_reformer''': ['''REFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ReformerConfig''']}

try:
		if not is_sentencepiece_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							   =  ['''ReformerTokenizer''']

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							   =  ['''ReformerTokenizerFast''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							   =  [
		    '''REFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''ReformerAttention''',
		    '''ReformerForMaskedLM''',
		    '''ReformerForQuestionAnswering''',
		    '''ReformerForSequenceClassification''',
		    '''ReformerLayer''',
		    '''ReformerModel''',
		    '''ReformerModelWithLMHead''',
		    '''ReformerPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_reformer import REFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, ReformerConfig

		try:
				if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_reformer import ReformerTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_reformer_fast import ReformerTokenizerFast

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_reformer import (
				    REFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ReformerAttention,
				    ReformerForMaskedLM,
				    ReformerForQuestionAnswering,
				    ReformerForSequenceClassification,
				    ReformerLayer,
				    ReformerModel,
				    ReformerModelWithLMHead,
				    ReformerPreTrainedModel,
				)

else:
		import sys

		__snake_case							   =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)