o
     e                     @   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}|d u rtd|ddddg}|r%|d| g7 }t| ttjfr<d }|tt|  g7 }n| }|dg7 }tj	||rKtj
nd tj
tj
d	|rY| nd \}}t|rjt|d
 t|S )Ngsgswin32czyCannot find Ghostscript, which is required for repairs.
Visit https://www.ghostscript.com/ for installation instructions.z-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lendecoder   )r   r   r   
executablerepair_argsr   r   r    r!   D/var/www/html/venv/lib/python3.10/site-packages/pdfplumber/repair.py_repair   s:   
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   repairedfr!   r!   r"   repair4   s   
r*   )NN)NNN)r   r   r   ior   r   typingr   r   r   r   r#   r*   r!   r!   r!   r"   <module>   s<    
.