a
    Lcòf  ã                	   @   sŠ  d Z ddlZdZdd„ Zejdk�r"d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ƒkrŽeZneZeZG dd„ deƒZG dd„ de	ƒZG dd„ deƒZeeƒZe
dƒZejZee_eeeeeege_ ej!Z!ee!_eeeeege!_ dd„ Z"dd„ Z#ndzddl$Z$e$jZe$jZe$jZW n4 e%e&f�yt   d Z ZZdd„ Z"dd„ Z#Y n0 dd„ Z"dd„ Z#dS )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                 C   s   t | dƒr|  ¡ S | S )zCGet a filedescriptor from something which could be a file or an fd.Úfileno)Úhasattrr   ©Úf© r   úT/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/core/files/locks.pyÚ_fd   s    r   Únt)	ÚPOINTERÚ	StructureÚUnionÚWinDLLÚbyrefÚc_int64Úc_ulongÚc_void_pÚsizeof)ÚBOOLÚDWORDÚHANDLEé   é   c                   @   s   e Zd ZdefdefgZdS )Ú_OFFSETZOffsetZ
OffsetHighN)Ú__name__Ú
__module__Ú__qualname__r   Ú_fields_r   r   r   r   r   9   s   r   c                   @   s"   e Zd ZdgZdefdefgZdS )Ú_OFFSET_UNIONÚ_offsetZPointerN)r   r   r    Ú_anonymous_r   ÚPVOIDr!   r   r   r   r   r"   <   s   r"   c                   @   s.   e Zd ZdgZdefdefdefdefgZdS )Ú
OVERLAPPEDZ_offset_unionZInternalZInternalHighZhEventN)r   r   r    r$   Ú	ULONG_PTRr"   r   r!   r   r   r   r   r&   @   s   ür&   Úkernel32c                 C   s2   t  t| ƒ¡}tƒ }t||dddt|ƒƒ}t|ƒS ©Nr   l     þ )ÚmsvcrtÚget_osfhandler   r&   Ú
LockFileExr   Úbool)r
   ÚflagsÚhfileÚ
overlappedÚretr   r   r   r   T   s    r   c                 C   s0   t  t| ƒ¡}tƒ }t|dddt|ƒƒ}t|ƒS r)   )r*   r+   r   r&   ÚUnlockFileExr   r-   )r
   r/   r0   r1   r   r   r   r   Z   s    r   c                 C   s   dS )NFr   ©r
   r.   r   r   r   r   l   s    c                 C   s   dS ©NTr   r	   r   r   r   r   p   s    c                 C   s0   zt  t| ƒ|¡ W dS  ty*   Y dS 0 d S )NTF)ÚfcntlÚflockr   ÚBlockingIOErrorr3   r   r   r   r   v   s
    c                 C   s   t  t| ƒt j¡ dS r4   )r5   r6   r   ZLOCK_UNr	   r   r   r   r   }   s    )'Ú__doc__ÚosÚ__all__r   Únamer*   Úctypesr   r   r   r   r   r   r   r   r   Zctypes.wintypesr   r   r   r   r   r   r'   r%   r   r"   r&   ZLPOVERLAPPEDr(   r,   ÚrestypeÚargtypesr2   r   r   r5   ÚImportErrorÚAttributeErrorr   r   r   r   Ú<module>   sL   ,	

