
`Tc           @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z e Z e j d k rd   Z	 d   Z
 y d d l Z d Z d Z e j j j Z d   Z	 e j j j Z e j j j Z e j j j Z e j j j Z e Z d	   Z
 Wn e k
 r n Xd
   Z n e j Z e Z d S(   s  
    werkzeug.posixemulation
    ~~~~~~~~~~~~~~~~~~~~~~~

    Provides a POSIX emulation for some features that are relevant to
    web applications.  The main purpose is to simplify support for
    systems such as Windows NT that are not 100% POSIX compatible.

    Currently this only implements a :func:`rename` function that
    follows POSIX semantics.  Eg: if the target file already exists it
    will be replaced without asking.

    This module was introduced in 0.6.1 and is not a public interface.
    It might become one in later versions of Werkzeug.

    :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
iNt   ntc         C   s   t  S(   N(   t   False(   t   srct   dst(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/posixemulation.pyt   <lambda>   s    c         C   s   t  S(   N(   R   (   R   R   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/posixemulation.pyR      s    i   i   c         C   s   t  |  t  s' t |  t j    }  n  t  | t  sN t | t j    } n  t |  |  ra t Sd } t } xM | r | d k  r t |  | t t	 B } | sp t
 j d  | d 7} qp qp W| S(   Ni    id   gMbP?i   (   t
   isinstancet   unicodet   syst   getfilesystemencodingt   _rename_atomict   TrueR   t   _MoveFileExt   _MOVEFILE_REPLACE_EXISTINGt   _MOVEFILE_WRITE_THROUGHt   timet   sleep(   R   R   t   retryt   rv(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/posixemulation.pyt   _rename'   s    
c         C   s   t  d  d d d d d d  } | d k r. t Szz d } t } xc | r | d k  r t |  | d  d  t t B|  } | r t |  } Pq@ t j d  | d 7} q@ W| SWd  t	 |  Xd  S(   Ni    i  s   Werkzeug renameiid   gMbP?i   (
   t   _CreateTransactiont   NoneR   t   _MoveFileTransactedR   R   t   _CommitTransactionR   R   t   _CloseHandle(   R   R   t   taR   R   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/posixemulation.pyR	   ?   s"    c         C   s   t  |  |  r d  Sy t j |  |  Wn t k
 r } | j t j k rQ   n  d | t j d t j	  f } t j | |  t j |  |  y t j
 |  Wq t k
 r q Xn Xd  S(   Ns   %s-%08xi    (   R   t   ost   renamet   OSErrort   errnot   EEXISTt   randomt   randintR   t   maxintt   unlinkt	   Exception(   R   R   t   et   old(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/posixemulation.pyR   V   s    (   t   __doc__R   R   R   R   R   R   t   can_rename_open_filet   nameR   R	   t   ctypesR   R   t   windllt   kernel32t   MoveFileExWR   t   ktmw32t   CreateTransactionR   t   CommitTransactionR   t   MoveFileTransactedWR   t   CloseHandleR   R
   R"   R   (    (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/posixemulation.pyt   <module>   s4   				