o
    h ,                  	   @   s  U d Z dZdZddlZddlZddlmZ ddlmZm	Z	m
Z
mZmZ ddlmZ ddlmZmZmZmZmZmZ zdd	lmZ W n eyP   dd	lmZ Y nw d
dl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ee	e
ef Z ee!e f Z"dZ#dZ$de%de%de%fddZ&dXde dee' de%fddZ(de de%fddZ)de de*fddZ+de ddfddZ,	dYde d ed!e*de%fd"d#Z-de d$e'de%fd%d&Z.de de%fd'd(Z/d)ed*edefd+d,Z0de ddfd-d.Z1i Z2eee!e%f e%f ed/< d0ee!e%f de%fd1d2Z3ed*e!de!fd3d4Z4ed*e%de!fd5d4Z4d*ee!e%f de!fd6d4Z4ed*e!de'fd7d8Z5ed*e%de%fd9d8Z5ed*e'de'fd:d8Z5d*ee'e!e%f dee'e%f fd;d8Z5d*e%de%fd<d=Z6d>e'de!fd?d@Z7dAZ8dBe'dCe'dDe'de'fdEdFZ9dZdHe!dIe'ddfdJdKZ:	Ld[dMe!dNe!dOe!ddfdPdQZ;d[dRe!dOe!ddfdSdTZ<dHe!dUe!ddfdVdWZ=dS )\z"Utility functions for PDF library.zMathieu Fenniakzbiziqe@mathieu.fenniak.net    N
getencoder)DEFAULT_BUFFER_SIZEBufferedReaderBufferedWriterBytesIOFileIO)SEEK_CUR)DictOptionalPatternTupleUnionoverload)	TypeAlias   )STREAM_TRUNCATED_PREMATURELYPdfStreamErrorTransformationMatrixTypeCompressedTransformationMatrixz2{} is deprecated and will be removed in PyPDF2 {}.zE{} is deprecated and will be removed in PyPDF2 3.0.0. Use {} instead.header1header2returnc                 C   sf   d}g }| |v r| ||  ||v r| || t|dkr-t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   U/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/PyPDF2/_utils.py_get_max_pdf_version_headerC   s   r!   streammaxcharsc                 C   s>   d}	 |  d}| s|s	 |S ||7 }t||kr	 |S q)z~
    Read non-whitespace characters and return them.

    Stops upon encountering whitespace or when maxchars is reached.
        Tr   )readisspacer   )r"   r#   txttokr   r   r    read_until_whitespaceV   s   
r)   c                 C   s(   |  d}|tv r|  d}|tv s	|S )zEFind and read the next non-whitespace character (ignores whitespace).r   )r%   WHITESPACESr"   r(   r   r   r    read_non_whitespaceg   s
   

r,   c                 C   s6   t d }d}|t v r| d}|d7 }|t v s
|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_whitespaceo   s   
r-   c                 C   sD   |  d}| dd |dkr|dvr |  d}|dvsd S d S d S )Nr      %)   
   )r%   seekr+   r   r   r    skip_over_comment|   s   

r3   Fregex
ignore_eofc                 C   sr   d}	 |  d}|s|r|S tt||}|dur4||d|  7 }| | t| d 	 |S ||7 }q)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$   T   Nr   )r%   r   r   searchstartr2   r   )r"   r4   r5   namer(   mr   r   r    read_until_regex   s   


r;   to_readc                 C   sd   |   |k r
td| | t | |}| | t t||kr0tdt| d| d|S )zGiven a stream at position X, read a block of size
    to_read ending at position X.
    The stream's position should be unchanged.
    z!Could not read malformed PDF filez
EOF: read z, expected ?)tellr   r2   r	   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rndt| |}t|d }|sF|dkr@|| dvr@|d8 }|dkr@|| dvs2|dkrFd}|rl|||d d  |dkrk|| dv rk|d8 }|dkrk|| dv s]n|| |dkr~| |d t	 n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   Tr   s   
Nr$   r.   )r>   r   r   minr   r?   r   r   r2   r	   join)r"   Zline_contentZ
found_crlfr<   blockidxr   r   r    read_previous_line   s8   


"rD   abc                    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   sx   d}|  | d tdd}|| | |d || | W d   n1 s.w   Y  |  | d dS )z5Create text file showing current location in context.i  r   zPyPDF2_pdfLocation.txtwbs   HEREN)r2   openwriter%   )r"   ZradiusZ	output_fhr   r   r    mark_location   s   
rX   B_CACHEsc                 C   s|   t }| |v r
||  S t| tr| S z| d}t| dk r!||| < |W S  ty=   | d}t| dk r9||| < | Y S w )Nlatin-1   zutf-8)rY   
isinstancebytesencoder   	Exception)rZ   bcrr   r   r    b_   s    


rc   c                 C      d S rG   r   rS   r   r   r    str_     re   c                 C   rd   rG   r   rS   r   r   r    re     rf   c                 C   s   t | tr
| dS | S )Nr[   )r]   r^   decoderS   r   r   r    re     s   

c                 C   rd   rG   r   rS   r   r   r    ord_  rf   rh   c                 C   rd   rG   r   rS   r   r   r    rh   "  rf   c                 C   rd   rG   r   rS   r   r   r    rh   '  rf   c                 C   s   t | tr	t| S | S rG   )r]   strordrS   r   r   r    rh   ,  s   
c                 C   s   t d}|| }|d S )N	hex_codecr   r   )rF   ZcoderZcodedr   r   r    	hexencode2  s   rl   numc                 C   s   t | ddS )NL )hexreplace)rm   r   r   r    hex_str9  s   rr   )    r0   r1      	    leftupup_leftc                 C   sT   | | | }t ||  }t || }t || }||kr"||kr"| S ||kr(|S |S rG   )abs)rv   rw   rx   pZ	dist_leftZdist_upZdist_up_leftr   r   r    paeth_predictor@  s   r{      msg
stacklevelc                 C   s   t j| t|d d S )N)r~   )warningswarnPendingDeprecationWarning)r}   r~   r   r   r    	deprecateN  s   r   3.0.0old_namenew_name
removed_inc                 C   s   t t| ||d d S N   )r   DEPR_MSGformat)r   r   r   r   r   r    deprecate_with_replacementR  s   r   r9   c                 C   s   t t| |d d S r   )r   DEPR_MSG_NO_REPLACEMENTr   )r9   r   r   r   r    deprecate_no_replacementX  s   r   srcc                 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   rG   )F)r|   )r   )>__doc__
__author____author_email__r   r   codecsr   ior   r   r   r   r   osr	   typingr
   r   r   r   r   r   r   ImportErrortyping_extensionserrorsr   r   rH   r   __annotations__r   Z
StreamTyperi   ZStrByteTyper   r   r^   r!   intr)   r,   boolr-   r3   r;   r?   rD   rT   rX   rY   rc   re   rh   rl   rr   r*   r{   r   r   r   r   r   r   r   r    <module>   s    &	
3
	$
