o
    'ij                     @  sz   d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 ddlmZ ddlmZmZ G d	d
 d
eZd
gZdS )    )annotationsN)suppress)EACCESEEXIST)Path   )BaseFileLock)ensure_directory_existsraise_on_not_writable_filec                   @  s$   e Zd ZdZd	ddZd	ddZdS )
SoftFileLocka  
    Portable file lock based on file existence.

    Unlike :class:`UnixFileLock <filelock.UnixFileLock>` and :class:`WindowsFileLock <filelock.WindowsFileLock>`,
    this lock does not use OS-level locking primitives. Instead, it creates the lock file with ``O_CREAT | O_EXCL``
    and treats its existence as the lock indicator. This makes it work on any filesystem but leaves stale lock files
    behind if the process crashes without releasing the lock.
    returnNonec              
   C  s   t | j t| j tjtjB tjB tjB }ttdd }|d ur$||O }zt	| j|| j
j}W n* tyZ } z|jtksH|jtkrGtjdksO W Y d }~d S W Y d }~d S d }~ww || j
_d S )N
O_NOFOLLOWwin32)r
   	lock_filer	   osO_WRONLYO_CREATO_EXCLO_TRUNCgetattropen_contextmodeOSErrorerrnor   r   sysplatformlock_file_fd)selfflags
o_nofollowfile_handler	exception r$   J/home/jeff/fluffinator/venv/lib/python3.10/site-packages/filelock/_soft.py_acquire   s0   


zSoftFileLock._acquirec                 C  sb   | j jd usJ t| j j d | j _tt t| j  W d    d S 1 s*w   Y  d S )N)	r   r   r   closer   r   r   r   unlink)r   r$   r$   r%   _release.   s   
"zSoftFileLock._releaseN)r   r   )__name__
__module____qualname____doc__r&   r)   r$   r$   r$   r%   r      s    
	r   )
__future__r   r   r   
contextlibr   r   r   r   pathlibr   _apir   _utilr	   r
   r   __all__r$   r$   r$   r%   <module>   s    *