
    j:j	T                        % S r SrSrSSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
J
r
Jr  SSKJr  SSKJr  SS	KJr  SS
KJrJrJrJrJr  \R.                  SS S:  a  SSKJr  OSSKJr  \R.                  S:  a  SSKJr  OSSKJr  SSKJrJrJrJr  \ \ \!\!\!4   \ \!\!\!4   \ \!\!\!4   4   r"\\#S'   \ \!\!\!\!\!\!4   r$\\#S'   \\   r%\\&   r'\\(\%4   r)S\\(   S\\
   4S jr*S\
S\(4S jr+S\(S\(S\(4S jr,Sr-SR]                  \-5      r/S\/-   S-   r0SQS \%S!\\1   S\&4S" jjr2S \'S\&4S# jr3S \%S\44S$ jr5S%\&S\44S& jr6S \%SS4S' jr7\Rp                  S(.S \%S)\\&   S*\1S\&4S+ jjr9S \'S,\1S\&4S- jr:S \%S\&4S. jr;S/\"S0\"S\"4S1 jr<S \%SS4S2 jr=SRS3\(S4\1SS4S5 jjr>S3\(S\4S6 jr?S7\(S8\(S9\(SS4S: jr@S7\(S8\(S9\(S\4S; jrAS<\(S9\(SS4S= jrBS<\(S9\(S\4S> jrCS?\(S@\(SA\SS4SB jrDS?\(S@\(SA\SS4SC jrE SSSD\(SE\F\(\4   SF\F\(\(4   SG\4SS4
SH jjrGSI\1S\(4SJ jrH " SK SL5      rI\	 " SM SN5      5       rJ\R                   " SO SP5      5       rLg)Tz"Utility functions for PDF library.zMathieu Fenniakzbiziqe@mathieu.fenniak.net    N)	dataclass)datetimetimezone)DEFAULT_BUFFER_SIZE)SEEK_CUR)Pattern)IOAnyNoReturnOptionalUnion   )   
   )	TypeAlias)r      )Self   )STREAM_TRUNCATED_PREMATURELYDeprecationErrorLimitReachedErrorPdfStreamErrorTransformationMatrixTypeCompressedTransformationMatrixtextreturnc                 `   U nU (       d  g U S   R                  5       (       a  SU -   n U R                  S5      (       a  U S-  n U R                  SS5      R                  SS5      R                  SS	5      n [        U R	                  S5      U R	                  S
5      5      nUS:  a  U[        U 5      S-
  :w  a  U S-  n S HO  n [        R                  " X5      nU R                  S5      (       a  UR                  [        R                  S9nUs  $    [        SU 35      e! [         a     Mn  f = f)Nr   zD:)Zz0000r   +r   ' -   00)zD:%YzD:%Y%mzD:%Y%m%dz
D:%Y%m%d%HzD:%Y%m%d%H%MD:%Y%m%d%H%M%SzD:%Y%m%d%H%M%S%zz+0000)tzinfozCan not convert date: )isdigitendswithreplacemaxfindlenr   strptimer   utc
ValueError)r   orgtextifds        B/var/www/website/venv/lib/python3.13/site-packages/pypdf/_utils.pyparse_iso8824_dater7   P   s   GAwd{}}Z  <<S!))#s3;;CDDDIIcNDIIcN+A1uc$i!m#	!!$*A }}W%%IIX\\I2H!" -gY7
88  		s   D
D-,D-dtc                    U R                  S5      nU R                  bb  U R                  5       nUc   e[        UR	                  5       5      n[        [        U5      S5      u  pEUS-  nUS:  a  SOSnX US SUS S3-  nU$ )	z
Convert a datetime object to PDF date string format.

Converts datetime to the PDF date format D:YYYYMMDDHHmmSSOHH'mm
as specified in the PDF Reference.

Args:
    dt: A datetime object to convert.

Returns:
    A date string in PDF format.
r'   i  <   r   r!   r$   02dr"   )strftimer(   	utcoffsetinttotal_secondsdivmodabs)r8   date_stroffsetr?   hours	remainderminutessigns           r6   format_iso8824_daterH   p   s     {{+,H	yy!!!F0023!#m"4d;r/#q(scfU3KqQ77O    header1header2c                     Sn/ nX;   a   UR                  UR                  U 5      5        X;   a   UR                  UR                  U5      5        [        U5      S:X  a  [        SU < SU< S35      eU[	        U5         $ )N)z%PDF-1.3z%PDF-1.4z%PDF-1.5z%PDF-1.6z%PDF-1.7z%PDF-2.0r   zNeither z nor z are proper headers)appendindexr.   r1   r,   )rJ   rK   versionspdf_header_indicess       r6   _get_max_pdf_version_headerrQ      s    H !!(.."9:!!(.."9:
!#8G;eG;>QRSSC*+,,rI   )       	   
          rI      [   ]streammaxcharsc                     Sn U R                  S5      nUR                  5       (       d  U(       d   U$ X#-  n[        U5      U:X  a   U$ MH  )a  
Read non-whitespace characters and return them.

Stops upon encountering whitespace or when maxchars is reached.

Args:
    stream: The data stream from which was read.
    maxchars: The maximum number of bytes returned; by default unlimited.

Returns:
    The data which was read.

rI   r   )readisspacer.   )rZ   r[   txttoks       r6   read_until_whitespacera      sR     C
kk!n;;== J 	
s8xJ rI   c                 v    U R                  S5      nU[        ;   a  U R                  S5      nU[        ;   a  M  U$ )z
Find and read the next non-whitespace character (ignores whitespace).

Args:
    stream: The data stream from which was read.

Returns:
    The data which was read.

r   r]   WHITESPACESrZ   r`   s     r6   read_non_whitespacerf      s5     ++a.C

kk!n 
JrI   c                     U R                  S5      nSnU[        ;   a"  US-  nU R                  S5      nU[        ;   a  M"  US:  $ )z
Similar to read_non_whitespace, but return a boolean if at least one
whitespace character was read.

Args:
    stream: The data stream from which was read.

Returns:
    True if one or more whitespace was skipped, otherwise return False.

r   r   rc   )rZ   r`   cnts      r6   skip_over_whitespaceri      sI     ++a.C
C

qkk!n 
 7NrI   valuec                 &    [        S U  5       5      $ )z
Check if the given value consists of whitespace characters only.

Args:
    value: The bytes to check.

Returns:
    True if the value only has whitespace characters, otherwise return False.

c              3   2   #    U  H  o[         ;   v   M     g 7fN)WHITESPACES_AS_BYTES).0bs     r6   	<genexpr>+check_if_whitespace_only.<locals>.<genexpr>   s     8%Q((%s   )all)rj   s    r6   check_if_whitespace_onlyrt      s     8%888rI   c                     U R                  S5      nU R                  SS5        US:X  a2  US;  a+  U R                  S5      nUS:X  a  [        S5      eUS;  a  M*  g g g )Nr      %)rT   rV   rI   zFile ended unexpectedly.)r]   seekr   re   s     r6   skip_over_commentry      s[    
++a.C
KKA
d{'++a.Ccz$%?@@ ' rI   )lengthregexrz   c                    / nSnSnSn U R                  U5      nU(       d  SR                  U5      $ [        U5      nXH-   =o:  a  [        SU	 SU S35      eXW-   n
UR	                  U
5      nUR                  U5        UbK  [        U5      nXL-
  UR                  5       -   nU R                  X-
  U-
  S5        SR                  U5      SU $ XH-  nUS	S nUS
:  a  US-  nM  )a_  
Read until the regular expression pattern matched (ignore the match).
Treats EOF on the underlying stream as the end of the token to be matched.

Args:
    stream: The stream to read from.
    regex: The pattern to search for.
    length: The (approximated) maximum number of bytes to read before raising an exception.

Returns:
    The read bytes.

r   rI      zRead stream length of z# exceeds maximum allowed length of .Nr   ii    )r]   joinr.   r   searchrM   startrx   )rZ   r{   rz   partstotal_lengthtail
chunk_sizetokentoken_lengthcurrent_lengthcurrent_buffersearch_matchoverlapactual_starts                 r6   read_until_regexr      s    ELDJ
J'88E?"5z*99ND#((88[\b[ccde  ||N3U#$iG'1L4F4F4HHLKK3lBAF88E?=L11$ ST{1J5 rI   to_readc                     U R                  5       U:  a  [        S5      eU R                  U* [        5        U R	                  U5      nU R                  U* [        5        U$ )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.

Args:
    stream:
    to_read:

Returns:
    The data which was read.

z!Could not read malformed PDF file)tellr   rx   r   r]   )rZ   r   r]   s      r6   read_block_backwardsr   &  sQ     {{}w@AA
KK(#;;wD
KK(#KrI   c                 H   / nSnU R                  5       S:X  a  [        [        5      e [        [        U R                  5       5      nUS:X  a  O[        X5      n[        U5      S-
  nU(       d+  US:  a  XE   S;  a  US-  nUS:  a
  XE   S;  a  M  US:  a  SnU(       a:  UR                  XES-   S 5        US:  a  XE   S;   a  US-  nUS:  a
  XE   S;   a  M  OUR                  U5        US:  a  U R                  US-   [        5        OM  SR                  USSS2   5      $ )	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.

Args:
    stream: StreamType:

Returns:
    The data which was read.

Fr   Tr   s   
NrI   rv   )r   r   r   minr   r   r.   rM   rx   r   r   )rZ   line_content
found_crlfr   blockidxs         r6   read_previous_liner   ?  s4   " LJ{{}9::
)6;;=9a< %V5%j1n (uz8q (uz8ax!

 Agi 01(uzW4q (uzW4
 &!8 KKa*A D 88L2&''rI   arp   c                 .   ^ [        U4S jU  5       5      $ )Nc              3   \   >^#    U  H   m[        U4S  j[        T6  5       5      v   M"     g7f)c              3   \   >#    U  H!  n[        S  [        TU5       5       5      v   M#     g7f)c              3   T   #    U  H  u  p[        U5      [        U5      -  v   M      g 7frm   )float)ro   r3   js      r6   rq   6matrix_multiply.<locals>.<genexpr>.<genexpr>.<genexpr>}  s     @-$!%(U1X%-s   &(N)sumzip)ro   colrows     r6   rq   ,matrix_multiply.<locals>.<genexpr>.<genexpr>}  s%     TGSc@#c3-@@@Gs   ),N)tupler   )ro   r   rp   s    @r6   rq   "matrix_multiply.<locals>.<genexpr>|  s+      C 	TCQRGTTTs   (,)r   )r   rp   s    `r6   matrix_multiplyr   y  s        rI   c                 B   SnU R                  U* S5        [        SS5       nUR                  U R                  U5      5        UR                  S5        UR                  U R                  U5      5        SSS5        U R                  U* S5        g! , (       d  f       N"= f)z5Create text file showing current location in context.i  r   zpypdf_pdfLocation.txtwbs   HEREN)rx   openwriter]   )rZ   radius	output_fhs      r6   mark_locationr     s|     F
KK	%t	,	F+, F+, 
- KK	 
-	,s   AB
Bmsg
stacklevelc                 8    [         R                  " U [        US9  g )N)r   )warningswarnDeprecationWarning)r   r   s     r6   	deprecater     s    MM#)jArI   c                     [        U 5      erm   )r   )r   s    r6   deprecationr     s    
3
rI   old_namenew_name
removed_inc                 .    [        U  SU SU S3S5        g)zFIssue a warning that a feature will be removed, but has a replacement., is deprecated and will be removed in pypdf . Use 	 instead.   Nr   r   r   r   s      r6   deprecate_with_replacementr     s'    *@FS[R\\ef	rI   c                 ,    [        U  SU SU S35        g)zMRaise an exception that a feature was already removed, but has a replacement.( is deprecated and was removed in pypdf r   r   Nr   r   s      r6   deprecation_with_replacementr     s"    *<ZLxjXabrI   namec                 (    [        U  SU S3S5        g)zCIssue a warning that a feature will be removed without replacement.r   r~   r   Nr   r   r   s     r6   deprecate_no_replacementr     s    B:,aPRSTrI   c                 &    [        U  SU S35        g)zJRaise an exception that a feature was already removed without replacement.r   r~   Nr   r   s     r6   deprecation_no_replacementr     s    4&@ANOrI   messagesourcevaluesc                    U(       a&  [         R                  " U5      R                  X5        g[         R                  " U5      R                  U 5        g)z
Use this instead of logger.error directly.

That allows people to overwrite it more easily.

See the docs on when to use which:
https://pypdf.readthedocs.io/en/latest/user/suppress-warnings.html
N)logging	getLoggererrorr   r   r   s      r6   logger_errorr     s9     &!''8&!''0rI   c                    U(       a&  [         R                  " U5      R                  X5        g[         R                  " U5      R                  U 5        g)aa  
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 pypdf, e.g. a non-compliant PDF being read in a way that
  pypdf could apply a robustness fix to still read it. This applies mainly
  to strict=False mode.
N)r   r   warningr   s      r6   logger_warningr     s;      &!))':
 	&!))'2rI   	func_namekwargsaliasesfailc                    UR                  5        Hv  u  pEXA;   d  M  U(       a  [        U SU S35      eXQ;   a  [        U  SU SU SU SU S3
5      eUR                  U5      X'   [        R
                  " U SU S3[        SS	9  Mx     g
)z
Helper function to deprecate arguments.

Args:
    func_name: Name of the function to be deprecated
    kwargs:
    aliases:
    fail:

z# is deprecated as an argument. Use z insteadz received both z and z as an argument. z is deprecated. Use r   r   )r   categoryr   N)itemsr   	TypeErrorpopr   r   r   )r   r   r   r   old_termnew_terms         r6   rename_kwargsr     s     &mmo&j CH:XV  ! k
%z J$$,: .#*I/ 
  &zz(3FMMj CH:XV+ .rI   bytesc                 f    U S:  a  U  S3$ U S:  a	  U S-  S S3$ U S:  a	  U S-  S S3$ U S-  S S3$ )	Ni  z Bytei@B z.1fz kBi ʚ;z MBz GB )r   s    r6   _human_readable_bytesr     s_    u}u}%-$C((u}%-$C((emC $$rI   c                   F    \ rS rSrSrS	S
S jjrS	S\4S jjrS\4S jr	Sr
g)classpropertyi'  z{
Decorator that converts a method with a single cls argument into a property
that can be accessed directly from the class.
Nr   c                     Xl         g rm   fgetselfmethods     r6   __init__classproperty.__init__-  s    	rI   c                 $    U R                  U5      $ rm   r   )r   instanceclss      r6   __get__classproperty.__get__0  s    yy~rI   c                     Xl         U $ rm   r   r   s     r6   getterclassproperty.getter3  s    	rI   r   rm   )r   N)__name__
__module____qualname____firstlineno____doc__r   r
   r   r   r   __static_attributes__r   rI   r6   r   r   '  s$    
S  rI   r   c                   t    \ rS rSr% SSKJr  Sr\\S'    Sr	\
\S'    Sr\\   \S	'    S
\4S jrS
\4S jrSrg)Filei8  r   )IndirectObjectr#   r   rI   dataNindirect_referencer   c           	          U R                   R                   SU R                   S[        [	        U R
                  5      5       S3$ )Nz(name=z, data: ))	__class__r   r   r   r.   r  r   s    r6   __str__File.__str__I  s?    ..))*&8DYZ]^b^g^gZhDiCjjkllrI   c                 \    U R                  5       S S S[        U R                  5       S3-   $ )Nrv   z, hash: r  )r  hashr  r
  s    r6   __repr__File.__repr__L  s,    ||~cr"xTYY/@%BBBrI   r   )r   r   r   r   genericr  r   str__annotations__r  r   r  r   r  r  r  r   rI   r6   r  r  8  sW    'D#N D% 4807m mC# CrI   r  c                       \ rS rSr\R
                  " S5      rS\SS4S jrS\S\	\
\\4      4S jrS\S\4S	 jrS\4S
 jrS\S\4S jrSrg)VersioniP  z^(\d+)(.*)$version_strr   Nc                 <    Xl         U R                  U5      U l        g rm   )r  _parse_version
components)r   r  s     r6   r   Version.__init__T  s    &--k:rI   c                 :   UR                  S5      n/ nU H  n[        R                  R                  U5      nU(       d  UR	                  SU45        M>  UR                  S5      nUR                  S5      nUc  SnUR	                  [        U5      U45        M     U$ )Nr~   r   r   r   )splitr  COMPONENT_PATTERNmatchrM   groupr>   )r   r  r  parsed_components	componentr  integer_prefixsuffixs           r6   r  Version._parse_versionX  s     &&s+
#I--33I>E!((!Y8"[[^N[[^F%!"$$c.&96%BC $ ! rI   otherc                 `    [        U[        5      (       d  gU R                  UR                  :H  $ )NF)
isinstancer  r  )r   r%  s     r6   __eq__Version.__eq__g  s'    %))%"2"222rI   c                 V    [        U R                  [        U R                  5      45      $ rm   )r  r	  r   r  r
  s    r6   __hash__Version.__hash__l  s    T^^U4??%;<==rI   c                 J   [        U[        5      (       d  [        S[        U5       35      e[	        U R
                  UR
                  5       H)  u  p#Uu  pEUu  pgXF:  a    gXF:  a    gXW:  a    gXW:  d  M)    g   [        U R
                  5      [        UR
                  5      :  $ )Nz#Version cannot be compared against TF)r'  r  r1   typer   r  r.   )r   r%  self_componentother_component
self_valueself_suffixother_valueother_suffixs           r6   __lt__Version.__lt__p  s    %))B4;-PQQ/24??EDTDT/U+N&4#J(7%K'')) 0V 4??#c%*:*:&;;;rI   )r  r  )r   r   r   r   recompiler  r  r   listr   r>   r  objectboolr(  r+  r
   r5  r  r   rI   r6   r  r  P  sv    

>2;C ;D ;!# !$uS#X2G !3F 3t 3
># ><C <D <rI   r  rm   )r   )F)Mr   
__author____author_email__	functoolsr   r7  sysr   dataclassesr   r   r   ior   osr   r   typingr	   r
   r   r   r   version_infor   typing_extensionsr   errorsr   r   r   r   r   r   r   r  r   
StreamTyper   BinaryStreamTyper  StrByteTyper7   rH   rQ   rd   r   rn   WHITESPACES_AS_REGEXPr>   ra   rf   r;  ri   rt   ry   maxsizer   r   r   r   r   r   r   r   r   r   r   r   r   dictr   r   r   r  total_orderingr  r   rI   r6   <module>rN     s  8 )
/    	 
  ! ' "    BQ7" +w&  ',	%
eUE&9 :E%PUBU<VV' )  -2	5%u,- 	  W
e9 CO$9Xc] 9x/A 9@H  2- -s -s -& :xx, 33d: *  QV 2 0 U "  (9E 9d 9Aj AT A RUQ\Q\ ,
 ,75> ,3 ,af ,^!1 C E 27(z 7(e 7(t$<	* 	 	B3 BC B B S  X     QU 3 # 3 S[ U3 UC UD U
PS Pc Ph P
1# 1# 1 1 13C 3C 33 34 34 SX   cN 59#s(^ KO 	 F% % %Z " C C C. 1< 1< 1<rI   