B
    ©0H[¸  ã            	   @   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jjZee_eeeeeege_ ejj!Z!ee!_eeeeege!_ dd„ Z"dd„ Z#nfyddl$Z$e$jZe$jZe$jZW n6 e%e&fk
�rr   d Z ZZdd„ Z"dd„ Z#Y nX dd„ Z"dd„ Z#dS )au  
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] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203
[2] http://sourceforge.net/p/roundup/code/ci/default/tree/roundup/backends/portalocker.py
[3] http://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
   ú[C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\core\files\locks.pyÚ_fd   s    r   Únt)	ÚsizeofÚc_ulongÚc_void_pÚc_int64Ú	StructureÚUnionÚPOINTERÚwindllÚbyref)Ú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   0   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!   5   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%   c             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   M   s    r   c             C   s0   t  t| ƒ¡}tƒ }t|dddt|ƒƒ}t|ƒS )Nr   l     þ )r'   r(   r   r%   ÚUnlockFileExr   r*   )r	   r,   r-   r.   r
   r
   r   r   S   s    r   c             C   s   dS )NFr
   )r	   r+   r
   r
   r   r   c   s    c             C   s   dS )NTr
   )r	   r
   r
   r   r   g   s    c             C   s   t  t| ƒ|¡}|dkS )Nr   )ÚfcntlÚflockr   )r	   r+   r.   r
   r
   r   r   k   s    c             C   s   t  t| ƒt j¡}|dkS )Nr   )r0   r1   r   ZLOCK_UN)r	   r.   r
   r
   r   r   o   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LPOVERLAPPEDÚkernel32r)   ÚrestypeÚargtypesr/   r   r   r0   ÚImportErrorÚAttributeErrorr
   r
   r
   r   Ú<module>   sJ   ,

