
    j5j                        d 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 erdd	lmZ  G d
 d      Z G d d      Zy)zCDefines context objects that are passed to child processes/threads.    )annotations)Iterator)Path)TYPE_CHECKING
OcrOptions)PdfInfo)PageInfo)OcrmypdfPluginManagerc                  j    e Zd ZU dZded<   ded<   ded<   ded	<   	 	 	 	 	 	 	 	 dd
ZddZddZddZy)
PdfContextz7Holds the context for a particular run of the pipeline.r   optionsr   originr	   pdfinfor   plugin_managerc                l    || _         || j                   _        || _        || _        || _        || _        y N)r   work_folderr   r   r   )selfr   r   r   r   r   s         J/var/www/html/qr/venv/lib/python3.12/site-packages/ocrmypdf/_jobcontext.py__init__zPdfContext.__init__   s5     #. &,    c                     | j                   |z  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   names     r   get_pathzPdfContext.get_path-   s     $&&r   c              #  r   K   t        | j                        }t        |      D ]  }t        | |        yw)z%Get all ``PageContext`` for this PDF.Nlenr   rangePageContextr   npagesns      r   get_page_contextszPdfContext.get_page_contexts5   s4     T\\"v 	'AdA&&	's   57c              #  t   K   t        | j                        }t        |      D ]  }t        | |      f  yw)zJGet all ``PageContext`` for this PDF packaged in tuple for args-splatting.Nr   r"   s      r   get_page_context_argsz PdfContext.get_page_context_args;   s7     T\\"v 	*AtQ'))	*s   68N)r   r   r   r   r   r   r   r	   r   strreturnr   )r*   zIterator[PageContext])r*   zIterator[tuple[PageContext]])	__name__
__module____qualname____doc____annotations__r   r   r%   r'    r   r   r   r      sX    AL-- - 	-
 -''*r   r   c                  V    e Zd ZU dZded<   ded<   ded<   ded	<   dd
ZddZd Zd Zy)r!   a  Holds our context for a page.

    Must be pickle-able, so stores only intrinsic/simple data elements or those
    capable of their serializing themselves via ``__getstate__``.

    Note: Uses OcrOptions with JSON serialization for multiprocessing compatibility.
    r   r   intpagenor
   pageinfor   r   c                    |j                   | _         |j                  | _        |j                  | _        || _        |j                  |   | _        |j                  | _        d | _        y r   )r   r   r   r3   r   r4   r   _pdf_context)r   pdf_contextr3   s      r   r   zPageContext.__init__R   sY    &22!(("**#++F3)88 r   c                F    | j                   | j                  dz   dd| z  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.
           06d_)r   r3   r   s     r   r   zPageContext.get_path]   s+     dkkAos$;1TF"CCCr   c                    | j                   j                         }| j                  j                         }||d<   |d= |j	                  dd        |S )Noptions_jsonr   r6   )__dict__copyr   model_dump_json_safepop)r   stater=   s      r   __getstate__zPageContext.__getstate__e   sM    ""$||88: ,n) 			.$'r   c                    | j                   j                  |       d|v r!ddlm}  |j                  |d         | _        y y )Nr=   r   r   )r>   updateocrmypdf._optionsr   model_validate_json_safer   )r   rB   r   s      r   __setstate__zPageContext.__setstate__q   s?    U# U"4>:>>u^?TUDL #r   N)r7   r   r(   )	r+   r,   r-   r.   r/   r   r   rC   rH   r0   r   r   r!   r!   B   s7     LK	!D
Vr   r!   N)r.   
__future__r   collections.abcr   pathlibr   typingr   rF   r   ocrmypdf.pdfinfor	   ocrmypdf.pdfinfo.infor
   ocrmypdf._plugin_managerr   r   r!   r0   r   r   <module>rP      s=    J " $    ( $ *>+* +*\6V 6Vr   