
    Ng$                        d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ ddZddZedd            ZdS )    )annotations)	Generator)contextmanagersuppress)
TextIOBase)PathLike)Path)copystat)NamedTemporaryFile)IOstreamr   returnNonec                N    t          | t                    rt          d          dS )z+Check that a stream is seekable and binary.z3stream must be binary (no transcoding) and seekableN)
isinstancer   	TypeError)r   s    G/var/www/html/ai-engine/env/lib/python3.11/site-packages/pikepdf/_io.pycheck_stream_is_usabler      s0    &*%% OMNNNO O    file1str | PathLikefile2c                   t          t                    5  t          |           t          |          k    s/t          |                               t          |                    rt	          d          	 ddd           dS # 1 swxY w Y   dS )z#Check that two files are different.zCannot overwrite input file. Open the file with pikepdf.open(..., allow_overwriting_input=True) to allow overwriting the input file.N)r   FileNotFoundErrorr	   samefile
ValueError)r   r   s     r   check_different_filesr      s    	#	$	$  ;;$u++%%e)=)=d5kk)J)J%4   &                 s   ABB	Bfilenamer	    Generator[IO[bytes], None, None]c              #    K   	 |                      d          }	 |5  |V  ddd           n# 1 swxY w Y   nV# t          t          f$ rB t          t                    5  |                                  ddd           n# 1 swxY w Y    w xY wdS # t          $ r Y nw xY w|                      d          5 }	 ddd           n# 1 swxY w Y   t          | j        d| j	         d          5 }	 |V  n|# t          t          f$ rh t          t                    5  |
                                 t          |j	                                                   ddd           n# 1 swxY w Y    w xY w|                                 |
                                 t          t                    5  t          | t          |j	                             ddd           n# 1 swxY w Y   t          |j	                                      |            t          t                    5  |                                  ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )a  Atomically ovewrite a file.

    If the destination file does not exist, it is created. If writing fails,
    the destination file is deleted.

    If the destination file does exist, a temporaryfile is created in the same
    directory, and data is written to that file. If writing succeeds, the temporary
    file is renamed to the destination file. If writing fails, the temporary file
    is deleted and the original destination file is left untouched.
    xbNabz	.pikepdf.F)dirprefixdelete)open	ExceptionKeyboardInterruptr   OSErrorunlinkFileExistsErrorr   parentnamecloser	   flushr
   replacetouch)r   r   tfs      r   atomic_overwriter3   !   s$     t$$
	                ,- 	 	 	'"" " "!!!" " " " " " " " " " " " " " "		
 	    $ 
t		                
O$?$?$?
 
 
 		HHHH,- 	 	 	'"" ' '


RW$$&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 		
 	






g 	. 	.XtBG}}---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	RWh'''g 	 	NN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	!                 s   B 9 -9 19 19 %BA?3B?B	BB	B
BB6CCC.I0C54I5%E.;E!E.!E%%E.(E%)E..?I-#GIG 	 I#G 	$>I"I7II	I
I	II"IN)r   r   r   r   )r   r   r   r   r   r   )r   r	   r   r   )
__future__r   collections.abcr   
contextlibr   r   ior   osr   pathlibr	   shutilr
   tempfiler   typingr   r   r   r3    r   r   <module>r>      s   # " " " " " % % % % % % / / / / / / / /                         ' ' ' ' ' '      O O O O    5 5 5 5 5 5r   