a
    ˜ëj‚/  ã                   @   sT  U d 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mZmZmZ ejee dœdd	„ƒZejd
d�G dd„ dƒƒZeƒ Ze	ded�Ze	e ed< edœdd„Zee eeef edœdd„Zd,ee eedœdd„Zed-ee eee dœdd„ƒZddddddd d!d"d#d$d%d&d'd(œZeƒ Zee ed)< edœd*d+„ZdS ).zConfiguration value handling.é    N)ÚIterator)Úcontextmanager)Ú
ContextVar)ÚAnyÚLiteralÚOptionalÚUnion)Úreturnc                   C   s
   t  d¡S )z•
    Small utility function to determine the `jbig2dec` binary path only once.

    Returns:
        The corresponding binary path if available.
    Zjbig2dec)ÚshutilÚwhich© r   r   úS/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pypdf/_configuration.pyÚ_determine_jbig2dec_binary   s    r   T)Úfrozenc                   @   sŽ  e Zd ZU dZdZeed< dZeed< dZeed< dZ	eed< dZ
eed< dZeed	< dZeed
< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed < dZeed!< dZeed"< dZeed#< d$Zeed%< e j!e"d&�Z#e$e% ed'< d(Z&e'd) ed*< d+Z(e)ed,< e*d d-œd.d/„Z+d0S )1ÚConfigurationaÂ  
    Configuration used while processing PDF files.

    These limits mostly protect against excessive resource consumption caused by malformed or malicious PDF files.

    .. note::

        Avoid relying on specific implementation details of this class. The main public API consists of the values
        being considered read-only for each instance with the overwrite method to create a new instance with the
        specified values changed.
    iÀhxÚmaximum_declared_stream_lengthÚ(array_based_stream_maximum_output_lengthi † Úarray_maximum_element_countÚ dictionary_maximum_element_countÚjbig2_maximum_output_lengthÚlzw_maximum_output_lengthÚ run_length_maximum_output_lengthÚzlib_maximum_output_lengthi@KL Ú"zlib_maximum_recovery_input_lengthÚbrotli_maximum_output_lengthi�Ð Úflate_maximum_columnsi 	= Úflate_maximum_row_lengthÚimage_maximum_buffer_sizeé   Ústream_filters_maximum_lengthi £áÚ#stream_decoding_work_maximum_lengthi€„ Ú!stream_parsing_work_maximum_countÚxmp_maximum_input_lengthÚxmp_maximum_element_countÚoutline_maximum_entrieséd   Úoutline_maximum_depthÚpage_tree_maximum_entriesÚpage_tree_maximum_depthÚpage_tree_maximum_page_entriesÚform_fields_maximum_entriesÚform_fields_maximum_depthiˆ  Ú(xform_maximum_invocations_per_extraction)Údefault_factoryÚjbig2dec_binaryÚcropbox)r/   ZtrimboxÚpage_merge_boxFÚdisable_legacy_handling)Úkwargsr	   c                 K   s   t j| fi |¤ŽS )a  
        Creates a new configuration with the specified values overwritten.

        Args:
            **kwargs: Configuration field names and their new values.

        Returns:
            A new configuration with the specified values overwritten.
        )ÚdataclassesÚreplace)Úselfr2   r   r   r   Úwith_overwrites“   s    
zConfiguration.with_overwritesN),Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚintÚ__annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r&   r'   r(   r)   r*   r+   r,   r3   Úfieldr   r.   r   Ústrr0   r   r1   Úboolr   r6   r   r   r   r   r      s>   
r   Zpypdf_configuration)ÚdefaultÚCURRENT_CONFIGURATIONc                   C   s   t  ¡ S )zY
    Get the current configuration.

    Returns:
        The current configuration.
    )rA   Úgetr   r   r   r   Úget_configurationª   s    rC   )ÚconfigurationÚ
overwritesr	   c                 C   s"   | dur| nt ƒ }|jf i |¤ŽS )a  
    Utility function to build a new configuration from the given values.

    Args:
        configuration: A possible explicit configuration to use instead of the current configuration.
        overwrites: Entries to overwrite.

    Returns:
        The generated configuration.
    N)rC   r6   )rD   rE   Úbaser   r   r   Ú_build_configuration´   s    rG   c                 K   s   t | |ƒ}t |¡ |S )a"  
    Overwrite the configuration for the current execution context.

    Args:
        configuration: A direct configuration instance to use.
        **overwrites: Configuration parameters to overwrite in the current or given configuration.

    Returns:
        The new configuration.
    )rG   rA   Úset)rD   rE   Únew_configurationr   r   r   Úoverwrite_configurationÆ   s    

rJ   c              	   k   s:   t | |ƒ}t |¡}z|V  W t |¡ nt |¡ 0 dS )a  
    Temporarily overwrite the configuration.

    Args:
        configuration: A direct configuration instance to use.
        **overwrites: Configuration parameters to overwrite in the current or given configuration.

    Returns:
        The new configuration.
    N)rG   rA   rH   Úreset)rD   rE   rI   Útokenr   r   r   Úapply_configurationÙ   s
    

rM   ÚMAX_DECLARED_STREAM_LENGTHÚ$MAX_ARRAY_BASED_STREAM_OUTPUT_LENGTHÚJBIG2_MAX_OUTPUT_LENGTHÚLZW_MAX_OUTPUT_LENGTHÚRUN_LENGTH_MAX_OUTPUT_LENGTHÚZLIB_MAX_OUTPUT_LENGTHÚZLIB_MAX_RECOVERY_INPUT_LENGTHÚFLATE_MAX_COLUMNSÚFLATE_MAX_ROW_LENGTHÚFLATE_MAX_BUFFER_SIZEÚXMP_MAX_INPUT_LENGTHÚXMP_MAX_ELEMENT_COUNTÚJBIG2DEC_BINARYÚMERGE_CROP_BOX)r   r   r   r   r   r   r   r   r   r   r"   r#   r.   r0   ÚWARNED_LEGACY_OVERWRITESc                  C   sþ   t ƒ } | jr| S ddlm} ddlm}m}m}m}m	}m
}m}m}	m}
m}m} ddlm}m} |	||||
|||||||||dœ}i }t ¡ D ]X\}}|| }|tt|ƒkrŽ|tvrÞddlm} ||d|› �dd	� t |¡ |||< qŽ|sð| S tf i |¤ŽS )
z§
    Overwrite the current configuration with the legacy configuration if it has been changed.

    Returns:
        The new configuration which has been applied.
    r   )r[   )rW   rU   rV   rP   rZ   rQ   rO   rN   rR   rS   rT   )rY   rX   )rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   )Údeprecate_with_replacementzConfiguration.z7.0.0)Zold_nameÚnew_nameZ
removed_in)rC   r1   Zpypdf._pager[   Zpypdf.filtersrW   rU   rV   rP   rZ   rQ   rO   rN   rR   rS   rT   Z	pypdf.xmprY   rX   ÚLEGACY_NAME_MAPPINGÚitemsÚgetattrÚDEFAULT_CONFIGURATIONr\   Zpypdf._utilsr]   ÚaddrJ   )rD   r[   rW   rU   rV   rP   rZ   rQ   rO   rN   rR   rS   rT   rY   rX   Zlegacy_valuesrE   Ú
field_nameZlegacy_nameZlegacy_valuer]   r   r   r   Úapply_legacy_configuration  sJ    4òý

re   )N)N) r:   r3   Ú	functoolsr
   Úcollections.abcr   Ú
contextlibr   Zcontextvarsr   Útypingr   r   r   r   Úcacher>   r   Z	dataclassr   rb   rA   r<   rC   ÚdictrG   rJ   rM   r_   rH   r\   re   r   r   r   r   Ú<module>   sh   

 þ
ý ÿý ÿýò