
    j:j              	          S SK JrJrJrJr  SSKJr  SSKJrJ	r	J
r
JrJrJr  \(       a  SSKJr  SSKJr  SSKJr   " S	 S
5      r " S S5      r\\\4   rSSSSS\\\\4      4S jrS\
SSS\\   4S jrS\SSS\\   4S jrg)    )TYPE_CHECKINGOptionalUnioncast   )logger_warning   )ArrayObjectDictionaryObjectIndirectObject	PdfObjectTextStringObjectis_null_or_none)
PageObject)	PdfReader)	PdfWriterc                   \    \ rS rSrSrS\SSSS4S jrS\\S4   4S	 jr	S
SS\SS4S jr
Srg)NamedReferenceLink*   zGNamed reference link being preserved until we can resolve it correctly.	reference
source_pdfr   returnNc                     Xl         X l        g)z0reference: TextStringObject with named referenceN
_reference_source_pdf)selfr   r   s      I/var/www/website/venv/lib/python3.13/site-packages/pypdf/generic/_link.py__init__NamedReferenceLink.__init__-   s    #%    c                     U R                   R                  R                  [        U R                  5      5      nU(       a  UR
                  $ S $ N)r   named_destinationsgetstrr   page)r   destinations     r   find_referenced_page'NamedReferenceLink.find_referenced_page2   s:    &&99==c$//>RS#.{8D8r!   
target_pdfr   new_pagec                     [        U R                  5      UR                  ;  a0  UR                  [        U R                  5      UR                  5        gg)2target_pdf: PdfWriter which the new link went intoN)r&   r   r$   add_named_destinationpage_numberr   r+   r,   s      r   patch_reference"NamedReferenceLink.patch_reference6   s@     tz'D'DD,,S-A8CWCWX Er!   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r)   r2   __static_attributes__ r!   r   r   r   *   sV    Q&"2 & &PT &
9eND,@&A 9Y+ Y YTX Yr!   r   c                   N    \ rS rSrSrS\SS4S jrS\4S jrSS	S
\SS4S jr	Sr
g)DirectReferenceLink=   zHDirect reference link being preserved until we can resolve it correctly.r   r   Nc                     Xl         g)zIreference: an ArrayObject whose first element is the Page indirect objectNr   )r   r   s     r   r   DirectReferenceLink.__init__@   s    #r!   c                 <    [        [        U R                  S   5      $ )Nr   )r   r   r   )r   s    r   r)   (DirectReferenceLink.find_referenced_pageD   s    NDOOA$677r!   r+   r   r,   c                      X R                   S'   g)r.   r   Nr?   r1   s      r   r2   #DirectReferenceLink.patch_referenceG   s    %r!   r?   )r4   r5   r6   r7   r8   r
   r   r   r)   r2   r9   r:   r!   r   r<   r<   =   s?    R$+ $$ $8n 8&+ & &TX &r!   r<   r,   r   old_pager   c                    U R                  S[        5       5      R                  5       nUR                  S[        5       5      R                  5       n[        U5      (       a
  [        5       n[        U5      (       a
  [        5       n[	        U[        5      (       a  [	        U[        5      (       d  [        S[        UUS9  / $ U Vs/ s H  n[        X@5      =nc  M  UPM     nnU Vs/ s H  n[        XA5      =nc  M  UPM     nn[        U5      [        U5      :w  a"  [        S[        [        U5      [        U5      S9  [        [        Xg5      5      $ s  snf s  snf )a  Extracts links from two pages on the assumption that the two pages are
the same. Produces one list of (new link, old link) tuples.

Non-link annotations are ignored before pairing to avoid dropping valid
links when one page includes additional non-link annotation entries.
z/AnnotszZExpected annotation arrays: %(old_annotations)s %(new_annotations)s. Ignoring annotations.)sourceold_annotationsnew_annotationsz8Annotation sizes differ: %(old_count)d vs. %(new_count)d)rG   	old_count	new_count)r%   r
   
get_objectr   
isinstancer   r4   _build_linklenlistzip)r,   rE   rI   rH   
annotationlink	new_links	old_linkss           r   extract_linksrV   O   s;    ll9km<GGIOll9km<GGIO''%-''%-o{33:oWb;c;ch++		
 	 *)J
55D 	)   *)J
55D 	)   9~Y'F)n)n		
 I)**'
s   EE'E=Eindirect_objectr'   c                 v   [        SUR                  5      n[        [        U R                  5       5      n[	        U[        5      (       a  UR                  S5      S:w  a  g SU;   a?  [        [        US   5      nUR                  S5      S:w  a  g SU;  a  g [        US   U5      $ SU;   a  [        US   U5      $ g )	Nr   z/Subtypez/Linkz/Az/Sz/GoToz/Dz/Dest)r   pdfr   rL   rM   r%   _create_link)rW   r'   srcrS   actions        r   rN   rN   z   s    
{DHH
%C /"<"<">?Dt-..488J3G73Rt|&T
3::dw&vF4L#..$DM3//r!   r   r   r   c                     [        U [        5      (       a  [        X5      $ [        U [        5      (       a  [	        U 5      $ g r#   )rM   r   r   r
   r<   )r   r   s     r   rZ   rZ      s6    )-..!)88)[))"9--r!   N)typingr   r   r   r   _utilsr    r
   r   r   r   r   r   _pager   _readerr   _writerr   r   r<   ReferenceLinkrP   tuplerV   rN   rZ   r:   r!   r   <module>rf      s   > 8 7 # i i"##Y Y&& & (*==>(+L (+L (+T%P]_lPlJmEn (+V | Q^H_ *I ; 8MCZ r!   