o
    ?Hh                     @   s0  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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mZmZ dd	lmZm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' ddl(m)Z)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6 ddlm7Z7m8Z8 e9e:Z;dZ<e=dZ>G dd de?e3Z@G dd deAe3ZBG dd deBZCdeddfddZDG d d! d!eBZEG d"d# d#eEZFG d$d% d%eEZGG d&d' d'eFZH	d1d(ed)ed*edeIe
eI eeJeIf f dee3eJeIeHf fd+d,ZKG d-d. d.eCZLG d/d0 d0eCZMdS )2zMathieu Fenniakzbiziqe@mathieu.fenniak.net    N)BytesIO)AnyDictIterableListOptionalTupleUnioncast   )PdfWriterProtocol)
WHITESPACES
StreamTypeb_deprecate_with_replacementdeprecation_with_replacementhex_strlogger_warningread_non_whitespaceread_until_regexskip_over_comment)CheckboxRadioButtonAttributesFieldDictionaryAttributes)FilterTypes)OutlineFontFlag)StreamAttributes)TypArguments)TypFitArguments)STREAM_TRUNCATED_PREMATURELYPdfReadErrorPdfStreamError   )BooleanObjectFloatObjectIndirectObject
NameObject
NullObjectNumberObject	PdfObjectTextStringObject)Fit)read_hex_string_from_streamread_string_from_streams   +-s   [+-]?(\d+)\s+(\d+)\s+R[^a-zA-Z]c                   @   s   e Zd Z		ddededeeedf ee df dd fd	d
Z	de
e fddZdededeef ddfddZdededeef ddfddZe	ddedededeee eeef f dd fddZedededd fddZdS )ArrayObjectF pdf_destforce_duplicateignore_fields.Nreturnc                 C   s   z| j j|kr|s| W S W n	 ty   Y nw td| t |}| D ].}t|tr<||||||}|	|j  q#t
|drL|	|||| q#|	| q#td|S )clone object into pdf_destr-   clone)indirect_referencepdf	Exceptionr
   _reference_cloner-   
isinstanceStreamObjectr4   appendhasattr)selfr/   r0   r1   arrdatadupr.   r.   _/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/PyPDF2/generic/_data_structures.pyr4   O   s$   


zArrayObject.clonec                 C   s   t | S )zS
        Emulate DictionaryObject.items for a list
        (index, object)
        )	enumerater=   r.   r.   rA   itemsj   s   zArrayObject.itemsstreamencryption_keyc                 C   s8   | d | D ]}| d ||| q| d d S )N   [    s    ])writewrite_to_stream)r=   rE   rF   r?   r.   r.   rA   rJ   q   s
   

zArrayObject.write_to_streamc                 C      t ddd | || d S NwriteToStreamrJ   3.0.0r   rJ   r=   rE   rF   r.   r.   rA   rM   z      zArrayObject.writeToStreamr6   forced_encodingc                 C   s   t  }| d}|dkrtd	 | d}| r#| d}| s| dd | d}|dkr5	 |S | dd |t| || q)Nr!   rG   zCould not read arrayT   ])r-   readr   isspaceseekr;   read_object)rE   r6   rR   r>   tmptok	peekaheadr.   r.   rA   read_from_stream   s"   



zArrayObject.read_from_streamc                 C      t ddd t| |S NreadFromStreamr\   rN   )r   r-   r\   rE   r6   r.   r.   rA   r_         zArrayObject.readFromStreamFr.   N)__name__
__module____qualname__r   boolr	   r   strr   r4   r   r   rD   r   bytesrJ   rM   staticmethodr   intr\   r_   r.   r.   r.   rA   r-   N   s\    

	
r-   c                   @   s  e Zd Z		d*dededeeedf ee df dd fd	d
Z	dd dededeeedf ee f ddf
ddZ
dedefddZdededefddZd+dedee defddZdedefddZedee fddZdee fddZedee fddZdededeef ddfd d!Zdededeef ddfd"d#Ze	d+ded$ed%edeee eeef f dd fd&d'Zeded$edd fd(d)ZdS ),DictionaryObjectFr.   r/   r0   r1   .Nr2   c                 C   st   z| j j|kr|s| W S W n	 ty   Y nw td| |  |}|du r(g }t| dkr8|| ||| |S )r3   rl   Nr   )	r5   r6   r7   r
   r8   	__class__lenkeys_cloner=   r/   r0   r1   d__r.   r.   rA   r4      s   zDictionaryObject.clonesrcc              
   C   s  d|vrd|v s d|vrd|v s d|vrd|v s d|vrd|v rt |}dD ]y}|D ]t}g }||v r|| vrt||trtd|| }| }	|durtd|| |}
|||
f |	duscJ |
j|	t	|< |
}	z||krtd}ntd|| }W n t
y   d}Y nw |dusK|D ]\}}||||||g  qq*q&| D ]B\}}||vrt|trt|dsd|_||||}|jdusJ |j| ||< q|| vrt|d	r||||n|| t	|< qdS )
update the object from src/Next/Prev/N/V))ru   rv   )rw   rx   rl   Nr5   r4   )listr9   raw_getr$   r
   r8   rm   r;   r5   r%   r7   rp   rD   r:   r<   r4   )r=   rs   r/   r0   r1   lstkobjscur_objprev_objclonscvvvr.   r.   rA   rp      sj   



zDictionaryObject._clonekeyc                 C   s   t | |S rc   )dict__getitem__r=   r   r.   r.   rA   rz      s   zDictionaryObject.raw_getvaluec                 C   2   t |ts	tdt |tstdt| ||S Nzkey must be PdfObjectzvalue must be PdfObject)r9   r(   
ValueErrorr   __setitem__r=   r   r   r.   r.   rA   r      
   

zDictionaryObject.__setitem__c                 C   r   r   )r9   r(   r   r   
setdefaultr   r.   r.   rA   r     r   zDictionaryObject.setdefaultc                 C   s   t | | S rc   )r   r   
get_objectr   r.   r.   rA   r   	  s   zDictionaryObject.__getitem__c                 C   sN   ddl m} | dd}|du rdS | }t||s%||}|| td< |S )a  
        Retrieve XMP (Extensible Metadata Platform) data relevant to the
        this object, if available.

        Stability: Added in v1.12, will exist for all future v1.x releases.
        @return Returns a {@link #xmp.XmpInformation XmlInformation} instance
        that can be used to access XMP metadata from the document.  Can also
        return None if no metadata was found on the document root.
        r   )XmpInformationz	/MetadataN)xmpr   getr   r9   r%   )r=   r   metadatar.   r.   rA   xmp_metadata  s   
zDictionaryObject.xmp_metadatac                 C      t ddd | jS )W
        .. deprecated:: 1.28.3

            Use :meth:`xmp_metadata` instead.
        getXmpMetadatar   rN   r   r   rC   r.   r.   rA   r   #  s   zDictionaryObject.getXmpMetadatac                 C   r   )r   xmpMetadatar   rN   r   rC   r.   r.   rA   r   .     zDictionaryObject.xmpMetadatarE   rF   c                 C   sZ   | d t|  D ]\}}||| | d ||| | d q| d d S )N   <<
rH      
   >>)rI   ry   rD   rJ   )r=   rE   rF   r   r   r.   r.   rA   rJ   8  s   

z DictionaryObject.write_to_streamc                 C   rK   rL   rO   rP   r.   r.   rA   rM   C  rQ   zDictionaryObject.writeToStreamr6   rR   c              
      s~  dt dt dtt  dtdt f
 fdd dtdtdtf fd	d
}| d}|dkr5tdt|   di }	 t	| }|dkrAq7|dkrP| 
dd t|  q7|sVtt|dkr`| d nu| 
dd zt| |}t	| }| 
dd t| ||}W n0 ty }	 z$|d ur|jrt|	 t|	 t t }
|
| |
W  Y d }	~	S d }	~	ww ||s|||< ndt|   d| }|d ur|jrt|t|t q8|  }t	| }|dkr| ddkr| d}|dkr| d}|dks|dvrtd|dkr| ddkr| 
dd tj|vr"td|tj }t|tr<|  }||}| 
|d  |  }| ||d!< t	| }| d"}|| d#kr|  }| 
d$d | d%}|d#krv|d! d d |d!< n5|js| 
|d  || ||d!< |  }n| 
|d  td&t|   d'|d(|d)n| 
|d  d!|v rt|S t }
|
| |
S )*Npp1rem_gensr6   r2   c                    s^   |j |d  }|D ]}||| kr| || k r|| }q	t|dkr$|S  | ||dd  |S )Nr   r!   )xrefrn   )r   r   r   r6   loget_next_obj_posr.   rA   r   O  s   z;DictionaryObject.read_from_stream.<locals>.get_next_obj_posrE   c                    sz    |   dt|j|d }|   }| ||    }|d}|dk r,td| d| || d  |d |d  S )Nl        r!   	   endstreamr   z6Unable to find 'endstream' marker for obj starting at .	   )tellry   r   rU   findr   rW   )rE   r6   eoncurrrwr   r   r.   rA   read_unsized_from_steam[  s   

zBDictionaryObject.read_from_stream.<locals>.read_unsized_from_steamr      <<zDictionary read error at byte z: stream must begin with '<<'T       %rS   r!      >z+Multiple definitions in dictionary at byte z	 for key    s   s   treamrH   )r      z)Stream data must be followed by a newliner   r   zStream length not definedr   __streamdata__   r   ir   z7Unable to find 'endstream' marker after stream at byte z (nd='z', end='z').)rk   r   r   r   ri   rU   r   r   r   r   rW   r   r    r   rX   r7   strict__repr__r   rd   rl   updater   SALENGTHr9   r$   r   r:   initialize_from_dictionary)rE   r6   rR   r   rY   r?   rZ   r   r   excretvalmsgposr   eollengthtpstartendstreamendr.   r   rA   r\   I  s   







(













z!DictionaryObject.read_from_streamc                 C   r]   r^   )r   rl   r\   r`   r.   r.   rA   r_     ra   zDictionaryObject.readFromStreamrb   rc   )rd   re   rf   r   rg   r	   r   rh   r   r4   rp   r   rz   r   r   r   r(   r   propertyr   r   r   r   ri   rJ   rM   rj   r   rk   r\   r_   r.   r.   r.   rA   rl      s    

@
	

 rl   c                
   @   s   e Zd Zd&ddZdefddZdefddZdefd	d
Zde	e fddZ
dededdfddZdededdfddZdedededdfddZdeddfddZdededededdf
ddZdeddfddZd&d d!Zd&d"d#Zd&d$d%ZdS )'
TreeObjectr2   Nc                 C   s   t |  d S rc   )rl   __init__rC   r.   r.   rA   r     s   zTreeObject.__init__c                 C      t ddd |  S )NhasChildrenhas_children4.0.0)r   r   rC   r.   r.   rA   r        zTreeObject.hasChildrenc                 C   s   d| v S )N/Firstr.   rC   r.   r.   rA   r        zTreeObject.has_childrenc                 C   s   |   S rc   )childrenrC   r.   r.   rA   __iter__  r   zTreeObject.__iter__c                 c   sb    |   sd S | td }| }	 |V  || td krd S |td}|d u r,d S | }q)Nr   T/Lastru   )r   r%   r   r   )r=   	child_refchildr.   r.   rA   r     s   zTreeObject.childrenr   r6   c                 C   rK   )NaddChild	add_childrN   )r   r   r=   r   r6   r.   r.   rA   r     s   zTreeObject.addChildc                 C   s   |  |d | d S rc   )insert_childr   r.   r.   rA   r     s   zTreeObject.add_childbeforec                    s  dt d ttf dtdd f fdd | }|j}d| vrQ|| td< td| td< || td	< | j|td
<  | |dd d|v rH|d= d|v rO|d= d S t	d| d	 }|j|krd|v rit	d|d }n/t	d||td< |j|td< | j|td
< d|v r|d= || td	<  | |dd d S |j|ks]zt
|d tsJ ||d td< |d |td< W n ty   |d= Y nw ||td< ||td< | j|td
<  | |dd d S )Nparentnr2   c                    s^   | d u rd S t d|  } d| v r-tt t| td | | td<  | dd | d S d S )Nr   /Count/Parent)r
   r   r'   rk   r%   r   )r   r   inc_parent_counterr.   rA   r     s   z3TreeObject.insert_child.<locals>.inc_parent_counterr   r   r   r   r   r!   ru   rv   rl   r   )r	   r$   r   rk   r   r5   r%   r'   r   r
   r9   rl   r7   )r=   r   r   r6   	child_objprevr.   r   rA   r     sX   


zTreeObject.insert_childc                 C      t ddd | | d S )NremoveChildremove_childrN   )r   r   )r=   r   r.   r.   rA   r   4     zTreeObject.removeChildr   prev_refcurlastc                 C   s  | tdd}|du rP|r-| }|td= || td< t| td d | td< dS | td dks7J | td= | td= td| v rN| td= dS dS |rc| }||td< ||td< n||ksiJ |td= || td< t| td d | td< dS )z;Adjust the pointers of the linked list and tree node count.ru   Nrv   r   r   r!   r   )r   r%   r   r'   )r=   r   r   r   r   next_refnext_objr.   r.   rA   _remove_node_from_tree8  s.   



 z!TreeObject._remove_node_from_treec           
      C   s   |  }|j}td|vrtd|td | krtdd}d }d }| td }|  }| td }|  }	|d urg||krJ| ||||	 d}n|}|}td|v r_|td }|  }nd }d }|d us;|smtd	t| d S )
Nr   /Removed child does not appear to be a tree itemz*Removed child is not a member of this treeFr   r   Tru   z"Removal couldn't find item in tree)r   r5   r%   r   r   _reset_node_tree_relationship)
r=   r   r   foundr   r   cur_refr   last_refr   r.   r.   rA   r   [  s:   
zTreeObject.remove_childc                 C   s,   t d| vr
tdtd| d |  dS )z:
        remove the object from the tree it is in
        r   r   r   N)r%   r   r
   r   rC   r.   r.   rA   remove_from_tree  s   zTreeObject.remove_from_treec                 C   s   t ddd |   d S )N	emptyTree
empty_treer   )r   r   rC   r.   r.   rA   r     s   zTreeObject.emptyTreec                 C   sd   | D ]
}|  }t| qtd| v r| td= td| v r#| td= td| v r0| td= d S d S )Nr   r   r   )r   r   r%   )r=   r   r   r.   r.   rA   r     s   


zTreeObject.empty_treer2   N)rd   re   rf   r   rg   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r.   r.   r.   rA   r     s2    
7
#
%
	r   r   r2   c                 C   s>   | t d= t d| v r| t d= t d| v r| t d= dS dS )z}
    Call this after a node has been removed from a tree.

    This resets the nodes attributes in respect to that tree.
    r   ru   rv   N)r%   )r   r.   r.   rA   r     s   

r   c                       s*  e Zd Zd%ddZdedededeee	d	f e
e	 f ddf
 fd
dZdef fddZeded fddZejd&ddZedefddZejdeddfddZdedede	ef ddfddZedee	ef ded fddZedee	ef ded fddZd'd!d"Zd'd#d$Z  ZS )(r:   r2   Nc                 C   s   d | _ d | _d S rc   )_StreamObject__datadecoded_selfrC   r.   r.   rA   r     s   
zStreamObject.__init__rs   r/   r0   r1   .c                    sh   t d|j| _zt d|j}|du rd| _n||d|| _W n	 ty(   Y nw t |||| dS )rt   r:   NT)r
   _datar   r4   r7   superrp   )r=   rs   r/   r0   r1   r   rm   r.   rA   rp     s   zStreamObject._clonec                    s   t   }|t| j7 }|S rc   )r   hash_value_datar   r   r=   r?   r   r.   rA   r     s   
zStreamObject.hash_value_dataDecodedStreamObjectc                 C   r   NdecodedSelfr   rN   r   r   rC   r.   r.   rA   r       zStreamObject.decodedSelfr   c                 C      t ddd || _d S r  r  r=   r   r.   r.   rA   r       
c                 C      | j S rc   r   rC   r.   r.   rA   r     s   zStreamObject._datac                 C   
   || _ d S rc   r
  r  r.   r.   rA   r     s   
rE   rF   c                 C   sp   t t| j| ttj< t| || | tj= |d | j}|r,ddl	m
} |||}|| |d d S )Ns   
stream
r   )RC4_encrypts
   
endstream)r'   rn   r   r%   r   r   rl   rJ   rI   	_securityr  )r=   rE   rF   r?   r  r.   r.   rA   rJ     s   


zStreamObject.write_to_streamr?   )EncodedStreamObjectr  c                 C   s
   t | S rc   )r:   r   )r?   r.   r.   rA   initializeFromDictionary  s   
z%StreamObject.initializeFromDictionaryc                 C   s>   t j| v r	t }nt }| d |_| d= | t j= ||  |S )Nr   )r   FILTERr  r  r   r   r   )r?   r   r.   r.   rA   r     s   


z'StreamObject.initialize_from_dictionaryr  c                 C   r   )NflateEncodeflate_encoderN   )r   r  rC   r.   r.   rA   r    r   zStreamObject.flateEncodec                 C   s   ddl m} tj| v r1| tj }t|tr|dttj	 nt }|
td |
| |}ntd}t }||ttj< || j|_|S )Nr   )FlateDecoder   z/FlateDecode)filtersr  r   r  r9   r-   insertr%   FTFLATE_DECODEr;   r  encoder   )r=   r  fnewfr   r.   r.   rA   r    s   



zStreamObject.flate_encoder   )r   r  r2   N)r2   r  )rd   re   rf   r   rl   r   rg   r	   r   rh   r   rp   ri   r   r   r   r  setterr   r   r   rJ   rj   r   r  r   r  r  __classcell__r.   r.   r   rA   r:     sV    




r:   c                   @   sL   e Zd ZdefddZdedefddZdefddZdedd	fd
dZd	S )r  r2   c                 C   r	  rc   r   rC   r.   r.   rA   get_data  s   zDecodedStreamObject.get_datar?   c                 C   r  rc   r  r   r.   r.   rA   set_data     
zDecodedStreamObject.set_datac                 C   r   NgetDatar  rN   )r   r   rC   r.   r.   rA   r"    s   zDecodedStreamObject.getDataNc                 C   r   NsetDatar  rN   r   r  r   r.   r.   rA   r$    r   zDecodedStreamObject.setData)rd   re   rf   r   r  r  r"  r$  r.   r.   r.   rA   r    s
    r  c                   @   s   e Zd ZdddZeded fddZejdeddfd	dZde	de
ef fd
dZde	de
ef fddZdeddfddZdeddfddZdS )r  r2   Nc                 C   s
   d | _ d S rc   )r   rC   r.   r.   rA   r   $  r   zEncodedStreamObject.__init__r  c                 C   r   r  r  rC   r.   r.   rA   r  '  r  zEncodedStreamObject.decodedSelfr   c                 C   r  r  r  r  r.   r.   rA   r  ,  r  c                 C   sn   ddl m} | jd ur| j S t }|| |_t|  D ]\}}|tj	tj
tjfvr0|||< q|| _|jS )Nr   )decode_stream_data)r  r&  r   r  r  r   ry   rD   r   r   r  DECODE_PARMS)r=   r&  decodedr   r   r.   r.   rA   r  1  s   


zEncodedStreamObject.get_datac                 C   r   r!  )r   r  rC   r.   r.   rA   r"  B  r   zEncodedStreamObject.getDatar?   c                 C   s   t d)Nz7Creating EncodedStreamObject is not currently supported)r   r   r.   r.   rA   r  F  r   zEncodedStreamObject.set_datac                 C   s   t ddd | |S r#  r%  r   r.   r.   rA   r$  I  s   
zEncodedStreamObject.setDatar   )rd   re   rf   r   r   r   r  r  r  r	   rh   ri   r  r"  r   r  r$  r.   r.   r.   rA   r  #  s    
r  c                   @   s  e Zd Z	ddedededeee eeef f ddfddZ				dd
ede
deeedf ee df dd fddZded
ede
deeedf ee f ddf
ddZdeddfddZdedeeef fddZedefddZejdeeef ddfddZdS )ContentStreamNrE   r6   rR   r2   c           	      C   s   || _ g | _|d urU| }t|tr9d}|D ]}|t|  7 }t|dks/|d dkr3|d7 }qt|}n| }|d usCJ t|}t|}|| _	| 
| d S d S )N    r   rS   r   )r6   
operationsr   r9   r-   r   r  rn   r   rR   $_ContentStream__parse_content_stream)	r=   rE   r6   rR   r?   r   stream_bytesstream_datastream_data_bytesr.   r.   rA   r   O  s&   

zContentStream.__init__Fr.   r/   r0   r1   .c                 C   sh   z| j j|kr|s| W S W n	 ty   Y nw td| | dd|}|du r*g }|| ||| |S )r3   r)  N)r5   r6   r7   r
   r8   rm   rp   rq   r.   r.   rA   r4   o  s   zContentStream.cloners   c                 C   s*   || _ ttd|j| _td|j| _dS )rt   r)  N)r6   ry   r
   r+  rR   )r=   rs   r/   r0   r1   r.   r.   rA   rp     s   zContentStream._clonec                 C   s   | dd g }	 t|}|dks|dkrd S | dd | s%|dv rOt|tjd}|dkrD|g ks6J | |}| j|df n'| j||f g }n|d	kra|d
vr`|	d}|d
vsWn
|t
|d | j q	)Nr   Tr*  rS   r!   )   '   "   BI   INLINE IMAGEr   r   r   )rW   r   isalphar   r%   delimiter_pattern_read_inline_imager+  r;   rU   rX   rR   )r=   rE   operandspeekoperatoriir.   r.   rA   __parse_content_stream  s,   

z$ContentStream.__parse_content_streamc                 C   s  t  }	 t|}|dd |dkrnt|| j}t|}|dd t|| j}|||< q|d}|d d dks=J t }	 |d}|sLtd	|d
}	|	dkr[|	| ni|	|d|	  ||	t
| d |d}|d}
|
dkr||	d |	 tv r|d}||
 }d}|tv rd}||7 }|d}|tv s|r|dd n|dd |	| n|dd |	| qA|| dS )NTrS   r!      I   r   s   IDi    zUnexpected end of stream   Er   F)settingsr?   )rl   r   rW   rX   r6   rU   r   r   r   rI   rn   r   getvalue)r=   rE   r@  rZ   r   r   rY   r?   bufloctok2tok3infohas_q_whitespacer.   r.   rA   r7    sX   







&z ContentStream._read_inline_imagec                 C   s   t  }| jD ]Q\}}|dkr;|d t  }|d |d  || dd  |d ||d  |d n|D ]}||d  |d	 q=|t| |d
 q| S )Nr3  r2  r@  r   s   ID r?   s   EIrH   r   )r   r+  rI   rJ   rA  r   )r=   newdatar8  r:  dicttextopr.   r.   rA   r     s    

zContentStream._datar   c                 C   s   |  tt| d S rc   )r,  r   r   r  r.   r.   rA   r     s   rc   rb   )rd   re   rf   r   r	   rh   r   r   rk   r   rg   r   r4   rl   r   rp   r   r,  r7  r   ri   r   r  r.   r.   r.   rA   r)  N  sN    
#

< r)  rE   r6   rR   c              	   C   s  |  d}| dd |dkrt| |S |dkr4|  d}| dd |dkr/t| ||S t| |S |dkr?t| ||S |d	ksG|d
krLt| S |dkrUt| |S |dkri|  ddkri| dd t	 S |dkrrt	| S |dkr|dvr|  d}t
|dkrtd|dvszt| }| dd t| ||S |dv r|  d}| t
| d t|d urt| |S t| S | dd td|d|   d|  d  )Nr!   rS      /   <r   rH  r   rG      t   f   (   e   s   endobji   nr   r4  r   zFile ended unexpectedly.s   0123456789+-.   iz(Invalid Elementary Object starting with z @z: P   )rU   rW   r%   r\   rl   r+   r-   r"   r,   r&   rn   r    r   rX   IndirectPatternmatchr$   r'   r   r   r   )rE   r6   rR   rZ   r9  r.   r.   rA   rX     sP   








"rX   c                   @   st  e Zd ZdZdeeef ddfddZede	e
 fddZede	e
 fd	d
Zede	e fddZede	d fddZede	e fddZede	e fddZede	e fddZede	e fddZede	e fddZede	e fddZede	e fddZede	e fddZede	e fd d!Zede	e fd"d#Zede	e fd$d%ZdS )&Fieldz
    A class representing a field dictionary.

    This class is accessed through
    :meth:`get_fields()<PyPDF2.PdfReader.get_fields>`
    r?   r2   Nc              	   C   sN   t |  t t  }|D ]}z
|| | t|< W q ty$   Y qw d S rc   )rl   r   r   
attributesr   r%   KeyError)r=   r?   field_attributesattrr.   r.   rA   r   E  s   
zField.__init__c                 C      |  tjS )z4Read-only property accessing the type of this field.)r   r   r  rC   r.   r.   rA   
field_typeR     zField.field_typec                 C   r   )zX
        .. deprecated:: 1.28.3

            Use :py:attr:`field_type` instead.
        	fieldTyper^  rN   )r   r^  rC   r.   r.   rA   r`  W  r   zField.fieldTypec                 C   r]  )z6Read-only property accessing the parent of this field.)r   r   ParentrC   r.   r.   rA   r   a  r_  zField.parentr-   c                 C   r]  )z4Read-only property accessing the kids of this field.)r   r   KidsrC   r.   r.   rA   kidsf  r_  z
Field.kidsc                 C   r]  )z4Read-only property accessing the name of this field.)r   r   TrC   r.   r.   rA   namek  r_  z
Field.namec                 C   r]  )z>Read-only property accessing the alternate name of this field.)r   r   TUrC   r.   r.   rA   alternate_namep  r_  zField.alternate_namec                 C   r   )z\
        .. deprecated:: 1.28.3

            Use :py:attr:`alternate_name` instead.
        altNamerg  rN   )r   rg  rC   r.   r.   rA   rh  u  r   zField.altNamec                 C   r]  )z
        Read-only property accessing the mapping name of this field. This
        name is used by PyPDF2 as a key in the dictionary returned by
        :meth:`get_fields()<PyPDF2.PdfReader.get_fields>`
        )r   r   TMrC   r.   r.   rA   mapping_name     zField.mapping_namec                 C   r   )zZ
        .. deprecated:: 1.28.3

            Use :py:attr:`mapping_name` instead.
        mappingNamerj  rN   )r   rj  rC   r.   r.   rA   rl    r   zField.mappingNamec                 C   r]  )z
        Read-only property accessing the field flags, specifying various
        characteristics of the field (see Table 8.70 of the PDF 1.7 reference).
        )r   r   FfrC   r.   r.   rA   flags     zField.flagsc                 C   r]  )zr
        Read-only property accessing the value of this field. Format
        varies based on field type.
        )r   r   VrC   r.   r.   rA   r     ro  zField.valuec                 C   r]  )z=Read-only property accessing the default value of this field.)r   r   DVrC   r.   r.   rA   default_value  r_  zField.default_valuec                 C   r   )z[
        .. deprecated:: 1.28.3

            Use :py:attr:`default_value` instead.
        defaultValuerr  rN   )r   rr  rC   r.   r.   rA   rs    r   zField.defaultValuec                 C   r]  )z
        Read-only property accessing the additional actions dictionary.
        This dictionary defines the field's behavior in response to trigger events.
        See Section 8.5.2 of the PDF 1.7 reference.
        )r   r   AArC   r.   r.   rA   additional_actions  rk  zField.additional_actionsc                 C   r   )z`
        .. deprecated:: 1.28.3

            Use :py:attr:`additional_actions` instead.
        additionalActionsru  rN   )r   ru  rC   r.   r.   rA   rv    r   zField.additionalActions)rd   re   rf   __doc__r   rh   r   r   r   r   r%   r^  r`  rl   r   rc  re  rg  rh  rj  rl  rk   rn  r   rr  rs  ru  rv  r.   r.   r.   rA   rX  =  sB    				rX  c                   @   s  e Zd ZU dZdZee ed< g Ze	e
 ed< dedeeeeef deddfd	d
Zed*ddZd*ddZdededeef ddfddZedee fddZedee fddZedee fddZedee fddZedee fddZedee fddZedee fd d!Z edee fd"d#Z!eded fd$d%Z"edee# fd&d'Z$edee fd(d)Z%dS )+Destinationa  
    A class representing a destination within a PDF file.
    See section 8.2.1 of the PDF 1.6 reference.

    :param str title: Title of this destination.
    :param IndirectObject page: Reference to the page of this destination. Should
        be an instance of :class:`IndirectObject<PyPDF2.generic.IndirectObject>`.
    :param Fit fit: How the destination is displayed.
    :raises PdfReadError: If destination type is invalid.


    Nnodechildstitlepagefitr2   c                 C   sl  |j }|j}t|  t|| td< || td< || td< |dkr8|\| ttj< | ttj< | td< d S |t	j
krY|\| ttj< | ttj< | ttj< | ttj< d S |t	jt	jfv rz|\| ttj< W d S  ty~   t | ttj< Y d S w |t	jt	jfv rz|\| ttj< W d S  ty   t | ttj< Y d S w |t	jt	jfv rd S td|)N/Title/Page/Typez/XYZ/ZoomzUnknown Destination Type: )fit_typefit_argsrl   r   r)   r%   TALEFTTOPTFFIT_RBOTTOMRIGHTFIT_HFIT_BHr7   r&   FIT_VFIT_BVFITFIT_Br   )r=   r{  r|  r}  typargsr.   r.   rA   r     sD   

zDestination.__init__r-   c                    s(   t  d d g fdddD  S )Nr  r  c                    s   g | ]
}| v r | qS r.   r.   ).0xrC   r.   rA   
<listcomp>  s
    z*Destination.dest_array.<locals>.<listcomp>)/Left/Bottom/Right/Topr  )r-   rz   rC   r.   rC   rA   
dest_array  s   
zDestination.dest_arrayc                 C   r   )zX
        .. deprecated:: 1.28.3

            Use :py:attr:`dest_array` instead.
        getDestArrayr  rN   )r   r  rC   r.   r.   rA   r    s   zDestination.getDestArrayrE   rF   c                 C   s   | d td}||| | d | j}||| td}||| | d td}||| | d | d d S )Nr   z/DrH   z/Sz/GoTor   r   )rI   r%   rJ   r  )r=   rE   rF   r   r   value_sr.   r.   rA   rJ     s   



zDestination.write_to_streamc                 C   
   |  dS )z3Read-only property accessing the destination title.r~  r   rC   r.   r.   rA   r{  *     
zDestination.titlec                 C   r  )z9Read-only property accessing the destination page number.r  r  rC   r.   r.   rA   r|  /  r  zDestination.pagec                 C   r  )z2Read-only property accessing the destination type.r  r  rC   r.   r.   rA   r  4  r  zDestination.typc                 C      |  ddS )z-Read-only property accessing the zoom factor.r  Nr  rC   r.   r.   rA   zoom9  r_  zDestination.zoomc                 C   r  )z<Read-only property accessing the left horizontal coordinate.r  Nr  rC   r.   r.   rA   left>  r_  zDestination.leftc                 C   r  )z=Read-only property accessing the right horizontal coordinate.r  Nr  rC   r.   r.   rA   rightC  r_  zDestination.rightc                 C   r  )z9Read-only property accessing the top vertical coordinate.r  Nr  rC   r.   r.   rA   topH  r_  zDestination.topc                 C   r  )z<Read-only property accessing the bottom vertical coordinate.r  Nr  rC   r.   r.   rA   bottomM  r_  zDestination.bottomc                 C   s"   |  dttdtdtdgS )zGRead-only property accessing the color in (R, G, B) with values 0.0-1.0z/Cr   )r   r-   r#   rC   r.   r.   rA   colorR  s   zDestination.colorc                 C   r  )zDRead-only property accessing the font type. 1=italic, 2=bold, 3=bothz/Fr   r  rC   r.   r.   rA   font_formatY  r_  zDestination.font_formatc                 C   r  )z
        Read-only property accessing the outline count.
        positive = expanded
        negative = collapsed
        absolute value = number of visible descendents at all levels
        r   Nr  rC   r.   r.   rA   outline_count^  s   zDestination.outline_count)r2   r-   )&rd   re   rf   rw  ry  r   rl   __annotations__rz  r   r   rh   r	   r'   r$   r&   r*   r   r   r  r  r   ri   rJ   r{  rk   r|  r  r  r#   r  r  r  r  r  r   r  r  r.   r.   r.   rA   rx    s`   
 
+

	
rx  rc   )N
__author____author_email__loggingreior   typingr   r   r   r   r   r   r	   r
   
_protocolsr   _utilsr   r   r   r   r   r   r   r   r   r   	constantsr   r   r   r  r   r   r   r   r  r   r  errorsr   r   r    _baser"   r#   r$   r%   r&   r'   r(   r)   _fitr*   r+   r,   	getLoggerrd   loggerNumberSignscompilerV  ry   r-   r   rl   r   r   r:   r  r  r)  rh   rk   rX   rX  rx  r.   r.   r.   rA   <module>   s\   (0(


S  : Bl+ <
7 	