o
    ީZh                     @   s   d dl Z d dlZd dlZd dlmZmZ d dlmZmZ 		ddee	e j
eef dee	 deee	e j
f  defdd	Z			ddee	e j
eef d
eee	e j
f  dee	 deee	e j
f  dee f
ddZdS )    N)BufferedReaderBytesIO)OptionalUnion
path_or_fppasswordgs_pathreturnc           	      C   s   |pt dpt dpt d}|d u rtd|ddddd	g}|r+|d
| g7 }t| ttjfrBd }|tt|  g7 }n| }|dg7 }tj	||rQtj
nd tj
tj
d}||ra| nd \}}|jrqt|d t|S )NgsZgswin32cZgswin64czyCannot find Ghostscript, which is required for repairs.
Visit https://www.ghostscript.com/ for installation instructions.z-sstdout=%stderrz-o-z-sDEVICE=pdfwritez-dPDFSETTINGS=/prepressz-sPDFPassword=)stdinstdoutstderrzutf-8)shutilwhich	Exception
isinstancestrpathlibPathabsolute
subprocessPopenPIPEcommunicateread
returncodedecoder   )	r   r   r   
executableZrepair_argsr   procr   r    r    H/var/www/html/lang_env/lib/python3.10/site-packages/pdfplumber/repair.py_repair   sF   	
r"   outfilec                 C   sT   t | ||d}|r(t|d}||  W d    d S 1 s!w   Y  d S |S )N)r   wb)r"   openwriter   )r   r#   r   r   Zrepairedfr    r    r!   repair<   s   
r(   )NN)NNN)r   r   r   ior   r   typingr   r   r   r   r"   r(   r    r    r    r!   <module>   s<    
6