U
    Y»{j¬7  ã                   @   sà  U d Z dZ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 dd	lmZmZmZmZmZmZmZmZmZ zdd
lmZ W n  ek
r²   dd
lmZ Y nX ddlmZmZmZ eeeeef eeeef eeeef f Z ee!d< eeeeeeef Z"ee!d< eZ#ee$e#f Z%dZ&dZ'dZ(dZ)e*e*e*dœdd„Z+dee#ee, e*dœdd„Z-e#e*dœdd„Z.e#e/dœdd„Z0e#ddœdd„Z1dfe#ee* e/e*d!œd"d#„Z2e#e,e*d$œd%d&„Z3e#e*dœd'd(„Z4e e e d)œd*d+„Z5e#ddœd,d-„Z6i Z7eee$e*f e*f e!d.< ee$e*f e*d/œd0d1„Z8ee$e$d2œd3d4„ƒZ9ee*e$d2œd5d4„ƒZ9ee$e*f e$d2œd6d4„Z9ee$e,d2œd7d8„ƒZ:ee*e*d2œd9d8„ƒZ:ee,e,d2œd:d8„ƒZ:ee,e$e*f ee,e*f d2œd;d8„Z:e*e*d2œd<d=„Z;e,e$d>œd?d@„Z<dAZ=e,e,e,e,dBœdCdD„Z>dge$e,ddFœdGdH„Z?e$ddIœdJdK„Z@dhe$e$e$ddMœdNdO„ZAdie$e$e$ddMœdPdQ„ZBdje$e$ddRœdSdT„ZCdke$e$ddRœdUdV„ZDe$e$ddWœdXdY„ZEe$edZœd[d\„ZFdle$ee$ef ee$e$f e/d]œd^d_„ZGe,e$d`œdadb„ZHe	G dcdd„ ddƒƒZIdS )mz"Utility functions for PDF library.zMathieu Fenniakzbiziqe@mathieu.fenniak.neté    N©Ú
getencoder)Ú	dataclass)ÚDEFAULT_BUFFER_SIZE)ÚSEEK_CUR)	ÚIOÚAnyÚCallableÚDictÚOptionalÚPatternÚTupleÚUnionÚoverload)Ú	TypeAliasé   )ÚSTREAM_TRUNCATED_PREMATURELYÚDeprecationErrorÚPdfStreamErrorÚTransformationMatrixTypeÚCompressedTransformationMatrixz2{} is deprecated and will be removed in PyPDF2 {}.z.{} is deprecated and was removed in PyPDF2 {}.zE{} is deprecated and will be removed in PyPDF2 3.0.0. Use {} instead.z>{} is deprecated and was removed in PyPDF2 {}. Use {} instead.)Úheader1Úheader2Úreturnc                 C   sf   d}g }| |kr |  | | ¡¡ ||kr8|  | |¡¡ t|ƒdkrZtd| ›d|›d�ƒ‚|t|ƒ S )N)s   %PDF-1.3s   %PDF-1.4s   %PDF-1.5s   %PDF-1.6s   %PDF-1.7s   %PDF-2.0r   zneither z nor z are proper headers)ÚappendÚindexÚlenÚ
ValueErrorÚmax)r   r   ÚversionsZpdf_header_indices© r    úL/var/www/html/bwave/python/venv/lib/python3.8/site-packages/PyPDF2/_utils.pyÚ_get_max_pdf_version_headerO   s    r"   )ÚstreamÚmaxcharsr   c                 C   s8   d}|   d¡}| ¡ s4|sq4||7 }t|ƒ|krq4q|S )z~
    Read non-whitespace characters and return them.

    Stops upon encountering whitespace or when maxchars is reached.
    ó    r   )ÚreadÚisspacer   )r#   r$   ÚtxtÚtokr    r    r!   Úread_until_whitespaceb   s    
r*   )r#   r   c                 C   s"   |   d¡}|tkr|   d¡}q
|S )zEFind and read the next non-whitespace character (ignores whitespace).r   )r&   ÚWHITESPACES©r#   r)   r    r    r!   Úread_non_whitespaces   s    
r-   c                 C   s0   t d }d}|t kr(|  d¡}|d7 }q|dkS )zr
    Similar to read_non_whitespace, but return a Boolean if more than
    one whitespace character was read.
    r   r   )r+   r&   )r#   r)   Zcntr    r    r!   Úskip_over_whitespace{   s    

r.   c                 C   s6   |   d¡}|  dd¡ |dkr2|dkr2|   d¡}qd S )Nr   éÿÿÿÿó   %)ó   
ó   )r&   Úseekr,   r    r    r!   Úskip_over_commentˆ   s
    
r4   F)r#   ÚregexÚ
ignore_eofr   c                 C   sp   d}|   d¡}|s"|r|S ttƒ‚| |¡}|dk	rb||d| ¡ … 7 }|  | ¡ t|ƒ d¡ ql||7 }q|S )zñ
    Read until the regular expression pattern matched (ignore the match).

    :raises PdfStreamError: on premature end-of-file
    :param bool ignore_eof: If true, ignore end-of-line and return immediately
    :param regex: re.Pattern
    r%   é   Nr   )r&   r   r   ÚsearchÚstartr3   r   )r#   r5   r6   Únamer)   Úmr    r    r!   Úread_until_regex�   s    



r<   )r#   Úto_readr   c                 C   s>   |   ¡ |k rtdƒ‚|  | t¡ |  |¡}|  | t¡ |S )z´
    Given a stream at position X, read a block of size to_read ending at position X.

    This changes the stream's position to the beginning of where the block was
    read.
    z!Could not read malformed PDF file)Útellr   r3   r   r&   )r#   r=   r&   r    r    r!   Úread_block_backwardsª   s    
r?   c                 C   sì   g }d}|   ¡ dkrttƒ‚tt|   ¡ ƒ}|dkr4qØt| |ƒ}t|ƒd }|sx|dkrl|| dkrl|d8 }qN|dkrxd}|r²| ||d d… ¡ |dkr¼|| dkr¼|d8 }q’n
| |¡ |dkr|  |d t	¡ qØqd 
|ddd… ¡S )	aª  
    Given a byte stream with current position X, return the previous line.

    All characters between the first CR/LF byte found before X
    (or, the start of the file, if no such byte is found) and position X
    After this call, the stream will be positioned one byte after the
    first non-CRLF character found beyond the first CR/LF byte before X,
    or, if no such byte is found, at the beginning of the stream.
    Fr   r   s   
TNr%   r/   )r>   r   r   Úminr   r?   r   r   r3   r   Újoin)r#   Zline_contentZ
found_crlfr=   ÚblockÚidxr    r    r!   Úread_previous_line»   s.    



rD   )ÚaÚbr   c                    s   t ‡ fdd„| D ƒƒS )Nc                 3   s(   | ] ‰ t ‡ fd d„tˆŽ D ƒƒV  qdS )c                 3   s&   | ]}t d d„ tˆ |ƒD ƒƒV  qdS )c                 s   s"   | ]\}}t |ƒt |ƒ V  qd S ©N)Úfloat)Ú.0ÚiÚjr    r    r!   Ú	<genexpr>ò   s     z6matrix_multiply.<locals>.<genexpr>.<genexpr>.<genexpr>N)ÚsumÚzip)rI   Úcol©Úrowr    r!   rL   ò   s     z,matrix_multiply.<locals>.<genexpr>.<genexpr>N)ÚtuplerN   )rI   ©rF   rP   r!   rL   ñ   s   ÿz"matrix_multiply.<locals>.<genexpr>)rR   )rE   rF   r    rS   r!   Úmatrix_multiplyî   s    þrT   c              	   C   sd   d}|   | d¡ tddƒ�0}| |  |¡¡ | d¡ | |  |¡¡ W 5 Q R X |   | d¡ dS )z5Create text file showing current location in context.iˆ  r   zPyPDF2_pdfLocation.txtÚwbs   HEREN)r3   ÚopenÚwriter&   )r#   ZradiusZ	output_fhr    r    r!   Úmark_location÷   s    
rX   ÚB_CACHE)Úsr   c                 C   s‚   t }| |kr||  S t| tƒr"| S z$|  d¡}t| ƒdk rB||| < |W S  tk
r|   |  d¡}t| ƒdk rt||| < | Y S X d S )Núlatin-1é   zutf-8)rY   Ú
isinstanceÚbytesÚencoder   Ú	Exception)rZ   ÚbcÚrr    r    r!   Úb_  s    


rc   )rF   r   c                 C   s   d S rG   r    rS   r    r    r!   Ústr_  s    rd   c                 C   s   d S rG   r    rS   r    r    r!   rd     s    c                 C   s   t | tƒr|  d¡S | S d S )Nr[   )r]   r^   ÚdecoderS   r    r    r!   rd   "  s    

c                 C   s   d S rG   r    rS   r    r    r!   Úord_)  s    rf   c                 C   s   d S rG   r    rS   r    r    r!   rf   .  s    c                 C   s   d S rG   r    rS   r    r    r!   rf   3  s    c                 C   s   t | tƒrt| ƒS | S rG   )r]   ÚstrÚordrS   r    r    r!   rf   8  s    
c                 C   s   t dƒ}|| ƒ}|d S )NÚ	hex_codecr   r   )rF   ZcoderZcodedr    r    r!   Ú	hexencode>  s    rj   )Únumr   c                 C   s   t | ƒ dd¡S )NÚLÚ )ÚhexÚreplace)rk   r    r    r!   Úhex_strE  s    rp   )ó    r1   r2   ó   	ó    )ÚleftÚupÚup_leftr   c                 C   sX   | | | }t ||  ƒ}t || ƒ}t || ƒ}||krD||krD| S ||krP|S |S d S rG   )Úabs)rt   ru   rv   ÚpZ	dist_leftZdist_upZdist_up_leftr    r    r!   Úpaeth_predictorL  s    ry   é   )ÚmsgÚ
stacklevelr   c                 C   s   t j| t|d� d S )N)r|   )ÚwarningsÚwarnÚDeprecationWarning)r{   r|   r    r    r!   Ú	deprecateZ  s    r€   )r{   r   c                 C   s   t | ƒ‚d S rG   )r   )r{   r    r    r!   Údeprecation^  s    r�   ú3.0.0)Úold_nameÚnew_nameÚ
removed_inr   c                 C   s   t t | ||¡dƒ dS )zS
    Raise an exception that a feature will be removed, but has a replacement.
    é   N)r€   ÚDEPR_MSGÚformat©rƒ   r„   r…   r    r    r!   Údeprecate_with_replacementb  s    rŠ   c                 C   s   t t | ||¡ƒ dS )zW
    Raise an exception that a feature was already removed, but has a replacement.
    N)r�   ÚDEPR_MSG_HAPPENEDrˆ   r‰   r    r    r!   Údeprecation_with_replacementk  s    rŒ   )r:   r…   r   c                 C   s   t t | |¡dƒ dS )zP
    Raise an exception that a feature will be removed without replacement.
    r†   N)r€   ÚDEPR_MSG_NO_REPLACEMENTrˆ   ©r:   r…   r    r    r!   Údeprecate_no_replacementt  s    r�   c                 C   s   t t | |¡ƒ dS )zT
    Raise an exception that a feature was already removed without replacement.
    N)r�   Ú DEPR_MSG_NO_REPLACEMENT_HAPPENEDrˆ   rŽ   r    r    r!   Údeprecation_no_replacement{  s    r‘   )r{   Úsrcr   c                 C   s   t  |¡ | ¡ dS )a“  
    Use this instead of logger.warning directly.

    That allows people to overwrite it more easily.

    ## Exception, warnings.warn, logger_warning
    - Exceptions should be used if the user should write code that deals with
      an error case, e.g. the PDF being completely broken.
    - warnings.warn should be used if the user needs to fix their code, e.g.
      DeprecationWarnings
    - logger_warning should be used if the user needs to know that an issue was
      handled by PyPDF2, e.g. a non-compliant PDF being read in a way that
      PyPDF2 could apply a robustness fix to still read it. This applies mainly
      to strict=False mode.
    N)ÚloggingÚ	getLoggerÚwarning)r{   r’   r    r    r!   Úlogger_warning‚  s    r–   )Úaliasesr   c                     s   t dœ‡ fdd„}|S )z¶
    Decorator for deprecated term "bookmark"
    To be used for methods and function arguments
        outline_item = a bookmark
        outline = a collection of outline items
    ©Úfuncc                    s   t  ˆ ¡‡‡ fdd„ƒ}|S )Nc                     s   t ˆj|ˆ dd� ˆ| |ŽS )NT)Úfail)Úrename_kwargsÚ__name__)ÚargsÚkwargs)r—   r™   r    r!   Úwrapperž  s    z9deprecation_bookmark.<locals>.decoration.<locals>.wrapper)Ú	functoolsÚwraps)r™   rŸ   ©r—   r˜   r!   Ú
decoration�  s    z(deprecation_bookmark.<locals>.decoration)r	   )r—   r£   r    r¢   r!   Údeprecation_bookmark•  s    r¤   )Ú	func_namerž   r—   rš   c                 C   sŒ   |  ¡ D ]~\}}||kr|r0t|› d|› d�ƒ‚||kr^t| › d|› d|› d|› d|› d�
ƒ‚| |¡||< tj|› d|› d�td� qd	S )
z1
    Helper function to deprecate arguments.
    z# is deprecated as an argument. Use z insteadz received both z and z as an argument. z is deprecated. Use z	 instead.)ÚmessageÚcategoryN)Úitemsr   Ú	TypeErrorÚpopr}   r~   r   )r¥   rž   r—   rš   Zold_termZnew_termr    r    r!   r›   ¨  s    ÿ ÿür›   )r^   r   c                 C   sV   | dk r| › d�S | dk r*| d d›d�S | dk rB| d d›d�S | d d›d�S d S )	Niè  z Bytei@B z.1fz kBi Êš;z MBz GBr    )r^   r    r    r!   Ú_human_readable_bytesÃ  s    
r«   c                   @   s:   e Zd ZU eed< eed< edœdd„Zedœdd„ZdS )	ÚFiler:   Údata)r   c                 C   s   d| j › dtt| jƒƒ› d�S )Nú
File(name=ú, data: ú))r:   r«   r   r­   ©Úselfr    r    r!   Ú__str__Ó  s    zFile.__str__c                 C   s*   d| j › dtt| jƒƒ› dt| jƒ› d�S )Nr®   r¯   z, hash: r°   )r:   r«   r   r­   Úhashr±   r    r    r!   Ú__repr__Ö  s    zFile.__repr__N)rœ   Ú
__module__Ú__qualname__rg   Ú__annotations__r^   r³   rµ   r    r    r    r!   r¬   Î  s   
r¬   )N)F)rz   )r‚   )r‚   )r‚   )r‚   )F)JÚ__doc__Ú
__author__Ú__author_email__r    r“   r}   Úcodecsr   Údataclassesr   Úior   Úosr   Útypingr   r   r	   r
   r   r   r   r   r   r   ÚImportErrorÚtyping_extensionsÚerrorsr   r   r   rH   r   r¸   r   Z
StreamTyperg   ZStrByteTyper�   r�   r‡   r‹   r^   r"   Úintr*   r-   Úboolr.   r4   r<   r?   rD   rT   rX   rY   rc   rd   rf   rj   rp   r+   ry   r€   r�   rŠ   rŒ   r�   r‘   r–   r¤   r›   r«   r¬   r    r    r    r!   Ú<module>   s¼   ,&ÿÿ	 ÿ  þ4 þ	" ÿ  þ
 ÿ  þ	 ÿ 
 
 ÿ