
    g                     :   d Z ddlZdZd Zej                  dk(  rddlZddlmZmZm	Z	m
Z
mZmZmZmZmZ ddlmZmZmZ dZdZd	Z ee       ee      k7  reZneZeZ G d
 de      Z G d de	      Z G d de      Z ee      Z e
d      Zej<                  Zee_        eeeeeege_         ejB                  Z!ee!_        eeeeege!_         d Z"d Z#y	 ddl$Z$e$j(                  Ze$j*                  Ze$j,                  Zd Z"d Z#y# e%e&f$ r dxZxZZd Z"d Z#Y yw xY w)am  
Portable file locking utilities.

Based partially on an example by Jonathan Feignberg in the Python
Cookbook [1] (licensed under the Python Software License) and a ctypes port by
Anatoly Techtonik for Roundup [2] (license [3]).

[1] https://code.activestate.com/recipes/65203/
[2] https://sourceforge.net/p/roundup/code/ci/default/tree/roundup/backends/portalocker.py  # NOQA
[3] https://sourceforge.net/p/roundup/code/ci/default/tree/COPYING.txt

Example Usage::

    >>> from django.core.files import locks
    >>> with open('./file', 'wb') as f:
    ...     locks.lock(f, locks.LOCK_EX)
    ...     f.write('Django')
    N)LOCK_EXLOCK_SHLOCK_NBlockunlockc                 >    t        | d      r| j                         S | S )zCGet a filedescriptor from something which could be a file or an fd.fileno)hasattrr	   fs    o/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/core/files/locks.py_fdr      s     H-188:414    nt)	POINTER	StructureUnionWinDLLbyrefc_int64c_ulongc_void_psizeof)BOOLDWORDHANDLE      c                       e Zd ZdefdefgZy)_OFFSETOffset
OffsetHighN)__name__
__module____qualname__r   _fields_ r   r   r    r    :   s    u%e'<=r   r    c                   "    e Zd ZdgZdefdefgZy)_OFFSET_UNION_offsetPointerN)r#   r$   r%   _anonymous_r    PVOIDr&   r'   r   r   r)   r)   =   s     k(9e*<=r   r)   c                   .    e Zd ZdgZdefdefdefdefgZy)
OVERLAPPED_offset_unionInternalInternalHighhEventN)r#   r$   r%   r,   	ULONG_PTRr)   r   r&   r'   r   r   r/   r/   A   s1    &'#Y'm,v	
r   r/   kernel32c           
          t        j                  t        |             }t               }t	        ||dddt        |            }t        |      S Nr   l      )msvcrtget_osfhandler   r/   
LockFileExr   bool)r   flagshfile
overlappedrets        r   r   r   U   s@    $$SV,\
q!Zz9JKCyr   c           	          t        j                  t        |             }t               }t	        |dddt        |            }t        |      S r7   )r8   r9   r   r/   UnlockFileExr   r;   )r   r=   r>   r?   s       r   r   r   [   s>    $$SV,\
5!Q
E*4EFCyr   c                 b    	 t        j                  t        |       |       y# t        $ r Y yw xY w)NTF)fcntlflockr   BlockingIOErrorr   r<   s     r   r   r   w   s.    CFE*" s   " 	..c                 ^    t        j                  t        |       t         j                         yNT)rC   rD   r   LOCK_UNr   s    r   r   r   ~   s    KKA.r   c                      y)NFr'   rF   s     r   r   r   m   s    r   c                      yrH   r'   r   s    r   r   r   q   s    r   )'__doc__os__all__r   namer8   ctypesr   r   r   r   r   r   r   r   r   ctypes.wintypesr   r   r   r   r   r   r4   r-   r    r)   r/   LPOVERLAPPEDr5   r:   restypeargtypesrA   r   r   rC   ImportErrorAttributeErrorr'   r   r   <module>rW      sa  & 

=5
 77d?
 
 
 43GGG g&**		E>) >> >
Y 
 :&L j!H$$JJ!5%|LJ((LL#UE5,GL------ 		- ( &''''G		s   (D DD