ó
Žâ0_c           @   sc   d  Z  d d l Z d d l Z d d l m Z d d l m Z d g Z d   Z d
 e	 d	  Z
 d S(   s   
Move a file in the safest way possible::

    >>> from django.core.files.move import file_move_safe
    >>> file_move_safe("/tmp/old_file", "/tmp/new_file")
i˙˙˙˙N(   t   copystat(   t   lockst   file_move_safec         C   s{   t  t j d  rA y t j j |  |  SWqA t k
 r= t SXn  t j j t j j |    t j j t j j |   k S(   Nt   samefile(   t   hasattrt   ost   pathR   t   OSErrort   Falset   normcaset   abspath(   t   srct   dst(    (    s8   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/move.pyt	   _samefile   s    i   i@   c         C   sŰ  t  |  |  r d SyG | rE t j | t j  rE t d |   n  t j |  |  d SWn t k
 rm n Xt |  d  ł } t j | t j t j	 Bt
 t d d  B| sľ t j n d B } zO t j | t j  d } x/ | d k r| j |  } t j | |  qŢ WWd t j |  t j |  XWd QXy t |  |  Wn4 t k
 ry} t
 | d d  t j k rz  qzn Xy t j |   WnI t k
 rÖ} t
 | d d  d	 k r×t
 | d d  d
 k r×  q×n Xd S(   sg  
    Moves a file from one location to another in the safest way possible.

    First, tries ``os.rename``, which is simple but will break across filesystems.
    If that fails, streams manually from one file to another in pure Python.

    If the destination file exists and ``allow_overwrite`` is ``False``, this
    function will throw an ``IOError``.
    Ns7   Destination file %s exists and allow_overwrite is Falset   rbt   O_BINARYi    t    t   errnot   winerrori    i   (   R   R   t   accesst   F_OKt   IOErrort   renameR   t   opent   O_WRONLYt   O_CREATt   getattrt   O_EXCLR   t   lockt   LOCK_EXt   Nonet   readt   writet   unlockt   closeR    R   t   EPERMt   remove(   t   old_file_namet   new_file_namet
   chunk_sizet   allow_overwritet   old_filet   fdt   current_chunkt   e(    (    s8   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/move.pyR      s<    &
0i   (   t   __doc__R   R   t   shutilR    t   django.core.filesR   t   __all__R   R   R   (    (    (    s8   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/move.pyt   <module>   s   		