
    qiq                    T   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(  r G d de      Zn@	 d dlZej.                  ej0                  ej2                  ej4                  fZdZ G d de      ZddgZy# eef$ r Y w xY w)    )annotationsN)suppress)EAGAINENOSYSEWOULDBLOCK)Path)cast   )BaseFileLock)ensure_directory_existsFwin32c                       e Zd ZdZddZddZy)UnixFileLockzHUses the :func:`fcntl.flock` to hard lock the lock file on unix systems.c                    t         NNotImplementedErrorselfs    @/opt/pipecat/venv/lib/python3.12/site-packages/filelock/_unix.py_acquirezUnixFileLock._acquire       %%    c                    t         r   r   r   s    r   _releasezUnixFileLock._release   r   r   NreturnNone)__name__
__module____qualname____doc__r   r    r   r   r   r      s    V	&	&r   r   Tc                  (    e Zd ZdZddZddZddZy)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.
        c                   t        | j                         t        j                  t        j                  z  }t        t        dd       }|||z  }|t        j                  z  }| j                         }	 t        j                  | j                  ||      }| j                  rBt        t              5  t        j                   || j"                  j$                         d d d        	 t'        j(                  |t&        j*                  t&        j,                  z         t        j.                  |      j0                  dk(  rt        j2                  |       y || j"                  _        y # t        $ r= | j                  r/t        | j                        j                  j                         rY y  t        $ rm t        | j                        j                         s 	 t        j                  | j                  |t        j                   z  |      }n# t        $ r Y Y y w xY wY w xY w# 1 sw Y   GxY w# t6        $ r}t        j2                  |       |j8                  t:        k(  rmt        t6              5  t        | j                        j=                          d d d        n# 1 sw Y   nxY w| j?                          | jA                          Y d }~y |j8                  tB        tD        hvr Y d }~y d }~ww xY w)N
O_NOFOLLOWr   )#r   	lock_fileosO_RDWRO_TRUNCgetattrO_CREAT
_open_modeopenFileNotFoundErrorr   parentexistsPermissionErrorhas_explicit_moder   fchmod_contextmodefcntlflockLOCK_EXLOCK_NBfstatst_nlinkcloselock_file_fdOSErrorerrnor   unlink_fallback_to_soft_lockr   r   r   )r   
open_flags
o_nofollow	open_modefd	exceptions         r   r   zUnixFileLock._acquire.   s(   #DNN3RZZ/J \48J%j(
"**$J)IWWT^^ZC" %%o. 6IIb$--"4"4564B => 88B<((A-HHRL13DMM.K %  >>d4>>&:&A&A&H&H&J"  DNN+224rzzk1I9UB(  6 6  	??f,!'* 6T^^,3356 6 6//1MMO??6;*?? @	s   3!E" /+H#5H, "AH&-H3HH	HHHHHH),	K-57K(,$J	K(J"	'K(
K((K-c                    ddl m} t        j                  dd       ddlm}m} t        | |      r|| _        y || _        y )Nr
   )SoftFileLockzDflock not supported on this filesystem, falling back to SoftFileLock   )
stacklevel)AsyncSoftFileLockBaseAsyncFileLock)	_softrI   warningswarnasynciorL   rM   
isinstance	__class__)r   rI   rL   rM   s       r   rB   z#UnixFileLock._fallback_to_soft_lock_   s1    +MM`mnoE2<TCT2U.DN[gDNr   c                f   t        d| j                  j                        }d | j                  _        t        t              5  t        | j                        j                          d d d        t        j                  |t        j                         t        j                  |       y # 1 sw Y   CxY w)Nint)r	   r5   r>   r   r?   r   r'   rA   r7   r8   LOCK_UNr(   r=   )r   rF   s     r   r   zUnixFileLock._releaseg   ss    eT]]778B)-DMM&'" .T^^$++-.KKEMM*HHRL. .s   $B''B0Nr   )r   r    r!   r"   r   rB   r   r#   r   r   r   r   %   s    	/	4b	h	r   	has_fcntl)
__future__r   r(   sysrO   
contextlibr   r@   r   r   r   pathlibr   typingr	   _apir   _utilr   rW   platformr   r7   r8   r9   r:   rV   _ImportErrorAttributeError__all__r#   r   r   <module>rd      s    " 	 
   - -    * 	<<7&| &[[%--F 	H| HX a ( s   2B B'&B'