3
g                 @   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re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 )aw  
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] https://sourceforge.net/p/roundup/code/ci/default/tree/roundup/backends/portalocker.py
[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| j S | S )zCGet a filedescriptor from something which could be a file or an fd.fileno)hasattrr   )f r
   U/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/core/files/locks.py_fd   s    r   nt)	POINTER	StructureUnionbyrefc_int64c_ulongc_void_psizeofwindll)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   2   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!   7   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 j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   O   s    c             C   s0   t j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   U   s    c             C   s   dS )NFr
   )r	   r+   r
   r
   r   r   e   s    c             C   s   dS )NTr
   )r	   r
   r
   r   r   i   s    c             C   s.   yt jt| | dS  tk
r(   dS X d S )NTF)fcntlflockr   BlockingIOError)r	   r+   r
   r
   r   r   m   s
    c             C   s   t jt| t j dS )NT)r0   r1   r   ZLOCK_UN)r	   r
   r
   r   r   t   s    )r   r   r   r   r   )'__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   ,

