
    ړi                    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)UnixFileLockHUses the :func:`fcntl.flock` to hard lock the lock file on unix systems.c                    t         NNotImplementedErrorselfs    5/tmp/pip-target-gsye3yef/lib/python/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   r   c                X   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,                  |      j.                  dk(  rt        j0                  |       y || j                   _        y # t        $ rm t        | j                        j                         s 	 t        j                  | j                  |t        j                   z  |      }n# t        $ r Y Y y w xY wY Cw xY w# 1 sw Y   xY w# t4        $ r}t        j0                  |       |j6                  t8        k(  rmt        t4              5  t        | j                        j;                          d d d        n# 1 sw Y   nxY w| j=                          | j?                          Y d }~y |j6                  t@        tB        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PermissionErrorr   existsFileNotFoundError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.= #  DNN+224rzzk1I9UB(  6 6  	??f,!'* 6T^^,3356 6 6//1MMO??6;*?? @	sx   3!E" /+G#5G( "-G3GG	GGGGGG%(	J)17J$($I	J$I	'J$J$$J)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_lockR   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._releaseZ   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    V(	4T	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 	;| ;~ G ( s   2B B'&B'