
    :QgY3              	           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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mZmZ 	 dd
lmZ 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Z+dKde%dee,   de*fdZ-de%de*fdZ.de%de/fdZ0de%ddfdZ1	 dLde%dee*   de/de*fdZ2de%de,de*fdZ3de%de*fd Z4d!e"d"e"de"fd#Z5de%ddfd$Z6i Z7eee&e*f   e*f   e#d%<   d&ee&e*f   de*fd'Z8ed"e&de&fd(       Z9ed"e*de&fd)       Z9d"ee&e*f   de&fd*Z9ed"e&de,fd+       Z:ed"e*de*fd,       Z:ed"e,de,fd-       Z:d"ee,e&e*f   dee,e*f   fd.Z:d"e*de*fd/Z;d0e,de&fd1Z<d2Z=d3e,d4e,d5e,de,fd6Z>dMd7e&d8e,ddfd9Z?	 dNd:e&d;e&d<e&ddfd=Z@dNd>e&d<e&ddfd?ZAd7e&d@e&ddfdAZBdBe&defdCZCdDe&dEee&ef   dBee&e&f   fdFZDdGe,de&fdHZEe	 G dI dJ             ZFy# e$ r
 dd
lmZ Y w xY w)Oz"Utility functions for PDF library.zMathieu Fenniakzbiziqe@mathieu.fenniak.net    N
getencoder)	dataclass)DEFAULT_BUFFER_SIZEBufferedReaderBufferedWriterBytesIOFileIO)SEEK_CUR)AnyCallable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                     d}g }| |v r |j                  |j                  |              ||v r |j                  |j                  |             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   versionspdf_header_indicess       J/var/www/html/answerous/venv/lib/python3.12/site-packages/PyPDF2/_utils.py_get_max_pdf_version_headerr&   N   s    H (!!(.."9:(!!(.."9:
!#8G;eG;>QRSSC*+,,    streammaxcharsc                     d}	 | j                  d      }|j                         s|s	 |S ||z  }t        |      |k(  r	 |S =)z~
    Read non-whitespace characters and return them.

    Stops upon encountering whitespace or when maxchars is reached.
    r'   r   )readisspacer    )r(   r)   txttoks       r%   read_until_whitespacer/   a   sR     C
kk!n;;= J 	s
s8xJ r'   c                 l    | j                  d      }|t        v r| j                  d      }|t        v r|S )zEFind and read the next non-whitespace character (ignores whitespace).r   )r+   WHITESPACESr(   r.   s     r%   read_non_whitespacer3   r   s3    
++a.C

kk!n 
Jr'   c                 p    t         d   }d}|t         v r| j                  d      }|dz  }|t         v r|dkD  S )zr
    Similar to read_non_whitespace, but return a Boolean if more than
    one whitespace character was read.
    r   r   )r1   r+   )r(   r.   cnts      r%   skip_over_whitespacer6   z   sE    
 a.C
C

kk!nq 
 7Nr'   c                     | j                  d      }| j                  dd       |dk(  r|dvr| j                  d      }|dvry y y )Nr      %)   
   )r+   seekr2   s     r%   skip_over_commentr=      sH    
++a.C
KKA
d{'++a.C ' r'   regex
ignore_eofc                    d}	 | j                  d      }|s|r|S t        t              |j                  |      }|E||d|j	                          z  }| j                  |j	                         t        |      z
  d       	 |S ||z  })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startr<   r    )r(   r>   r?   namer.   ms         r%   read_until_regexrF      s     D
kk"o !=>>LL=C!'')$$DKK	CH,a0K 	 r'   to_readc                     | j                         |k  rt        d      | j                  | t               | j	                  |      }| j                  | 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   r<   r   r+   )r(   rG   r+   s      r%   read_block_backwardsrJ      sQ     {{}w@AA
KK(#;;wD
KK(#Kr'   c                    g }d}| j                         dk(  rt        t              	 t        t        | j                               }|dk(  rnt        | |      }t        |      dz
  }|s%|dk\  r||   dvr|dz  }|dk\  r||   dvr|dk\  rd}|r6|j                  ||dz   d        |dk\  r+||   dv r$|dz  }|dk\  r||   dv rn|j                  |       |dk\  r| j                  |dz   t               ndj                  |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'   r8   )rI   r   r   minr   rJ   r    r   r<   r   join)r(   line_content
found_crlfrG   blockidxs         r%   read_previous_linerR      s?    LJ{{}9::
)6;;=9a< %VW5%j1n (uSz8q (uSz8ax!

 cAgi 01(uSzW4q (uSzW4
 &!8 KKa*A D 88L2&''r'   abc                 ,    t        fd| D              S )Nc              3   T   K   | ]  t        fd t         D                 yw)c              3   V   K   | ]   }t        d  t        |      D               " yw)c              3   P   K   | ]  \  }}t        |      t        |      z     y wN)float).0ijs      r%   	<genexpr>z6matrix_multiply.<locals>.<genexpr>.<genexpr>.<genexpr>   s!     @$!Q%(U1X%@s   $&N)sumzip)r[   colrows     r%   r^   z,matrix_multiply.<locals>.<genexpr>.<genexpr>   s"     TSc@#c3-@@Ts   &)N)tupler`   )r[   rb   rT   s    @r%   r^   z"matrix_multiply.<locals>.<genexpr>   s)       	TCQRGTTs   $()rc   )rS   rT   s    `r%   matrix_multiplyrd      s        r'   c                 8   d}| j                  | d       t        dd      5 }|j                  | j                  |             |j                  d       |j                  | j                  |             ddd       | j                  | d       y# 1 sw Y   xY w)z5Create text file showing current location in context.i  r   zPyPDF2_pdfLocation.txtwbs   HEREN)r<   openwriter+   )r(   radius	output_fhs      r%   mark_locationrk      s     F
KK	&	- -F+, F+,- KK	- -s   ABBB_CACHEsc                     t         }| |v r||    S t        | t              r| S 	 | j                  d      }t	        |       dk  r||| <   |S # t
        $ r) | j                  d      }t	        |       dk  r||| <   |cY S w xY w)Nlatin-1   zutf-8)rl   
isinstancebytesencoder    	Exception)rm   bcrs      r%   b_rw     s    	BBw!u!U	HHYq6A:BqE HHWq6A:BqE	s   %A	 	/A;:A;c                      y rY    rT   s    r%   str_r{         r'   c                      y rY   ry   rz   s    r%   r{   r{     r|   r'   c                 H    t        | t              r| j                  d      S | S )Nro   )rq   rr   decoderz   s    r%   r{   r{   !  s     !Uxx	""r'   c                      y rY   ry   rz   s    r%   ord_r   (  r|   r'   c                      y rY   ry   rz   s    r%   r   r   -  r|   r'   c                      y rY   ry   rz   s    r%   r   r   2  r|   r'   c                 <    t        | t              rt        |       S | S rY   )rq   strordrz   s    r%   r   r   7  s    !S1vHr'   c                 2    t        d      } ||       }|d   S )N	hex_codecr   r   )rT   codercodeds      r%   	hexencoder   =  s    {#E!HE8Or'   numc                 8    t        |       j                  dd      S )NL )hexreplace)r   s    r%   hex_strr   D  s    s8C$$r'   )    r:   r;      	    leftupup_leftc                     | |z   |z
  }t        || z
        }t        ||z
        }t        ||z
        }||k  r||k  r| S ||k  r|S |S rY   )abs)r   r   r   p	dist_leftdist_updist_up_lefts          r%   paeth_predictorr   K  s^    r	GAAHI!b&kGq7{#LG	\ 9	L	 	r'   msg
stacklevelc                 <    t        j                  | t        |       y )N)r   )warningswarnPendingDeprecationWarning)r   r   s     r%   	deprecater   Y  s    MM#0ZHr'   old_namenew_name
removed_inc                 F    t        t        j                  | ||      d       y N   )r   DEPR_MSGformat)r   r   r   s      r%   deprecate_with_replacementr   ]  s     hooh*=qAr'   rD   c                 D    t        t        j                  | |      d       y r   )r   DEPR_MSG_NO_REPLACEMENTr   )rD   r   s     r%   deprecate_no_replacementr   c  s    %,,T:>Br'   srcc                 L    t        j                  |      j                  |        y)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   s     r%   logger_warningr   g  s      c""3'r'   aliasesc                        dt         f f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                 F     t        j                          fd       }|S )Nc                  B    t        j                  |        | i |S rY   )rename_kwargs__name__)argskwargsr   r   s     r%   wrapperz7deprecate_bookmark.<locals>.decoration.<locals>.wrapper  s#    $--9(((r'   )	functoolswraps)r   r   r   s   ` r%   
decorationz&deprecate_bookmark.<locals>.decoration  s%    			) 
	) r'   )r   )r   r   s   ` r%   deprecate_bookmarkr   z  s      r'   	func_namer   c                     |j                         D ]X  \  }}||v s||v rt        |  d| d| d| d| d
      |j                  |      ||<   t        j                  | d| d       Z y	)
z1
    Helper function to deprecate arguments.
    z received both z and z as an argument. z is deprecated. Use z	 instead.z# is deprecated as an argument. Use z instead)messageN)items	TypeErrorpopr   r   )r   r   r   old_termnew_terms        r%   r   r     s     &mmo (v6! k
%zIZj 4XJiI   &zz(3F8MMj CH:XVr'   rr   c                 `    | dk  r|  dS | dk  r	| dz  ddS | dk  r	| dz  ddS | dz  ddS )	Ni  z Bytei@B z.1fz kBi ʚ;z MBz GBry   )rr   s    r%   _human_readable_bytesr     s_    u}	%-$C((	%-$C((%-$C((r'   c                   :    e Zd ZU eed<   eed<   defdZdefdZy)FilerD   datar   c                 `    d| j                    dt        t        | j                               dS )N
File(name=, data: ))rD   r   r    r   selfs    r%   __str__zFile.__str__  s+    DII;h/DS^/T.UUVWWr'   c                     d| j                    dt        t        | j                               dt	        | j                         dS )Nr   r   z, hash: r   )rD   r   r    r   hashr   s    r%   __repr__zFile.__repr__  s@    DII;h/DS^/T.UU]^bcgclcl^m]nnoppr'   N)r   
__module____qualname__r   __annotations__rr   r   r   ry   r'   r%   r   r     s(    
I
KX Xq# qr'   r   rY   )F)   )z3.0.0)G__doc__
__author____author_email__r   r   r   codecsr   dataclassesr   ior   r   r   r	   r
   osr   typingr   r   r   r   r   r   r   r   r   ImportErrortyping_extensionserrorsr   r   rZ   r   r   r   
StreamTyper   StrByteTyper   r   rr   r&   intr/   r3   boolr6   r=   rF   rJ   rR   rd   rk   rl   rw   r{   r   r   r   r1   r   r   r   r   r   r   r   r   r   ry   r'   r%   <module>r      se  8 )
/      !  	 	 	,  A&+	%
eUE&9 :E%PUBU<VV' )  -2	5%u,- 	  7NNFBC
CO$N R- - -5 -&*  QV "
 u 
 
 
!j !T ! CH&u~;?
4 c e "0(z 0(e 0(f$<	* 	 	 +-eCJ&	' ,%U

  $ 
C C  
 
E c  
E#u* #  
C C  
 
E e  
 
C C  
E#sE/" uS%Z'8  5 % % % 3# 3   I3 IC I I
 5<BB B.1B	BC3 CC Cd C( (# ($ (&# ( & cN59#s(^,) ) ) q q qi  ,++,s   	G> >HH