
    af                     D    d Z ddlZddlmZmZ ddlmZ dgZd Z	 d
d	Z	dS )z
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")
    N)copymodecopystat)locksfile_move_safec                    t          t          j        d          r2	 t          j                            | |          S # t          $ r Y dS w xY wt          j                            t          j                            |                     t          j                            t          j                            |                    k    S )NsamefileF)hasattrospathr   OSErrornormcaseabspath)srcdsts     H/var/www/html/env/lib/python3.11/site-packages/django/core/files/move.py	_samefiler      s    rw
## 	7##C--- 	 	 	55	 7BGOOC0011RW5E5E
6 6  s   < 
A
	A
   Fc           
      D   t          | |          rdS 	 |s1t          j        |t          j                  rt	          d|z            t          j        | |           dS # t          $ r Y nw xY wt          | d          5 }t          j        |t          j        t          j	        z  t          t          dd          z  |st          j        ndz            }	 t          j        |t          j                   d}|dk    r0|                    |          }t          j        ||           |dk    0t          j        |           t          j        |           n-# t          j        |           t          j        |           w xY w	 ddd           n# 1 swxY w Y   	 t'          | |           n2# t(          $ r% 	 t+          | |           n# t(          $ r Y nw xY wY nw xY w	 t          j        |            dS # t(          $ r!}t          |dd          dk    r Y d}~dS d}~ww xY w)	aU  
    Move a file from one location to another in the safest way possible.

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

    If the destination file exists and ``allow_overwrite`` is ``False``, raise
    ``FileExistsError``.
    Nz8Destination file %s exists and allow_overwrite is False.rbO_BINARYr       winerror    )r   r
   accessF_OKFileExistsErrorrenamer   openO_WRONLYO_CREATgetattrO_EXCLr   lockLOCK_EXreadwriteunlockcloser   PermissionErrorr   remove)old_file_namenew_file_name
chunk_sizeallow_overwriteold_filefdcurrent_chunkes           r   r   r      s    ..  	29]BG#D#D 	!J   
 		-///    	 
mT	"	" hW*"j!,,- %4:299<
 
	Jr5=))) M3&& (j 9 9]+++  3&& LHRLLLL LHRLLLLL'              *
....   
	]M2222 	 	 	D	
	-        
 1j!$$** +*****s   AA 
A+*A+>AFAE+)F*E>>FFFF+ +
G6GG
GGGGGG4 4
H>HH)r   F)
__doc__r
   shutilr   r   django.core.filesr   __all__r   r    r   r   <module>r8      s     
			 % % % % % % % % # # # # # #
   INH H H H H Hr   