o
    e                     @  s   d Z ddlmZ ddlZddlZddl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
lmZ G dd dZG dd dZdddZdS )zCDefines context objects that are passed to child processes/threads.    )annotationsN)	Namespace)copy)Path)Iterator)PluginManager)PdfInfo)PageInfoc                   @  sP   e Zd ZU dZded< ded< ded< ded	< dddZdddZdddZdS )
PdfContextz7Holds the context for a particular run of the pipeline.r   optionsr   originr   pdfinfor   plugin_managerwork_folderc                 C  s"   || _ || _|| _|| _|| _d S N)r   r   r   r   r   )selfr   r   r   r   r    r   DD:\Projects\ConvertPro\env\Lib\site-packages\ocrmypdf/_jobcontext.py__init__   s
   
zPdfContext.__init__namestrreturnc                 C  s
   | j | S )zGenerate a ``Path`` for an intermediate file involved in processing.

        The path will be in a temporary folder that is common for all processing
        of this particular PDF.
        )r   r   r   r   r   r   get_path,   s   
zPdfContext.get_pathIterator[PageContext]c                 c  s*    t | j}t|D ]}t| |V  q
dS )z%Get all ``PageContext`` for this PDF.N)lenr   rangePageContext)r   Znpagesnr   r   r   get_page_contexts4   s
   
zPdfContext.get_page_contextsN)r   r   r   r   r   r   r   r   r   r   r   r   )r   r   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   r   r   r
      s   
 

r
   c                   @  sV   e Zd ZU dZded< ded< ded< ded	< d
ed< dddZdddZdd ZdS )r   zHolds our context for a page.

    Must be pickable, so stores only intrinsic/simple data elements or those
    capable of their serializing themselves via ``__getstate__``.
    r   r   r   r   intpagenor	   pageinfor   r   pdf_contextr
   c                 C  s6   |j | _ |j| _|j| _|| _|j| | _|j| _d S r   )r   r   r   r'   r   r(   r   )r   r)   r'   r   r   r   r   H   s   zPageContext.__init__r   r   r   c                 C  s   | j | jd dd|  S )zGenerate a ``Path`` for a file that is part of processing this page.

        The path will be based in a common temporary folder and have a prefix based
        on the page number.
           Z06d_)r   r'   r   r   r   r   r   P   s   zPageContext.get_pathc                 C  s`   | j  }t| j|d< t|d jtttjfsd|d _t|d j	tttjfs.d|d _	|S )Nr   stream)
__dict__r   r   
isinstanceZ
input_filer   bytesosPathLikeZoutput_file)r   stater   r   r   __getstate__X   s   


zPageContext.__getstate__N)r)   r
   r    )r!   r"   r#   r$   r%   r   r   r3   r   r   r   r   r   ;   s   
 

r   r   r   r   r   c                 C  s0   |j rtd|  tjd d S tj| dd d S )Nz%Temporary working files retained at:
)fileT)ignore_errors)Zkeep_temporary_filesprintsysstderrshutilrmtree)r   r   r   r   r   cleanup_working_filesc   s   r;   )r   r   r   r   )r$   
__future__r   r0   r9   r7   argparser   r   pathlibr   typingr   Zpluggyr   Zocrmypdf.pdfinfor   Zocrmypdf.pdfinfo.infor	   r
   r   r;   r   r   r   r   <module>   s   %(