


'''simple docstring'''






import logging
import os
import threading
import time


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

try:
  import msvcrt
except ImportError:
  __A					:  Tuple											=      None

try:
  import fcntl
except ImportError:
  __A					:  Any											=      None


# Backward compatibility
# ------------------------------------------------
try:
  TimeoutError
except NameError:
  __A					:  List[str]											=      OSError


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

__A					:  Any											=      "3.0.12"


__A					:  str											=      None







def 				UpperCamelCase_			(    ):
  '''simple docstring'''





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






class    __snake_case       (   _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    def __init__(   self    :  Dict    ,						lowerCamelCase    :  List[Any]		)   ->  Dict:
      lowerCAmelCase_			:      Union[str, Any]			=   lock_file
      return None





    def __str__(   self    :  str		)   ->  Dict:
      lowerCAmelCase_			:      Optional[int]			=   F'The file lock \'{self.lock_file}\' could not be acquired.'
      return temp







class    __snake_case       :







    """simple docstring"""



    def __init__(   self    :  Dict    ,						lowerCamelCase    :  Union[str, Any]		)   ->  Union[str, Any]:
      lowerCAmelCase_			:      int			=   lock
      return None

    def __enter__(   self    :  Union[str, Any]		)   ->  Union[str, Any]:
      return self.lock





    def __exit__(   self    :  Any    ,						lowerCamelCase    :  int    ,						lowerCamelCase    :  str    ,						lowerCamelCase    :  Tuple		)   ->  int:
      self.lock.release()
      return None







class    __snake_case       :







    """simple docstring"""



    def __init__(   self    :  Optional[Any]    ,						lowerCamelCase    :  int    ,						lowerCamelCase    :  Optional[int]=-1    ,						lowerCamelCase    :  Optional[Any]=None		)   ->  Optional[Any]:
      lowerCAmelCase_			:      Optional[int]			=   max_filename_length if max_filename_length is not None else 2_55
      # Hash the filename if it's too long
      lowerCAmelCase_			:      int			=   self.hash_filename_if_too_long(lowerCamelCase    ,						lowerCamelCase		)
      # The path to the lock file.
      lowerCAmelCase_			:      Dict			=   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_			:      Any			=   None

      # The default timeout value.
      lowerCAmelCase_			:      List[Any]			=   timeout

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

    @property
    def __lowercase   (   self    :  Dict		)   ->  Optional[int]:
      return self._lock_file

    @property
    def __lowercase   (   self    :  Dict		)   ->  Dict:
      return self._timeout

    @timeout.setter
    def __lowercase   (   self    :  Optional[int]    ,						lowerCamelCase    :  int		)   ->  Union[str, Any]:
      lowerCAmelCase_			:      Optional[Any]			=   float(lowerCamelCase		)
      return None

    def __lowercase   (   self    :  Optional[int]		)   ->  List[Any]:
      raise NotImplementedError()

    def __lowercase   (   self    :  Dict		)   ->  Tuple:
      raise NotImplementedError()

    @property
    def __lowercase   (   self    :  Optional[int]		)   ->  int:
      return self._lock_file_fd is not None

    def __lowercase   (   self    :  Any    ,						lowerCamelCase    :  List[Any]=None    ,						lowerCamelCase    :  List[str]=0.05		)   ->  str:
      # Use the default timeout, if no timeout is provided.
      if timeout is None:
        lowerCAmelCase_			:      List[str]			=   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_			:      Optional[int]			=   self._lock_file
      lowerCAmelCase_			:      str			=   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(lowerCamelCase		)
      except:  # noqa
        # Something did go wrong, so decrement the counter.
        with self._thread_lock:
          lowerCAmelCase_			:      Dict			=   max(0    ,						self._lock_counter - 1		)

        raise
      return _Acquire_ReturnProxy(lock=self		)

    def __lowercase   (   self    :  str    ,						lowerCamelCase    :  int=False		)   ->  List[str]:
      with self._thread_lock:
        if self.is_locked:
          self._lock_counter -= 1

          if self._lock_counter == 0 or force:
            lowerCAmelCase_			:      List[str]			=   id(self		)
            lowerCAmelCase_			:      List[Any]			=   self._lock_file

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

      return None

    def __enter__(   self    :  Union[str, Any]		)   ->  Dict:
      self.acquire()
      return self

    def __exit__(   self    :  Tuple    ,						lowerCamelCase    :  List[str]    ,						lowerCamelCase    :  Any    ,						lowerCamelCase    :  Optional[Any]		)   ->  List[Any]:
      self.release()
      return None

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





    def __lowercase   (   self    :  Tuple    ,						lowerCamelCase    :  str    ,						lowerCamelCase    :  int		)   ->  str:
      lowerCAmelCase_			:      List[str]			=   os.path.basename(lowerCamelCase		)
      if len(lowerCamelCase		) > max_length and max_length > 0:
        lowerCAmelCase_			:      Dict			=   os.path.dirname(lowerCamelCase		)
        lowerCAmelCase_			:      int			=   str(hash(lowerCamelCase		)		)
        lowerCAmelCase_			:      List[Any]			=   filename[: max_length - len(lowerCamelCase		) - 8] + """...""" + hashed_filename + """.lock"""
        return os.path.join(lowerCamelCase    ,						lowerCamelCase		)
      else:
        return path







class    __snake_case       (   _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    def __init__(   self    :  List[Any]    ,						lowerCamelCase    :  Dict    ,						lowerCamelCase    :  Union[str, Any]=-1    ,						lowerCamelCase    :  Optional[int]=None		)   ->  str:
      from .file_utils import relative_to_absolute_path

      super().__init__(lowerCamelCase    ,						timeout=lowerCamelCase    ,						max_filename_length=lowerCamelCase		)
      lowerCAmelCase_			:      List[str]			=   """\\\\?\\""" + relative_to_absolute_path(self.lock_file		)

    def __lowercase   (   self    :  List[str]		)   ->  Tuple:
      lowerCAmelCase_			:      List[Any]			=   os.O_RDWR | os.O_CREAT | os.O_TRUNC

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





    def __lowercase   (   self    :  List[Any]		)   ->  List[str]:
      lowerCAmelCase_			:      Optional[int]			=   self._lock_file_fd
      lowerCAmelCase_			:      List[Any]			=   None
      msvcrt.locking(lowerCamelCase    ,						msvcrt.LK_UNLCK    ,						1		)
      os.close(lowerCamelCase		)

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







class    __snake_case       (   _SCREAMING_SNAKE_CASE):







    """simple docstring"""



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

    def __lowercase   (   self    :  Any		)   ->  Tuple:
      lowerCAmelCase_			:      int			=   os.O_RDWR | os.O_CREAT | os.O_TRUNC
      lowerCAmelCase_			:      Tuple			=   os.open(self._lock_file    ,						lowerCamelCase		)

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





    def __lowercase   (   self    :  Optional[Any]		)   ->  Optional[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_			:      Optional[int]			=   self._lock_file_fd
      lowerCAmelCase_			:      Optional[int]			=   None
      fcntl.flock(lowerCamelCase    ,						fcntl.LOCK_UN		)
      os.close(lowerCamelCase		)
      return None







class    __snake_case       (   _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    def __lowercase   (   self    :  Optional[Any]		)   ->  Optional[Any]:
      lowerCAmelCase_			:      Any			=   os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
      try:
        lowerCAmelCase_			:      Optional[int]			=   os.open(self._lock_file    ,						lowerCamelCase		)
      except OSError:
        pass
      else:
        lowerCAmelCase_			:      Any			=   fd
      return None





    def __lowercase   (   self    :  List[str]		)   ->  str:
      os.close(self._lock_file_fd		)
      lowerCAmelCase_			:      str			=   None

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







__A					:  Optional[Any]											=      None

if msvcrt:
  __A					:  Any											=      WindowsFileLock
elif fcntl:
  __A					:  Dict											=      UnixFileLock
else:
  __A					:  int											=      SoftFileLock

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







'''simple docstring'''






def 				UpperCamelCase_			(    A__					:   int = 10_00					):
  '''simple docstring'''





  lowerCAmelCase_			:      Optional[Any]			=   3
  lowerCAmelCase_			:      Dict			=   0
  while a < n:
    if a % 3 == 0 or a % 5 == 0:
      result += a
    elif a % 15 == 0:
      result -= a
    a += 1
  return result


if __name__ == "__main__":
  print(F'''{solution() = }''')



