o
    >ek                     @   sD  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mZmZmZ ddlmZmZ ddl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!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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 ddlm:Z:m;Z; e<e=Z>dZ?e@dZAG dd dee e6ZBG dd de	eef e6ZCG dd deCZDdeddfddZEG dd  d eCZFG d!d" d"eFZGG d#d$ d$eFZHG d%d& d&eGZI	d0d'ed(ee d)edeJeeJ e	eKeJf f dee6eKeJeIf fd*d+ZLG d,d- d-eDZMG d.d/ d/eDZNdS )1zMathieu Fenniakzbiziqe@mathieu.fenniak.net    N)BytesIO)AnyCallableDictIterableListOptionalSequenceSetTupleUnioncast   )PdfReaderProtocolPdfWriterProtocol)	WHITESPACES
StreamTypeb_deprecate_no_replacementdeprecate_with_replacementlogger_warningread_non_whitespaceread_until_regexskip_over_comment)CheckboxRadioButtonAttributesFieldDictionaryAttributesOutlineFontFlag)FilterTypes)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ee	f   dd fddZ
dee fd	d
Z	ddededeef ddfddZe	ddedee dedeee ee	ef f dd fddZdS )ArrayObjectF pdf_destforce_duplicateignore_fields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rN|	|||| q$|	| q$|S )Clone object into pdf_dest.r0   clone)indirect_referencepdf	Exceptionr   _reference_cloner0   
isinstanceStreamObjectr7   appendhasattr)selfr2   r3   r4   arrdatadupr1   r1   _/var/www/html/humari/django-venv/lib/python3.10/site-packages/pypdf/generic/_data_structures.pyr7   Z   s.   

zArrayObject.clonec                 C   s   t | S )z:Emulate DictionaryObject.items for a list (index, object).)	enumerater@   r1   r1   rD   itemsx   s   zArrayObject.itemsNstreamencryption_keyc                 C   sH   |d ur	t dd |d | D ]}|d || q|d d S )N/the encryption_key parameter of write_to_stream5.0.0   [    s    ])r   writewrite_to_stream)r@   rH   rI   rB   r1   r1   rD   rO   |   s   

zArrayObject.write_to_streamr9   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$   rL   zCould not read arrayT   ])r0   readr"   isspaceseekr>   read_object)rH   r9   rP   rA   tmptok
peek_aheadr1   r1   rD   read_from_stream   s"   



zArrayObject.read_from_streamFr1   N)__name__
__module____qualname__r   boolr   r	   r   strintr7   r   r   rG   r   bytesrO   staticmethodr   r   r   rZ   r1   r1   r1   rD   r0   Y   s@    

r0   c                   @   sH  e Zd Z		d"dededeeeee	f   dd fddZ
d	d dededeeeee	f   d
ee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#dededeef ddfddZe	d#dedee dedeee ee	ef f dd fd d!ZdS )$DictionaryObjectFr1   r2   r3   r4   r5   c                 C   s~   z| j j|kr|s| W S W n	 ty   Y nw t }td| |  ||}|du r,g }t| dkr=|	| |||| |S )r6   re   Nr   )
r8   r9   r:   setr   r;   	__class__lenkeys_cloner@   r2   r3   r4   visitedd__r1   r1   rD   r7      s"   zDictionaryObject.clonesrcrl   Nc              
      s  d} dusJ t   |t k r;t | tr1tt | dkr) |=  |= q |  d8  < |d7 }|t k st fdddD rt   dD ]}|D ]}g }	|v r|| vrt|trt| tr	dddu stt| 	dddu s	ddtt| 	ddkrtd	| }
| }|
durtd	|

|
 ||}|jdur|jj}|jj}||f|v rd}
n>|||f |	|
|f |dusJ |j|t|< |}z|
krd}
ntd	|
| }
W n ty   d}
Y nw |
dus|	D ]\}}|||| | qqRqN D ]J\}}| vrft|trNt|d
s5d|_||| }|jdusDJ |j| ||< q|| vrft|dr`||| n|| t|< qdS )z
        Update the object from src.

        Args:
            src: "DictionaryObject":
            pdf_dest:
            force_duplicate:
            ignore_fields:
        r   Nr$   c                 3   s    | ]@}| vo@|v o@t |to@t | to@d ddu p@tt| d ddu p@d dtt| d dkV  qdS )/TypeN)r<   raw_getr'   re   getr   ).0fieldr4   rn   r1   rD   	<genexpr>   s"    

z*DictionaryObject._clone.<locals>.<genexpr>)/Next/Prev/N/V))rv   rw   )rx   ry   ro   re   r8   r7   )listrh   r<   rb   r   anyrp   r'   re   rq   r;   rg   r8   idnum
generationaddr>   r(   r:   rj   rG   r=   r?   r7   )r@   rn   r2   r3   r4   rl   xlstkobjscur_objprev_objclonr|   r}   scvvvr1   rt   rD   rj      s   








3


zDictionaryObject._clonekeyc                 C   s   t | |S r\   )dict__getitem__r@   r   r1   r1   rD   rp   -  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)r<   r+   
ValueErrorr   __setitem__r@   r   r   r1   r1   rD   r   0  
   

zDictionaryObject.__setitem__c                 C   r   r   )r<   r+   r   r   
setdefaultr   r1   r1   rD   r   7  r   zDictionaryObject.setdefaultc                 C   s   t | | S r\   )r   r   
get_objectr   r1   r1   rD   r   >  s   zDictionaryObject.__getitem__c                 C   sN   ddl m} | dd}|du rdS | }t||s%||}|| td< |S )u  
        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.
        See Table 315 – Additional entries in a metadata stream dictionary

        Returns:
          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   rq   r   r<   r(   )r@   r   metadatar1   r1   rD   xmp_metadataA  s   
zDictionaryObject.xmp_metadatarH   rI   c                 C   s   |d ur	t dd |d t|  D ],\}}t|dkr+|d dkr+|d dkr+q||| |d || |d	 q|d
 d S )NrJ   rK      <<
r   r$   %rQ   rM      
   >>)r   rN   rz   rG   rh   rO   )r@   rH   rI   r   r   r1   r1   rD   rO   [  s   
$

z DictionaryObject.write_to_streamr9   rP   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>|d ur+|jr+tdtd |   t td|ttj< |tj }t|tr_|  }|d usTJ ||}| 
|d! |d u rfd}|  }|d!krw| ||d"< n
t| t d#|d"< t	| }| d$}|| d#kr|  }| 
d%d | d&}|d#kr|d" d d |d"< n:|d ur|js| 
|d! || ||d"< |  }n| 
|d! td't|   d(|d)|d*n| 
|d! d"|v rt!"|S t }
|
| |
S )+Npp1rem_gensr9   r5   c                    s^   |j |d  }|D ]}||| kr| || k r|| }q	t|dkr$|S  | ||dd  |S )Nr   r$   )xrefrh   )r   r   r   r9   locoget_next_obj_posr1   rD   r   r  s   z;DictionaryObject.read_from_stream.<locals>.get_next_obj_posrH   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 .	   )tellrz   r   rS   findr"   rU   )rH   r9   eoncurrrwr   r   r1   rD   read_unsized_from_stream~  s   

zCDictionaryObject.read_from_stream.<locals>.read_unsized_from_streamr      <<zDictionary read error at byte z: stream must begin with '<<'T       %rQ   r$      >z+Multiple definitions in dictionary at byte z	 for key    s   s   treamrM   )r      z)Stream data must be followed by a newliner   r   zStream length not definedzStream length not defined @pos=r   __streamdata__r      ir   z7Unable to find 'endstream' marker after stream at byte z (nd='z', end='z').)#rb   r   r   r   rc   rS   r"   hexr   r   rU   r   r#   r!   rV   r:   strict__repr__r   r]   re   updaterq   SALENGTHr*   r(   r<   r'   r   r   recompiler=   initialize_from_dictionary)rH   r9   rP   r   rW   rB   rX   r   r   excretvalmsgposr   eollengthtpstartendstreamendr1   r   rD   rZ   l  s   







(















z!DictionaryObject.read_from_streamr[   r\   )r]   r^   r_   r   r`   r   r	   r   ra   rb   r7   r
   r   rj   r   rp   r   r   r+   r   propertyr   r   rc   rO   rd   r   r   r   rZ   r1   r1   r1   rD   re      sd    

q
re   c                   @   s2  e Zd Zd+dee ddf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 f deddfddZdeded f deddfddZ	d+de	de	dedeede	f  de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 )-
TreeObjectNdctr5   c                 C   s    t |  |r| | d S d S r\   )re   __init__r   )r@   r   r1   r1   rD   r     s   
zTreeObject.__init__c                 C   s   t ddd |  S )NhasChildrenhas_children4.0.0)r   r   rF   r1   r1   rD   r   	  s   zTreeObject.hasChildrenc                 C   s   d| v S )N/Firstr1   rF   r1   r1   rD   r        zTreeObject.has_childrenc                 C   s   |   S r\   )childrenrF   r1   r1   rD   __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/Lastrv   )r   r(   r   rq   )r@   	child_refchildr1   r1   rD   r     s   zTreeObject.childrenr   r9   c                 C   s   |  |d | d S r\   )insert_child)r@   r   r9   r1   r1   rD   	add_child"  s   zTreeObject.add_childparentnc                 C   sf   |d u rd S t d| }d|v r1ttdt t|td | |td< | |dd | d S d S )Nr   /Countr   /Parent)r   r   r*   maxrb   r(   inc_parent_counter_defaultrq   )r@   r   r   r1   r1   rD   r   %  s   z%TreeObject.inc_parent_counter_defaultc                 C   s   |d u rd S t d| }|dddk}t t|dd}|dk r&t|}t|| |r.dnd |td< |s:d S | |dd | d S )	Nr   z
/%is_open%Tr   r   r$   rQ   r   )r   r   rq   rb   absr*   r(   inc_parent_counter_outline)r@   r   r   opnr   r1   r1   rD   r   1  s    z%TreeObject.inc_parent_counter_outlinebeforeinc_parent_counter.c                 C   s  |d u r| j }| }|j}d| vrF|| td< td| td< || td< | j|td< || |dd d|v r=|d= d|v rD|d= |S td	| d }|j|krd|v r^td
|d }n/td
||td< |j|td< | j|td< d|v r||d= || td< || |dd |S |j|ksRz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 |S )Nr   r   r   r   r   r$   rv   rw   re   r   )
r   r   r8   r(   r*   rq   r   r<   re   r:   )r@   r   r   r9   r   	child_objprevr1   r1   rD   r   A  sP   


zTreeObject.insert_childr   prev_refcurlastc                 C   s   | tdd}|du rI|r-| }|td= || td< t| td d | td< dS td| td< | td= td| v rG| td= dS dS |r\| }||td< ||td< n||ksbJ |td= || td< t| td d | td< dS )	z
        Adjust the pointers of the linked list and tree node count.

        Args:
            prev:
            prev_ref:
            cur:
            last:
        rv   Nrw   r   r   r$   r   r   )rq   r(   r   r*   )r@   r   r   r   r   next_refnext_objr1   r1   rD   _remove_node_from_treet  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   Trv   z"Removal couldn't find item in tree)r   r8   r(   r   r   _reset_node_tree_relationship)
r@   r   r   foundr   r   cur_refr   last_refr   r1   r1   rD   remove_child  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   rF   r1   r1   rD   remove_from_tree  s   zTreeObject.remove_from_treec                 C   s   t ddd |   d S )N	emptyTree
empty_treer   )r   r   rF   r1   r1   rD   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   r1   r1   rD   r     s   


zTreeObject.empty_treer\   r5   N)r]   r^   r_   r   re   r   r`   r   r   r   r   r   r   r   r   r   r'   rb   r   r   r   r   r   r   r   r   r   r1   r1   r1   rD   r     s`    


3
*
%
r   r   r5   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.

    Args:
        child_obj:
    r   rv   rw   N)r(   )r   r1   r1   rD   r     s   
	
r   c                       s  e Zd Zd!ddZdedededeee	e
ef   d	eeeef  ddf fd
dZde	ee
f fddZdeddfddZdef fddZ	d"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eddfdd Z  ZS )$r=   r5   Nc                 C   s   d| _ d | _d S N    )_datadecoded_selfrF   r1   r1   rD   r     s   
zStreamObject.__init__rn   r2   r3   r4   rl   c                    sp   t d|j| _zt d|j}|du rd| _nt d||||| _W n	 ty+   Y nw t ||||| dS )
        Update the object from src.

        Args:
            src:
            pdf_dest:
            force_duplicate:
            ignore_fields:
        r=   NDecodedStreamObject)r   r   r   r7   r:   superrj   )r@   rn   r2   r3   r4   rl   r   rg   r1   rD   rj     s   zStreamObject._clonec                 C   s   | j S r\   r   rF   r1   r1   rD   get_data  s   zStreamObject.get_datarB   c                 C   s
   || _ d S r\   r  r@   rB   r1   r1   rD   set_data     
zStreamObject.set_datac                    s   t   }|t| j7 }|S r\   )r   hash_value_datar   r   r  r  r1   rD   r    s   
zStreamObject.hash_value_datarH   rI   c                 C   sb   |d ur	t dd tt| j| ttj< t| | | tj= |	d |	| j |	d d S )NrJ   rK   s   
stream
s
   
endstream)
r   r*   rh   r   r(   r   r   re   rO   rN   r@   rH   rI   r1   r1   rD   rO     s   
zStreamObject.write_to_stream)EncodedStreamObjectr   c                 C   s
   t | S r\   )r=   r   )rB   r1   r1   rD   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   )rB   r   r1   r1   rD   r   .  s   


z'StreamObject.initialize_from_dictionaryrQ   levelr	  c              	   C   s  ddl m} tj| v r]| tj }t|trFtttjg|}ztt	 g| 
tjt }W n4 tyE   tt	 | 
tjt g}Y nw tttj|g}tt	 | 
tjt	 g}nttj}d }t }||  ||ttj< |d ur~||ttj< |t| j||_|S )Nr   FlateDecode)filtersr  r   r  r<   r0   r(   FTFLATE_DECODEr)   rq   DECODE_PARMS	TypeErrorr	  r   encoder   r   )r@   r  r  fparmsr   r1   r1   rD   flate_encode=  s6   




zStreamObject.flate_encoder   r\   )rQ   )r]   r^   r_   r   re   r   r`   r   r	   r   ra   rb   r
   r   rj   rc   r  r  r  r   rO   rd   r   r   r
  r   r  __classcell__r1   r1   r  rD   r=     sN    



r=   c                   @   s   e Zd ZdS )r   N)r]   r^   r_   r1   r1   r1   rD   r   ^  s    r   c                       sF   e Zd Zd
ddZdeeef fddZdeddf fdd	Z  Z	S )r	  r5   Nc                 C   s
   d | _ d S r\   )r   rF   r1   r1   rD   r   c  r  zEncodedStreamObject.__init__c                 C   sx   ddl m} | jd ur| j S t }|t||  t|  D ]\}}|t	j
t	jt	jfvr4|||< q"|| _| S )Nr   )decode_stream_data)r  r  r   r  r   r  r   rz   rG   r   r   r  r  )r@   r  decodedr   r   r1   r1   rD   r  g  s   

zEncodedStreamObject.get_datarB   c                    sj   ddl m} | tjdtjkr1t|tst	d| j
d us J | j
| t || d S td)Nr   r   zdata must be byteszLStreams encoded with different filter from only FlateDecode is not supported)r  r  rq   r   r  r  r  r<   rc   r  r   r  r   r  r"   )r@   rB   r  r  r1   rD   r  y  s   
zEncodedStreamObject.set_datar   )
r]   r^   r_   r   r   rc   ra   r  r  r  r1   r1   r  rD   r	  b  s    
r	  c                       s  e Zd ZdZ	d&dedededeee ee	ef f ddf fddZ
			
d'dededeeeee	f   dd fddZdedededeeeee	f   deee	e	f  ddf fddZdeddfddZdedeeef fddZdefddZdeddf fddZedeeeef  fddZejdeeeef  ddfd dZd(d!d"Z	d&ded#edeef ddf fd$d%Z  ZS ))ContentStreama  
    In order to be fast, this datastructure can contain either:
    * raw data in ._data
    * parsed stream operations in ._operations

    At any time, ContentStream object can either have one or both of those fields defined,
    and zero or one of those fields set to None.

    Those fields are "rebuilt" lazily, when accessed:
    * when .get_data() is called, if ._data is None, it is rebuilt from ._operations
    * when .operations is called, if ._operations is None, it is rebuilt from ._data

    On the other side, those fields can be invalidated:
    * when .set_data() is called, ._operations is set to None
    * when .operations is set, ._data is set to None
    NrH   r9   rP   r5   c                    s   || _ g | _|d u rt d d S | }t|trEd}|D ]}|t|  7 }t	|dks7|d dkr;|d7 }qt t
| n| }|d usOJ t t| || _d S )Nr   r   rQ   r   )r9   _operationsr   r  r   r<   r0   r   r  rh   rc   rP   )r@   rH   r9   rP   rB   r   stream_datar  r1   rD   r     s"   

zContentStream.__init__Fr1   r2   r3   r4   c                 C   sr   z| j j|kr|s| W S W n	 ty   Y nw t }td| | dd||}|du r.g }|| |||| |S )z
        Clone object into pdf_dest.

        Args:
            pdf_dest:
            force_duplicate:
            ignore_fields:

        Returns:
            The cloned ContentStream
        r  N)r8   r9   r:   rf   r   r;   rg   rj   rk   r1   r1   rD   r7     s$   zContentStream.clonern   rl   c                    s:   t d|}t t|j || _t|j| _|j| _dS )r   r  N)	r   r   r  r   r   r9   rz   r  rP   )r@   rn   r2   r3   r4   rl   src_csr  r1   rD   rj     s
   
zContentStream._clonec                 C   s   | dd g }	 t|}|dks|dkrd S | dd | s%|dv rNt|tj}|dkrC|g ks5J | |}| j|df n'| j||f g }n|d	kr`|d
vr_|	d}|d
vsVn
|t
|d | j q	)Nr   Tr   rQ   r$   )   '   "   BI   INLINE IMAGEr   )r   r   r   )rU   r   isalphar   r(   delimiter_pattern_read_inline_imager  r>   rS   rV   rP   )r@   rH   operandspeekoperatoriir1   r1   rD   _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[|	| n|	|d|	  ||	t
| d |d}|d}
|
dkr|dd |	| q@||
 }|d}|tvr|dd |	| nT||	d |	 tv r|tv r|d}|tv s|dd n7|tv r||7 }|d}|tv s|dd |dkrn|d
kr|d}|dd |dkrnn|	| qA|| dS )NTrQ   r$      I   r   s   IDi    zUnexpected end of stream   Er      Qs   EMC)settingsrB   )re   r   rU   rV   r9   rS   r   r"   r   rN   rh   r   getvalue)r@   rH   r2  rX   r   r   rW   rB   bufr   tok2infotok3oper1   r1   rD   r&    sz   








8z ContentStream._read_inline_imagec                 C   s   | j s^t }| jD ]O\}}|dkr=|d t }|d | || dd  |d ||d  |d n|D ]}|| |d	 q?|t| |d
 q	| | _ t| j S )Nr#  r"  r2  r   r/  s   ID rB   s   EIrM   r   )r   r   r  rN   rO   r3  r   )r@   new_datar'  r)  	dict_textopr1   r1   rD   r  d  s$   




zContentStream.get_datarB   c                    s   t  | g | _d S r\   )r   r  r  r  r  r1   rD   r  z  s   
zContentStream.set_datac                 C   s,   | j s| jr| tt| j d| _| j S r   )r  r   r+  r   r   rF   r1   r1   rD   
operations~  s   zContentStream.operationsr<  c                 C   s   || _ d| _d S r   )r  r   )r@   r<  r1   r1   rD   r<    s   
c                 C   sN   | j r| j dg df | j g df d S | jr%dt| j d | _d S d S )Nr   qQs   q
s   Q
)r  insertr>   r   r   rF   r1   r1   rD   isolate_graphics_state  s   z$ContentStream.isolate_graphics_staterI   c                    s&   | j s
| jr
|   t || d S r\   )r   r  r  r   rO   r  r  r1   rD   rO     s   zContentStream.write_to_streamr\   r[   r   ) r]   r^   r_   __doc__r   r   ra   r   r   rb   r   r`   r   r	   r7   re   r   r
   r   rj   r   r+  r&  rc   r  r  r   r<  setterr@  rO   r  r1   r1   r  rD   r    sj    #
#O 
	r  rH   r9   rP   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r|d usJ t| |S t| S | dd td|d|   d|  d  )Nr$   rQ      /   <r   r/  r   rL      t   f   (   e   s   endobji   nr   )r   r   r   zFile ended unexpectedly.s   0123456789+-.   iz(Invalid Elementary Object starting with z @z: P   )rS   rU   r(   rZ   re   r.   r0   r%   r/   r)   rh   r#   r   rV   IndirectPatternmatchr'   r*   r"   r   r   )rH   r9   rP   rX   r(  r1   r1   rD   rV     sR   








"rV   c                   @   s   e Zd ZdZde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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dS )Fieldz
    A class representing a field dictionary.

    This class is accessed through
    :meth:`get_fields()<pypdf.PdfReader.get_fields>`
    rB   r5   Nc              	   C   s   t |  t t  }|j| _|D ]}z
|| | t|< W q ty(   Y qw t| 	dt
r[tt
| td  }t|trF| }n|d u rMd}ntdt|| td< d S d S )Nry   r  zShould never happen)re   r   r   
attributesr   r8   r(   KeyErrorr<   rq   r	  r   r  rc   decoder:   r,   )r@   rB   field_attributesattrdd_strr1   r1   rD   r     s*   


zField.__init__c                 C      |  tjS )z4Read-only property accessing the type of this field.)rq   r   r  rF   r1   r1   rD   
field_type     zField.field_typec                 C   rW  )z6Read-only property accessing the parent of this field.)rq   r   ParentrF   r1   r1   rD   r     rY  zField.parentr0   c                 C   rW  )z4Read-only property accessing the kids of this field.)rq   r   KidsrF   r1   r1   rD   kids  rY  z
Field.kidsc                 C   rW  )z4Read-only property accessing the name of this field.)rq   r   TrF   r1   r1   rD   name  rY  z
Field.namec                 C   rW  )z>Read-only property accessing the alternate name of this field.)rq   r   TUrF   r1   r1   rD   alternate_name  rY  zField.alternate_namec                 C   rW  )z
        Read-only property accessing the mapping name of this field.

        This name is used by pypdf as a key in the dictionary returned by
        :meth:`get_fields()<pypdf.PdfReader.get_fields>`
        )rq   r   TMrF   r1   r1   rD   mapping_name	     zField.mapping_namec                 C   rW  )z
        Read-only property accessing the field flags, specifying various
        characteristics of the field (see Table 8.70 of the PDF 1.7 reference).
        )rq   r   FfrF   r1   r1   rD   flags  s   zField.flagsc                 C   rW  )zs
        Read-only property accessing the value of this field.

        Format varies based on field type.
        )rq   r   VrF   r1   r1   rD   r        zField.valuec                 C   rW  )z=Read-only property accessing the default value of this field.)rq   r   DVrF   r1   r1   rD   default_value$  rY  zField.default_valuec                 C   rW  )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.
        )rq   r   AArF   r1   r1   rD   additional_actions)  rc  zField.additional_actions)r]   r^   r_   rA  re   r   r   r   r(   rX  r   r\  ra   r^  r`  rb  rb   re  r   r   ri  rk  r1   r1   r1   rD   rO    s.    	rO  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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.

    Args:
        title: Title of this destination.
        page: Reference to the page of this destination. Should
            be an instance of :class:`IndirectObject<pypdf.generic.IndirectObject>`.
        fit: How the destination is displayed.

    Raises:
        PdfReadError: If destination type is invalid.
    Nnodechildstitlepagefitr5   c                 C   s  |j }|j}t|  t|| td< || td< || td< |dkr_t|dk r0|td t|dk r=|td t|dk rJ|td |\| tt	j
< | tt	j< | td	< d S t|d
krgd S |tjkr|\| tt	j
< | tt	j< | tt	j< | tt	j< d S |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 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/Pagero   z/XYZr$   g        r   r-  /Zoomr   zUnknown Destination Type: )fit_typefit_argsre   r   r,   r(   rh   r>   r*   TALEFTTOPTFFIT_RBOTTOMRIGHTFIT_HFIT_BHr:   r)   FIT_VFIT_BVFITFIT_Br"   )r@   ro  rp  rq  typargsr1   r1   rD   r   K  sT   

zDestination.__init__r0   c                    s(   t  d d g fdddD  S )Nrs  ro   c                    s   g | ]
}| v r | qS r1   r1   )rr   r   rF   r1   rD   
<listcomp>  s
    z*Destination.dest_array.<locals>.<listcomp>)/Left/Bottom/Right/Toprt  )r0   rp   rF   r1   rF   rD   
dest_array~  s   
zDestination.dest_arrayrH   rI   c                 C   s   |d ur	t dd |d td}|| |d | j}|| td}|| |d td}|| |d |d	 d S )
NrJ   rK   r   z/DrM   z/Sz/GoTor   r   )r   rN   r(   rO   r  )r@   rH   rI   r   r   value_sr1   r1   rD   rO     s"   







zDestination.write_to_streamc                 C   
   |  dS )z3Read-only property accessing the destination title.rr  rq   rF   r1   r1   rD   ro       
zDestination.titlec                 C   r  )z9Read-only property accessing the destination page number.rs  r  rF   r1   r1   rD   rp    r  zDestination.pagec                 C   r  )z2Read-only property accessing the destination type.ro   r  rF   r1   r1   rD   r    r  zDestination.typc                 C      |  ddS )z-Read-only property accessing the zoom factor.rt  Nr  rF   r1   r1   rD   zoom  rY  zDestination.zoomc                 C   r  )z<Read-only property accessing the left horizontal coordinate.r  Nr  rF   r1   r1   rD   left  rY  zDestination.leftc                 C   r  )z=Read-only property accessing the right horizontal coordinate.r  Nr  rF   r1   r1   rD   right  rY  zDestination.rightc                 C   r  )z9Read-only property accessing the top vertical coordinate.r  Nr  rF   r1   r1   rD   top  rY  zDestination.topc                 C   r  )z<Read-only property accessing the bottom vertical coordinate.r  Nr  rF   r1   r1   rD   bottom  rY  zDestination.bottomc                 C   s"   |  dttdtdtdgS )zHRead-only property accessing the color in (R, G, B) with values 0.0-1.0.z/Cr   )rq   r0   r&   rF   r1   r1   rD   color  s   zDestination.colorc                 C   r  )z_
        Read-only property accessing the font type.

        1=italic, 2=bold, 3=both
        z/Fr   r  rF   r1   r1   rD   font_format  rg  zDestination.font_formatc                 C   r  )z
        Read-only property accessing the outline count.

        positive = expanded
        negative = collapsed
        absolute value = number of visible descendants at all levels
        r   Nr  rF   r1   r1   rD   outline_count  s   	zDestination.outline_count)r5   r0   r\   )%r]   r^   r_   rA  rm  r   re   __annotations__rn  r   r   ra   r   r*   r'   r)   r-   r   r   r  r   rc   rO   ro  rb   rp  r  r  r&   r  r  r  r  r  r   r  r  r1   r1   r1   rD   rl  4  sf   
 
3
rl  r\   )O
__author____author_email__loggingr   ior   typingr   r   r   r   r   r   r	   r
   r   r   r   
_protocolsr   r   _utilsr   r   r   r   r   r   r   r   r   	constantsr   r   r   r   r  r   r   r   rw  r    rz  errorsr!   r"   r#   _baser%   r&   r'   r(   r)   r*   r+   r,   _fitr-   r.   r/   	getLoggerr]   loggerNumberSignsr   rM  r0   re   r   r   r=   r   r	  r  ra   rb   rV   rO  rl  r1   r1   r1   rD   <module>   sZ   4,(


J  b Ys&  
7c