HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/ocrmypdf/__pycache__/api.cpython-38.pyc
U

��Z^�#�-@s�ddlZddlZddlZddlmZddlmZddlmZddl	m
Z
mZddlmZddl
mZdd	lmZdd
lmZGdd�d�ZGd
d�de�Zddd�Zdd�Zdddddddddddddddddddddddddddddddddddddddddddd�+ejejeeeejeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeejejeeee
eefd�*dd�ZdS)�N)�suppress)�IntEnum)�Path)�Dict�List)�tqdm�)�run_pipeline)�
check_options)�parserc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�TqdmConsoleanWrapper to log messages in a way that is compatible with tqdm progress bar

    This routes log messages through tqdm so that it can print them above the
    progress bar, and then refresh the progress bar, rather than overwriting
    it which looks messy.

    For some reason Python 3.6 prints extra empty messages from time to time,
    so we suppress those.
    cCs||_tjdd�dk|_dS)Nr�)��)�file�sys�version_info�py36)�selfr�r�./usr/lib/python3/dist-packages/ocrmypdf/api.py�__init__,szTqdmConsole.__init__cCsD|jr*|��dkr@tj|��d|jd�ntj|��d|jd�dS)N��
)�endr)r�stripr�write�rstripr)r�msgrrrr0szTqdmConsole.writec	Cs"tt��|j��W5QRXdS)N)r�AttributeErrorr�flush)rrrrr 8s
zTqdmConsole.flushN)�__name__�
__module__�__qualname__�__doc__rrr rrrrr!s
rc@s eZdZdZdZdZdZdZdS)�	Verbosityz&Verbosity level for configure_logging.���rrr
N)r!r"r#r$�quiet�default�debugZ	debug_allrrrrr%=s
r%TFc	Cs�|rdnd}t�|�}|�tj�|r:tjttj�d�}ntjtjd�}|dkr^|�tj�n"|dkrt|�tj�n|�tj	�t�
d�}|dkr�t�
d�}|�|�|�|�|dkr�t�d	�}|�tj�t�d
�}|�tj	�|r�t�
d�|S)a9Set up logging.

    Library users may wish to use this function if they want their log output to be
    similar to ocrmypdf command line interface. If not used, the external application
    should configure logging on its own.

    ocrmypdf will perform all of its logging under the ``"ocrmypdf"`` logging namespace.
    In addition, ocrmypdf imports pdfminer, which logs under ``"pdfminer"``. A library
    user may wish to configure both; note that pdfminer is extremely chatty at the log
    level ``logging.INFO``.

    Library users may perform additional configuration afterwards.

    Args:
        verbosity (Verbosity): Verbosity level.
        progress_bar_friendly (bool): Install the TqdmConsole log handler, which is
            compatible with the tqdm progress bar; without this log messages will
            overwrite the progress bar
        manage_root_logger (bool): Configure the process's root logger, to ensure
            all log output is sent through

    Returns:
        The toplevel logger for ocrmypdf (or the root logger, if we are managing it).
    rZocrmypdf)�streamrrz%(levelname)7s - %(message)sr
z'%(name)s - %(levelname)7s - %(message)sZpdfminerZPILT)�loggingZ	getLoggerZsetLevel�DEBUGZ
StreamHandlerrr�stderrZERROR�INFOZ	FormatterZsetFormatterZ
addHandlerZcaptureWarnings)	�	verbosityZprogress_bar_friendlyZmanage_root_logger�prefix�logZconsoleZ	formatterZpdfminer_logZpil_logrrr�configure_loggingFs0







r2c
KsVg}g}|��D]�\}}|dkr"q|dkr:|�||f�q|�dd�}t|t�rf|r|�d|���q|�d|���t|ttf�r�|�t|��qt|t�r�|�|�qt|t�r�|�t|��qt	|�d|�dt
|��d���q|�t|��|�t|��dt_t�
|�}|D]\}	}t||	|��qtj�d	��rR|j�rRt�|�|jd
<|S)N>�progress_bar�
tesseract_env�_�-z--z: z (�)TZPYTEST_CURRENT_TESTZ_OCRMYPDF_TEST_INFILE)�items�append�replace�
isinstance�bool�int�float�strr�	TypeError�typerZapi_mode�
parse_args�setattr�os�environ�getr4�fspath)
�
input_file�output_file�kwargsZcmdlineZdeferred�arg�valZ
cmd_style_arg�options�keywordrrr�create_options�s<


 
rO)+�language�	image_dpi�output_type�sidecar�jobs�use_threads�title�author�subject�keywords�rotate_pages�remove_background�deskew�clean�clean_final�unpaper_args�
oversample�remove_vectors�	threshold�	force_ocr�	skip_text�redo_ocr�skip_big�optimize�jpg_quality�png_quality�jbig2_lossy�jbig2_page_group_size�pages�max_image_mpixels�tesseract_config�tesseract_pagesegmode�
tesseract_oem�pdf_renderer�tesseract_timeout�rotate_pages_threshold�pdfa_image_compression�
user_words�
user_patterns�
fast_web_view�keep_temporary_filesr3r4)*rHrIrPrQrSrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrdrerfrgrhrirjrkrlrmrnrorprrrsrurvrwrxr3r4c+.Cs tft��}-t|-�t|-dd�S)a�Run OCRmyPDF on one PDF or image.

    For most arguments, see documentation for the equivalent command line parameter.
    A few specific arguments are discussed here:

    Args:
        use_threads (bool): Use worker threads instead of processes. This reduces
            performance but may make debugging easier since it is easier to set
            breakpoints.
        tesseract_env (dict): Override environment variables for Tesseract
    Raises:
        ocrmypdf.PdfMergeFailedError: If the input PDF is malformed, preventing merging
            with the OCR layer.
        ocrmypdf.MissingDependencyError: If a required dependency program is missing or
            was not found on PATH.
        ocrmypdf.UnsupportedImageFormatError: If the input file type was an image that
            could not be read, or some other file type that is not a PDF.
        ocrmypdf.DpiError: If the input file is an image, but the resolution of the
            image is not credible (allowing it to proceed would cause poor OCR).
        ocrmypdf.OutputFileAccessError: If an attempt to write to the intended output
            file failed.
        ocrmypdf.PriorOcrFoundError: If the input PDF seems to have OCR or digital
            text already, and settings did not tell us to proceed.
        ocrmypdf.InputFileError: Any other problem with the input file.
        ocrmypdf.SubprocessOutputError: Any error related to executing a subprocess.
        ocrmypdf.EncryptedPdfERror: If the input PDF is encrypted (password protected).
            OCRmyPDF does not remove passwords.
        ocrmypdf.TesseractConfigError: If Tesseract reported its configuration was not
            valid.

    Returns:
        :class:`ocrmypdf.ExitCode`
    T)Zapi)rO�localsr
r	).rHrIrPrQrRrSrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrdrerfrgrhrirjrkrlrmrnrorprqrrrsrtrurvrwrxr3r4rMrrr�ocr�sRrz)TF)r+rDr�
contextlibr�enumr�pathlibr�typingrrrZ_syncr	Z_validationr
Zclirrr%r2rO�PathLiker?r=r<r>rzrrrr�<module>s�	
=4�
�