o
    /i                  	   @  s   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZ ddlmZ dd	lmZ d
ZejdkrJG dd deZn&zd dlZejejejejfZW n eefye   Y nw dZG dd deZddgZdS )    )annotationsN)suppress)EAGAINENOSYSEWOULDBLOCK)Path)cast   )BaseFileLock)ensure_directory_existsFwin32c                   @  s$   e Zd ZdZd	ddZd	ddZdS )
UnixFileLockzHUses the :func:`fcntl.flock` to hard lock the lock file on unix systems.returnNonec                 C     t NNotImplementedErrorself r   H/home/kim/smarthome/.venv/lib/python3.10/site-packages/filelock/_unix.py_acquire      UnixFileLock._acquirec                 C  r   r   r   r   r   r   r   _release   r   UnixFileLock._releaseNr   r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r      s    
r   Tc                   @  s.   e Zd ZdZdddZdddZddd	Zd
S )r   a0  
        Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems.

        Lock file cleanup: Unix and macOS delete the lock file reliably after release, even in
        multi-threaded scenarios. Unlike Windows, Unix allows unlinking files that other processes
        have open.
        r   r   c                 C  s  t | j tjtjB }ttdd }|d ur||O }|tjO }|  }z
t| j||}W n@ t	yB   | jrAt
| jj rAY d S   tyl   t
| j sP zt| j|tj @ |}W n t	yi   Y Y d S w Y nw | jrtt t|| jj W d    n1 sw   Y  zt|tjtjB  W nO ty } zCt| |jtkrtt t
| j  W d    n1 sw   Y  |   |   W Y d }~d S |jtthvr܂ W Y d }~d S d }~ww t |j!dkrt| d S || j_"d S )N
O_NOFOLLOWr   )#r   	lock_fileosO_RDWRO_TRUNCgetattrO_CREATZ
_open_modeopenFileNotFoundErrorr   parentexistsPermissionErrorZhas_explicit_moder   fchmod_contextmodefcntlflockLOCK_EXLOCK_NBOSErrorcloseerrnor   unlink_fallback_to_soft_lockr   r   r   fstatst_nlinklock_file_fd)r   Z
open_flagsZ
o_nofollowZ	open_modefd	exceptionr   r   r   r   .   s\   

	



r   c                 C  sH   ddl m} tjddd ddlm}m} t| |r|| _d S || _d S )Nr	   )SoftFileLockzDflock not supported on this filesystem, falling back to SoftFileLock   )
stacklevel)AsyncSoftFileLockBaseAsyncFileLock)	Z_softr?   warningswarnZasynciorB   rC   
isinstance	__class__)r   r?   rB   rC   r   r   r   r9   _   s   z#UnixFileLock._fallback_to_soft_lockc                 C  s   t d| jj}d | j_tt t| j  W d    n1 s!w   Y  t	|tj
 tt t| W d    d S 1 sBw   Y  d S )Nint)r   r/   r<   r   r5   r   r#   r8   r1   r2   LOCK_UNr$   r6   )r   r=   r   r   r   r   g   s   

"r   Nr   )r   r   r    r!   r   r9   r   r   r   r   r   r   %   s
    

1	has_fcntl)
__future__r   r$   sysrD   
contextlibr   r7   r   r   r   pathlibr   typingr   Z_apir
   Z_utilr   rJ   platformr   r1   r2   r3   r4   rI   _ImportErrorAttributeError__all__r   r   r   r   <module>   s0    

M