ó
TRšNc           @   s8  d  Z  d Z d Z yR d d l Z d d l Z d d l Z e j Z d Z	 e j
 Z e j   Z d	 Z Wn e e f k
 r} n Xy1 d d l Z e j Z e j	 Z	 e j Z d
 Z Wn e e f k
 rČ n Xd   Z e d	 k ró d   Z d   Z nA e d
 k rd   Z d   Z n  d Z Z	 Z d   Z d   Z d S(   s  
Portable file locking utilities.

Based partially on example by Jonathan Feignberg <jdf@pobox.com> in the Python
Cookbook, licensed under the Python Software License.

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203

Example Usage::

    >>> from django.core.files import locks
    >>> f = open('./file', 'wb')
    >>> locks.lock(f, locks.LOCK_EX)
    >>> f.write('Django')
    >>> f.close()
t   LOCK_EXt   LOCK_SHt   LOCK_NBt   lockt   unlocki˙˙˙˙Ni    t   ntt   posixc         C   s   t  |  d  r |  j   p |  S(   sC   Get a filedescriptor from something which could be a file or an fd.t   fileno(   t   hasattrR   (   t   f(    (    sD   /home/panlixing/Python_Projects/gaeseries/django/core/files/locks.pyt   fd+   s    c         C   s2   t  j t |    } t  j | | d d t  d  S(   Ni    i  ˙˙(   t	   win32filet   _get_osfhandleR
   t
   LockFileExt   __overlapped(   t   filet   flagst   hfile(    (    sD   /home/panlixing/Python_Projects/gaeseries/django/core/files/locks.pyR   0   s    c         C   s/   t  j t |    } t  j | d d t  d  S(   Ni    i  ˙˙(   R   R   R
   t   UnlockFileExR   (   R   R   (    (    sD   /home/panlixing/Python_Projects/gaeseries/django/core/files/locks.pyR   4   s    c         C   s   t  j t |   |  d  S(   N(   t   fcntlt   lockfR
   (   R   R   (    (    sD   /home/panlixing/Python_Projects/gaeseries/django/core/files/locks.pyR   8   s    c         C   s   t  j t |   t  j  d  S(   N(   R   R   R
   t   LOCK_UN(   R   (    (    sD   /home/panlixing/Python_Projects/gaeseries/django/core/files/locks.pyR   ;   s    c         C   s   d  S(   N(    (   R   R   (    (    sD   /home/panlixing/Python_Projects/gaeseries/django/core/files/locks.pyR   B   s    c         C   s   d  S(   N(    (   R   (    (    sD   /home/panlixing/Python_Projects/gaeseries/django/core/files/locks.pyR   E   s    (   s   LOCK_EXs   LOCK_SHs   LOCK_NBs   locks   unlock(   t   __doc__t   __all__t   Nonet   system_typet   win32conR   t
   pywintypest   LOCKFILE_EXCLUSIVE_LOCKR    R   t   LOCKFILE_FAIL_IMMEDIATELYR   t
   OVERLAPPEDR   t   ImportErrort   AttributeErrorR   R
   R   R   (    (    (    sD   /home/panlixing/Python_Projects/gaeseries/django/core/files/locks.pyt   <module>   s>   		
			
				