


'''simple docstring'''



import logging
import os
import threading
import time


try:
	import warnings
except ImportError:
	_lowercase    :    List[str]			     =  None

try:
	import msvcrt
except ImportError:
	_lowercase    :    Optional[Any]			     =  None

try:
	import fcntl
except ImportError:
	_lowercase    :    List[str]			     =  None


# Backward compatibility
# ------------------------------------------------
try:
	TimeoutError
except NameError:
	_lowercase    :    Tuple			     =  OSError


# Data
# ------------------------------------------------
_lowercase    :    Optional[int]			     =  [
    """Timeout""",
    """BaseFileLock""",
    """WindowsFileLock""",
    """UnixFileLock""",
    """SoftFileLock""",
    """FileLock""",
]

_lowercase    :    List[str]			     =  """3.0.12"""


_lowercase    :    Tuple			     =  None


def    lowerCamelCase__   ( ):




						'''simple docstring'''






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






class  UpperCamelCase__(     lowerCAmelCase ):




				def __init__(	self    :				Any   ,					lowerCAmelCase    :				List[Any]   )->  Tuple:

										"""simple docstring"""




										UpperCAmelCase         =			lock_file
										return None





				def __str__(	self    :				Tuple   )->  Optional[int]:

										"""simple docstring"""




										UpperCAmelCase         =			F"""The file lock '{self.lock_file}' could not be acquired."""
										return temp







class  UpperCamelCase__:




				def __init__(	self    :				Optional[int]   ,					lowerCAmelCase    :				str   )->  Tuple:

										"""simple docstring"""




										UpperCAmelCase         =			lock
										return None




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

										"""simple docstring"""




										return self.lock





				def __exit__(	self    :				Tuple   ,					lowerCAmelCase    :				int   ,					lowerCAmelCase    :				str   ,					lowerCAmelCase    :				Optional[Any]   )->  str:

										"""simple docstring"""




										self.lock.release()
										return None







class  UpperCamelCase__:




				def __init__(	self    :				Dict   ,					lowerCAmelCase    :				int   ,					lowerCAmelCase    :				List[Any]=-1   ,					lowerCAmelCase    :				Dict=None   )->  Any:

										"""simple docstring"""




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

										# The default timeout value.
										UpperCAmelCase         =			timeout

										# We use this lock primarily for the lock counter.
										UpperCAmelCase         =			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         =			0
										return None




				@property
				def   a__(	self    :				Dict   )->  Tuple:

										"""simple docstring"""




										return self._lock_file




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

										"""simple docstring"""




										return self._timeout




				@timeout.setter
				def   a__(	self    :				str   ,					lowerCAmelCase    :				Tuple   )->  Any:

										"""simple docstring"""




										UpperCAmelCase         =			float(UpperCamelCase__   )
										return None




				def   a__(	self    :				Any   )->  Any:

										"""simple docstring"""




										raise NotImplementedError()




				def   a__(	self    :				Dict   )->  List[Any]:

										"""simple docstring"""




										raise NotImplementedError()




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

										"""simple docstring"""




										return self._lock_file_fd is not None




				def   a__(	self    :				int   ,					lowerCAmelCase    :				Optional[int]=None   ,					lowerCAmelCase    :				Tuple=0.05   )->  List[str]:

										"""simple docstring"""




										if timeout is None:
																UpperCAmelCase         =			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         =			id(self   )
										UpperCAmelCase         =			self._lock_file
										UpperCAmelCase         =			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         =			max(0   ,					self._lock_counter - 1   )

																raise
										return _Acquire_ReturnProxy(lock=self   )




				def   a__(	self    :				int   ,					lowerCAmelCase    :				Optional[int]=False   )->  Union[str, Any]:

										"""simple docstring"""




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

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

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

										return None




				def __enter__(	self    :				Optional[Any]   )->  Optional[int]:

										"""simple docstring"""




										self.acquire()
										return self




				def __exit__(	self    :				Dict   ,					lowerCAmelCase    :				List[Any]   ,					lowerCAmelCase    :				Optional[Any]   ,					lowerCAmelCase    :				Union[str, Any]   )->  List[Any]:

										"""simple docstring"""




										self.release()
										return None




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

										"""simple docstring"""




										self.release(force=UpperCamelCase__   )
										return None





				def   a__(	self    :				Tuple   ,					lowerCAmelCase    :				Any   ,					lowerCAmelCase    :				Optional[Any]   )->  str:

										"""simple docstring"""




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







class  UpperCamelCase__(     lowerCAmelCase ):




				def __init__(	self    :				Optional[int]   ,					lowerCAmelCase    :				Any   ,					lowerCAmelCase    :				Any=-1   ,					lowerCAmelCase    :				Optional[int]=None   )->  Union[str, Any]:

										"""simple docstring"""




										from .file_utils import relative_to_absolute_path

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




				def   a__(	self    :				Optional[Any]   )->  Optional[int]:

										"""simple docstring"""




										UpperCAmelCase         =			os.O_RDWR | os.O_CREAT | os.O_TRUNC

										try:
																UpperCAmelCase         =			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         =			fd
										return None





				def   a__(	self    :				int   )->  int:

										"""simple docstring"""




										UpperCAmelCase         =			self._lock_file_fd
										UpperCAmelCase         =			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  UpperCamelCase__(     lowerCAmelCase ):




				def __init__(	self    :				Any   ,					lowerCAmelCase    :				List[Any]   ,					lowerCAmelCase    :				List[Any]=-1   ,					lowerCAmelCase    :				Optional[Any]=None   )->  Any:

										"""simple docstring"""




										UpperCAmelCase         =			os.statvfs(os.path.dirname(UpperCamelCase__   )   ).f_namemax
										super().__init__(UpperCamelCase__   ,					timeout=UpperCamelCase__   ,					max_filename_length=UpperCamelCase__   )




				def   a__(	self    :				Optional[int]   )->  str:

										"""simple docstring"""




										UpperCAmelCase         =			os.O_RDWR | os.O_CREAT | os.O_TRUNC
										UpperCAmelCase         =			os.open(self._lock_file   ,					UpperCamelCase__   )

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





				def   a__(	self    :				List[Any]   )->  Tuple:

										"""simple docstring"""




										UpperCAmelCase         =			self._lock_file_fd
										UpperCAmelCase         =			None
										fcntl.flock(UpperCamelCase__   ,					fcntl.LOCK_UN   )
										os.close(UpperCamelCase__   )
										return None







class  UpperCamelCase__(     lowerCAmelCase ):




				def   a__(	self    :				str   )->  Tuple:

										"""simple docstring"""




										UpperCAmelCase         =			os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
										try:
																UpperCAmelCase         =			os.open(self._lock_file   ,					UpperCamelCase__   )
										except OSError:
																pass
										else:
																UpperCAmelCase         =			fd
										return None





				def   a__(	self    :				Any   )->  List[str]:

										"""simple docstring"""




										os.close(self._lock_file_fd   )
										UpperCAmelCase         =			None

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







_lowercase    :    str			     =  None

if msvcrt:
	_lowercase    :    int			     =  WindowsFileLock
elif fcntl:
	_lowercase    :    Tuple			     =  UnixFileLock
else:
	_lowercase    :    List[str]			     =  SoftFileLock

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





'''simple docstring'''



def    lowerCamelCase__   ( A     :    str  ):




						'''simple docstring'''






						assert column_title.isupper()
						UpperCAmelCase         =			0
						UpperCAmelCase         =			len(A  ) - 1
						UpperCAmelCase         =			0

						while index >= 0:
												UpperCAmelCase         =			(ord(column_title[index]  ) - 64) * pow(26   ,     A  )
												answer += value
												power += 1
												index -= 1

						return answer


if __name__ == "__main__":
	from doctest import testmod

	testmod()





