o
    h+                    @   s  d Z dZdZddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZmZmZ dd	lmZ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$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/Z0 ddl(m1Z2 ddl3m4Z4m5Z5m6Z6m7Z7 e8e9Z:dZ;dZ<e=dZ>G dd dZ?G dd de?Z@G dd de?ZAG dd deBe?ZCG dd de?ZDG dd dejEe?ZFG d d! d!eGe?ZHd"ed#ed$ fd%d&ZI	ddd"ed'edeJeeJ eeGeJf f d#ed$ fd(d)ZK	ddd"ed'edeJeeJ eeGeJf f d#ed$ fd*d+ZL	ddd"ed'edeJeeJ eeGeJf f d#ed$ fd,d-ZMG d.d/ d/eNe?ZOG d0d1 d1eJe?ZPG d2d3 d3eJe?ZQG d4d5 d5eRe?ZSG d6d7 d7eSZTG d8d9 d9eSZUG d:d; d;eUZVG d<d= d=eUZWG d>d? d?eVZX	ddd"ed@ed'edeJeeJ eeGeJf f d#ee?eGeJeXf fdAdBZYG dCdD dDeCZZG dEdF dFeTZ[G dGdH dHe
Z\G dIdJ dJeTZ]G dKdL dLe]Z^	dddMeeJeNf d'edeJeeJ eeGeJf f d#eePeOf fdNdOZ_	dddMeeJeNf d'edeJeeJ eeGeJf f d#eePeOf fdPdQZ`dReDdSeJdTeeeaeaeaf  dUebdVebd#eTfdWdXZcdYeJd#eNfdZd[Zdd\eNd#eJfd]d^Zed_eJd#eeaeaeaf fd`daZfG dbdc dcZgdS )ezHImplementation of generic PDF objects (dictionary, number, string, ...).zMathieu Fenniakzbiziqe@mathieu.fenniak.net    N)IntFlag)BytesIO)	AnyCallableDictIterableListOptionalTupleUnioncast   )_pdfdoc_encoding_pdfdoc_encoding_revrev_encoding)WHITESPACES
StreamTypeb_deprecate_no_replacementdeprecate_with_replacementhex_str	hexencodelogger_warningread_non_whitespaceread_until_regexskip_over_commentstr_)CheckboxRadioButtonAttributesFieldDictionaryAttributes)FilterTypes)StreamAttributes)TypArguments)TypFitArguments)STREAM_TRUNCATED_PREMATURELYPdfReadErrorPdfReadWarningPdfStreamErrors   /<[tf(n%s   +-s   [+-]?(\d+)\s+(\d+)\s+R[^a-zA-Z]c                   @   s   e Zd ZU ejZed ed< defddZ	defddZ
ded  fdd	Zded  fd
dZdededeef ddfddZdS )	PdfObject).zhashlib._Hash	hash_funcreturnc                 C   s   d|    S )Nz%s)encodeself r-   V/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/PyPDF2/generic.pyhash_value_data^      zPdfObject.hash_value_datac                 C   s"   d| j j| |   f  S )Nz%s:%s)	__class____name__r(   r/   	hexdigestr*   r+   r-   r-   r.   
hash_valuea   s   zPdfObject.hash_valuec                 C      | S )zResolve indirect references.r-   r+   r-   r-   r.   
get_objectj   s   zPdfObject.get_objectc                 C      t dd |  S )N	getObjectr6   )r   r6   r+   r-   r-   r.   r8   n      
zPdfObject.getObjectstreamencryption_keyNc                 C   s   t N)NotImplementedErrorr,   r:   r;   r-   r-   r.   write_to_streamr      zPdfObject.write_to_stream)r2   
__module____qualname__hashlibsha1r(   r   __annotations__bytesr/   r4   r	   r6   r8   r   r   strr?   r-   r-   r-   r.   r'   Z   s   
 	r'   c                   @   s   e Zd Zdededeef ddfddZededd fddZ	dededeef ddfd	d
Z
defddZededd fddZdS )
NullObjectr:   r;   Nr)   c                 C   s   | d d S )N   null)writer>   r-   r-   r.   r?   y   s   zNullObject.write_to_streamc                 C   s    |  d}|dkrtdt S )N   rI   zCould not read Null object)readr$   rH   )r:   Znulltxtr-   r-   r.   read_from_stream~   s   
zNullObject.read_from_streamc                 C      t dd | || d S NwriteToStreamr?   r   r?   r>   r-   r-   r.   rP         
zNullObject.writeToStreamc                 C   s   dS )NrH   r-   r+   r-   r-   r.   __repr__   s   zNullObject.__repr__c                 C      t dd t| S NreadFromStreamrM   )r   rH   rM   r:   r-   r-   r.   rV         

zNullObject.readFromStream)r2   rA   rB   r   r   rG   rF   r?   staticmethodrM   rP   rS   rV   r-   r-   r-   r.   rH   x   s(    

rH   c                   @   s   e Zd ZdeddfddZdedefddZd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e
dd fddZede
dd fddZdS )BooleanObjectvaluer)   Nc                 C   
   || _ d S r<   r[   r,   r[   r-   r-   r.   __init__      
zBooleanObject.__init___BooleanObject__oc                 C   s.   t |tr| j|jkS t |tr| j|kS dS )NF)
isinstancerZ   r[   bool)r,   ra   r-   r-   r.   __eq__   s
   


zBooleanObject.__eq__c                 C   s   | j rdS dS )NTrueFalser]   r+   r-   r-   r.   rS         zBooleanObject.__repr__r:   r;   c                 C   s"   | j r
|d d S |d d S )N   trues   false)r[   rJ   r>   r-   r-   r.   r?      s   zBooleanObject.write_to_streamc                 C   rN   rO   rQ   r>   r-   r-   r.   rP      rR   zBooleanObject.writeToStreamc                 C   s<   |  d}|dkrtdS |dkr|  d tdS td)NrK   rh   Ts   falsr   FzCould not read Boolean object)rL   rZ   r$   )r:   wordr-   r-   r.   rM      s   

zBooleanObject.read_from_streamc                 C   rT   rU   )r   rZ   rM   rW   r-   r-   r.   rV      rX   zBooleanObject.readFromStream)r2   rA   rB   r   r_   objectrc   rd   rG   rS   r   r   rF   r?   rP   rY   rM   rV   r-   r-   r-   r.   rZ      s,    


rZ   c                   @   s   e Zd Zd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 )ArrayObjectr)   c                 C   s   t | S )zS
        Emulate DictionaryObject.items for a list
        (index, object)
        )	enumerater+   r-   r-   r.   items   s   zArrayObject.itemsr:   r;   Nc                 C   s8   | d | D ]}| d ||| q| d d S )N   [    s    ])rJ   r?   )r,   r:   r;   datar-   r-   r.   r?      s
   

zArrayObject.write_to_streamc                 C   rN   rO   rQ   r>   r-   r-   r.   rP      rR   zArrayObject.writeToStreampdf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   rn   zCould not read arrayT   ])rk   rL   r$   isspaceseekappendread_object)r:   rq   rr   arrtmptokZ	peekaheadr-   r-   r.   rM      s"   



zArrayObject.read_from_streamc                 C      t dd t| |S rU   )r   rk   rM   r:   rq   r-   r-   r.   rV         
zArrayObject.readFromStreamr<   )r2   rA   rB   r   rm   r   r   rG   rF   r?   rP   rY   r   r   r   intrM   rV   r-   r-   r-   r.   rk      sF    
	
rk   c                   @   s   e Zd ZdedededdfddZdee fdd	Zde	fd
dZ
dedefddZded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ededd fddZedededd fddZdS )IndirectObjectidnum
generationrq   r)   Nc                 C   s   || _ || _|| _d S r<   )r   r   rq   )r,   r   r   rq   r-   r-   r.   r_      s   
zIndirectObject.__init__c                 C   s    | j | }|d u rd S | S r<   )rq   r6   )r,   objr-   r-   r.   r6      s   zIndirectObject.get_objectc                 C   s"   d| j d| jdt| j dS )NzIndirectObject(z, ))r   r   idrq   r+   r-   r-   r.   rS     s   "zIndirectObject.__repr__otherc                 C   s6   |d uot |to| j|jko| j|jko| j|ju S r<   )rb   r   r   r   rq   r,   r   r-   r-   r.   rd   	  s   


zIndirectObject.__eq__c                 C   s   |  | S r<   )rd   r   r-   r-   r.   __ne__  r0   zIndirectObject.__ne__r:   r;   c                 C   s"   | t| j d| j d d S )N z R)rJ   r   r   r   r>   r-   r-   r.   r?     s   "zIndirectObject.write_to_streamc                 C   rN   rO   rQ   r>   r-   r-   r.   rP     rR   zIndirectObject.writeToStreamc                 C   s   d}	 |  d}|stt| rn||7 }qd}	 |  d}|s&tt| r.|s-qn||7 }qt| }|dkrFtdt|   tt	|t	||S )N    Tr      Rz0Error reading indirect object reference at byte )
rL   r&   r#   ru   r   r$   r   tellr   r   )r:   rq   r   r{   r   rr-   r-   r.   rM      s4   

	zIndirectObject.read_from_streamc                 C   r|   rU   )r   r   rM   r}   r-   r-   r.   rV   ;  r~   zIndirectObject.readFromStream)r2   rA   rB   r   r   r_   r	   r'   r6   rG   rS   rc   rd   r   r   r   rF   r?   rP   rY   rM   rV   r-   r-   r-   r.   r      s<    	

r   c                   @   s   e Zd Z	ddeeef dee dd fddZdefdd	Zd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dS )FloatObject0Nr[   contextr)   c                 C   sv   zt j| t||W S  ty:   zt j| t|W  Y S  t jy9   td| t t j| d Y  Y S w w )NzInvalid FloatObject r   )	decimalDecimal__new__r   	ExceptionrG   InvalidOperationr   r2   )clsr[   r   r-   r-   r.   r   D  s   zFloatObject.__new__c                 C   sX   | |   krt| tdS | d}|r*|d dkr*|d d }|r*|d dks|S )Nr   z.5frs   r   )to_integralrG   quantizer   r   )r,   or-   r-   r.   rS   R  s   zFloatObject.__repr__c                 C      t t| dS Nutf8)floatreprr*   r+   r-   r-   r.   
as_numeric]     zFloatObject.as_numericr:   r;   c                 C      | t| d d S r   rJ   r   r*   r>   r-   r-   r.   r?   `     zFloatObject.write_to_streamc                 C   rN   rO   rQ   r>   r-   r-   r.   rP   e  rR   zFloatObject.writeToStream)r   N)r2   rA   rB   r   rG   r   r	   r   rS   r   r   r   rF   r?   rP   r-   r-   r-   r.   r   C  s2    


r   c                   @   s   e Zd ZedZdedd fddZd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e
ded ef fddZede
ded ef fddZd
S )NumberObjects	   [^+-.0-9]r[   r)   c                 C   s6   t |}zt | |W S  ty   t | d Y S w Nr   )r   r   OverflowError)r   r[   valr-   r-   r.   r   o  s   zNumberObject.__new__c                 C   r   r   )r   r   r*   r+   r-   r-   r.   r   v  r   zNumberObject.as_numericr:   r;   Nc                 C   r   r   r   r>   r-   r-   r.   r?   y  r   zNumberObject.write_to_streamc                 C   rN   rO   rQ   r>   r-   r-   r.   rP   ~  rR   zNumberObject.writeToStreamc                 C   s*   t | tj}|ddkrt|S t|S )N   .rs   )r   r   NumberPatternfindr   )r:   numr-   r-   r.   rM     s   zNumberObject.read_from_streamc                 C   rT   rU   )r   r   rM   rW   r-   r-   r.   rV        

zNumberObject.readFromStream)r2   rA   rB   recompiler   r   r   r   r   r   r   rG   rF   r?   rP   rY   r   rM   rV   r-   r-   r-   r.   r   l  s4    



r   r:   r)   )TextStringObjectByteStringObjectc                 C   s   t ddd t| S )NreadHexStringFromStreamread_hex_string_from_stream4.0.0)r   r   rW   r-   r-   r.   r     s   r   rr   c                 C   s   |  d d}d}	 t| }|stt|dkrn||7 }t|dkr/|tt|dd7 }d}q
t|dkr:|d	7 }t|dkrJ|tt|dd7 }tt||S )
Nr    r   T   >      base   0)	rL   r   r&   r#   lenchrr   create_string_objectr   )r:   rr   txtxr{   r-   r-   r.   r     s&   

r   c                 C      t ddd t| |S )NreadStringFromStreamread_string_from_streamr   )r   r   )r:   rr   r-   r-   r.   r     s   
r   c           	   	   C   s  |  d}d}d}	 |  d}|stt|dkr|d7 }n|dkr,|d8 }|dkr+nn|dkr|  d}i dd	d
ddddddddddddddddddddddddddddddddddd}z|| }W nP ty   | rtd D ]}|  d}| r||7 }q ttt|d!d"}n#|d#v r|  d}|d#vr| 	d$d d}nd%|
d& }t|t Y nw ||7 }q
t||S )'Nr   r   T   (   )r      \   n   
   r      t   	   b      f      cs   \c   /ro      %   <r   rn   rt      #   _   &   $)r   r   r   r      r   s   
rs   zUnexpected escaped string: r   )rL   r&   r#   KeyErrorisdigitranger   r   r   rv   decoder   r2   r   )	r:   rr   r{   Zparensr   Zescape_dict_Zntokmsgr-   r-   r.   r     s   



	





@r   c                   @   sb   e Zd ZdZed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dS )r   a=  
    Represents a string object where the text encoding could not be determined.
    This occurs quite often, as the PDF spec doesn't provide an alternate way to
    represent strings -- for example, the encryption data stored in files (like
    /O) is clearly not text, but is still stored in a "String" object.
    r)   c                 C   r5   )z7For compatibility with TextStringObject.original_bytes.r-   r+   r-   r-   r.   original_bytes  r@   zByteStringObject.original_bytesr:   r;   Nc                 C   sD   | }|rddl m} |||}|d |t| |d d S )Nr   RC4_encryptr   r   )	_securityr   rJ   r   )r,   r:   r;   bytearrr   r-   r-   r.   r?     s   

z ByteStringObject.write_to_streamc                 C   rN   rO   rQ   r>   r-   r-   r.   rP   !  rR   zByteStringObject.writeToStream)r2   rA   rB   __doc__propertyrF   r   r   r   rG   r?   rP   r-   r-   r-   r.   r     s$    
r   c                   @   sx   e Zd ZdZdZdZedefddZd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d
S )r   z
    Represents a string object that has been decoded into a real unicode string.
    If read from a PDF document, this string appeared to match the
    PDFDocEncoding, or contained a UTF-16BE BOM mark to cause UTF-16 decoding to
    occur.
    Fr)   c                 C      |   S )a-  
        It is occasionally possible that a text string object gets created where
        a byte string object was expected due to the autodetection mechanism --
        if that occurs, this "original_bytes" property can be used to
        back-calculate what the original encoded bytes were.
        )get_original_bytesr+   r-   r-   r.   r   3  s   zTextStringObject.original_bytesc                 C   s,   | j rtj| d S | jrt| S td)Nutf-16bez#no information about original bytes)autodetect_utf16codecsBOM_UTF16_BEr*   autodetect_pdfdocencodingencode_pdfdocencodingr   r+   r-   r-   r.   r   =  s
   z#TextStringObject.get_original_bytesr:   r;   Nc                 C   s   zt | }W n ty   tj| d }Y nw |r1ddlm} |||}t|}||d  d S |	d |D ]}t
| sN|dkrN|	td|  q8|	tt
| q8|	d d S )Nr   r   r   r   ro   z\%03or   )r   UnicodeEncodeErrorr   r   r*   r   r   r   r?   rJ   r   isalnumr   )r,   r:   r;   r   r   r   cr-   r-   r.   r?   J  s    

z TextStringObject.write_to_streamc                 C   rN   rO   rQ   r>   r-   r-   r.   rP   g  rR   zTextStringObject.writeToStream)r2   rA   rB   r   r   r   r   rF   r   r   r   r   rG   r?   rP   r-   r-   r-   r.   r   (  s*    	
r   c                   @   s   e Zd ZedZ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ededd fddZedededd fddZdS )
NameObjects   \s+|[\(\)<>\[\]{}/%]r   r:   r;   Nr)   c                 C   s   | t|  d S r<   )rJ   r   r>   r-   r-   r.   r?   r  s   zNameObject.write_to_streamc                 C   rN   rO   rQ   r>   r-   r-   r.   rP   w  rR   zNameObject.writeToStreamrq   c              
   C   s   |  d}|tjkrtd|t| tjdd7 }zz|d}W n ttfy0   |d}Y nw t|W S  ttfyZ } z|j	sQt
dt t|W  Y d }~S td|d }~ww )Nr   zname read errorT)Z
ignore_eofzutf-8gbkz Illegal character in Name Object)rL   r   surfixr$   r   delimiter_patternr   r   UnicodeDecodeErrorstrictr   r2   )r:   rq   namereter-   r-   r.   rM   }  s$   




zNameObject.read_from_streamc                 C   r|   rU   )r   r   rM   r}   r-   r-   r.   rV     r~   zNameObject.readFromStream)r2   rA   rB   r   r   r   r   r   r   rG   rF   r?   rP   rY   r   rM   rV   r-   r-   r-   r.   r   n  s6    


r   c                   @   s4  e Z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 ) DictionaryObjectkeyr)   c                 C   s   t | |S r<   )dict__getitem__r,   r   r-   r-   r.   raw_get  r0   zDictionaryObject.raw_getr[   c                 C   2   t |ts	tdt |tstdt| ||S Nzkey must be PdfObjectzvalue must be PdfObject)rb   r'   
ValueErrorr   __setitem__r,   r   r[   r-   r-   r.   r    
   

zDictionaryObject.__setitem__Nc                 C   r   r  )rb   r'   r  r   
setdefaultr  r-   r-   r.   r    r  zDictionaryObject.setdefaultc                 C   s   t | | S r<   )r   r   r6   r   r-   r-   r.   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)Zxmpr  getr6   rb   r   )r,   r  metadatar-   r-   r.   xmp_metadata  s   
zDictionaryObject.xmp_metadatac                 C      t dd | jS )W
        .. deprecated:: 1.28.3

            Use :meth:`xmp_metadata` instead.
        getXmpMetadatar
  r   r
  r+   r-   r-   r.   r    s   
zDictionaryObject.getXmpMetadatac                 C   r  )r  xmpMetadatar
  r  r+   r-   r-   r.   r       
zDictionaryObject.xmpMetadatar:   r;   c                 C   sZ   | d t|  D ]\}}||| | d ||| | d q| d d S )N   <<
ro   r      >>)rJ   listrm   r?   r,   r:   r;   r   r[   r-   r-   r.   r?     s   

z DictionaryObject.write_to_streamc                 C   rN   rO   rQ   r>   r-   r-   r.   rP     rR   zDictionaryObject.writeToStreamrq   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 nC| 
dd t| |}t	| }| 
dd t| ||}||s|||< ndt|   d| }	|d ur|jrt|	t|	t q8|  }
t	| }|dkro| ddkro| d}|dkr| d}|dks|dvrtd|dkr| ddkr| 
dd tj|vrtd|tj }t|tr|  }||}| 
|d  |  }| ||d!< t	| }| d"}|| d#krn|  }
| 
d$d | d%}|d#kr@|d! d d |d!< n5|jsV| 
|d  || ||d!< |  }
n| 
|
d  td&t|   d'|d(|d)n| 
|
d  d!|v rt|S t }|| |S )*Npp1rem_gensrq   r)   c                    s^   |j |d  }|D ]}||| kr| || k r|| }q	t|dkr$|S  | ||dd  |S )Nr   r   )xrefr   )r  r  r  rq   lr   get_next_obj_posr-   r.   r    s   z;DictionaryObject.read_from_stream.<locals>.get_next_obj_posr:   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 .	   )r   r  r  rL   r   r$   rv   )r:   rq   Zeoncurrrwr  r  r-   r.   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    r   rs   r   r   z+Multiple definitions in dictionary at byte z	 for key    s   s   treamro   )r   r   z)Stream data must be followed by a newliner   r   zStream length not definedr   __streamdata__r   r  ir  z7Unable to find 'endstream' marker after stream at byte z (nd='z', end='z').)r   r   r   r   rF   rL   r$   r   r   r   rv   r   r&   r#   rx   r  r   warningswarnr%   SALENGTHrb   r   r6   StreamObjectinitialize_from_dictionaryr   update)r:   rq   rr   r!  rz   rp   r{   r   r[   r   posseollengthtZpstartr   Zndstreamendretvalr-   r  r.   rM     s   





 












z!DictionaryObject.read_from_streamc                 C   r|   rU   )r   r   rM   r}   r-   r-   r.   rV   l  r~   zDictionaryObject.readFromStreamr<   )r2   rA   rB   r   r   r  r	   r  r'   r   r   r
  r  r  r   r   rG   rF   r?   rP   rY   r   r   r   rM   rV   r-   r-   r-   r.   r     sZ    
	

r   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dfddZdeddfddZdddZdddZdS )
TreeObjectr)   Nc                 C   s   t |  d S r<   )r   r_   r+   r-   r-   r.   r_   u  rg   zTreeObject.__init__c                 C   s   t ddd |  S )NhasChildrenhas_childrenr   )r   r7  r+   r-   r-   r.   r6  x  s   zTreeObject.hasChildrenc                 C   s   d| v S )N/Firstr-   r+   r-   r-   r.   r7  |     zTreeObject.has_childrenc                 C   r   r<   )childrenr+   r-   r-   r.   __iter__  r9  zTreeObject.__iter__c                 c   s8    |   sd S | d }	 |V  || d krd S |d }q)Nr8  T/Last/Next)r7  r,   childr-   r-   r.   r:    s   zTreeObject.childrenr?  rq   c                 C   rN   )NaddChild	add_child)r   rA  )r,   r?  rq   r-   r-   r.   r@    s   
zTreeObject.addChildc                 C   s   |  }||}t|tsJ d| vr%|| td< td| td< d }ntt| d }|| td< t| td d | td< |rZ||}t|tsNJ ||td< ||td< || }t|tsfJ ||td< d S )	Nr8  r   /Countr<  r   /Prevr=  /Parent)r6   Zget_referencerb   r   r   r   r   r   )r,   r?  rq   	child_objprevprev_refZ
parent_refr-   r-   r.   rA    s(   


zTreeObject.add_childc                 C      t dd | | d S )NremoveChildremove_child)r   rJ  r>  r-   r-   r.   rI       
zTreeObject.removeChildc                 C   s  |  }td|vrtd|td | krtdd}d }d }| td }|  }| td }|  }	|d ur||kr|d u rtd|v rf|td }
|
  }|td= |
| td< | td	  d
8  < nb| td	 d
kspJ | td	= | td= td| v r| td= nBtd|v r|td }
|
  }||td< |
|td< | td	  d
8  < n||	ksJ |td= || td< | td	  d
8  < d}n|}|}td|v r|td }|  }nd }d }|d us8|std|td= td|v r|td= td|v r|td= d S d S )NrD  z/Removed child does not appear to be a tree itemz*Removed child is not a member of this treeFr8  r<  r=  rC  rB  r   Tz"Removal couldn't find item in tree)r6   r   r  )r,   r?  rE  foundrG  rF  Zcur_refcurZlast_reflastZnext_refZnext_objr-   r-   r.   rJ    sn   





,

zTreeObject.remove_childc                 C   s   t ddd |   d S )N	emptyTree
empty_treer   )r   rP  r+   r-   r-   r.   rO    s   zTreeObject.emptyTreec                 C   s   | D ]!}|  }|td= td|v r|td= td|v r#|td= qtd| v r/| td= td| v r:| td= td| v rG| td= d S d S )NrD  r=  rC  rB  r8  r<  )r6   r   )r,   r?  rE  r-   r-   r.   rP    s   




zTreeObject.empty_treer)   N)r2   rA   rB   r_   rc   r6  r7  r   r;  r	   r:  r@  rA  rI  rJ  rO  rP  r-   r-   r-   r.   r5  t  s    

Dr5  c                       s   e Zd Zd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+  r)   Nc                 C   s   d | _ d | _d S r<   )_StreamObject__datadecoded_selfr+   r-   r-   r.   r_     s   
zStreamObject.__init__c                    s   t   }|t| j7 }|S r<   )superr/   r   _datar,   rp   r1   r-   r.   r/     s   
zStreamObject.hash_value_dataDecodedStreamObjectc                 C   r  NdecodedSelfrS  r   rS  r+   r-   r-   r.   rZ       
zStreamObject.decodedSelfr[   c                 C      t dd || _d S rY  r[  r^   r-   r-   r.   rZ    rX   c                 C      | j S r<   rR  r+   r-   r-   r.   rU    s   zStreamObject._datac                 C   r\   r<   r_  r^   r-   r-   r.   rU  "  s   
r:   r;   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   r   s
   
endstream)r   r   rU  r   r)  r*  r   r?   rJ   r   r   )r,   r:   r;   rp   r   r-   r-   r.   r?   &  s   


zStreamObject.write_to_streamrp   )EncodedStreamObjectrX  c                 C   s
   t | S r<   )r+  r,  )rp   r-   r-   r.   initializeFromDictionary5  s   
z%StreamObject.initializeFromDictionaryc                 C   s>   t j| v r	t }nt }| d |_| d= | t j= ||  |S )Nr&  )r)  FILTERr`  rX  rU  r*  r-  )rp   r4  r-   r-   r.   r,  ;  s   


z'StreamObject.initialize_from_dictionaryr`  c                 C   r7   )NflateEncodeflate_encode)r   rd  r+   r-   r-   r.   rc  J  r9   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)filtersre  r)  rb  rb   rk   insertr   FTZFLATE_DECODErw   r`  r*   rU  )r,   re  fZnewfr4  r-   r-   r.   rd  N  s   



zStreamObject.flate_encoderQ  )r[   rX  r)   N)r)   r`  )r2   rA   rB   r_   rF   r/   r   r	   rZ  setterr   rU  r   r   rG   r?   rY   r   ra  r,  rc  rd  __classcell__r-   r-   rW  r.   r+  
  s@    




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 )rX  r)   c                 C   r^  r<   rU  r+   r-   r-   r.   get_datac  s   zDecodedStreamObject.get_datarp   c                 C   r\   r<   rl  rV  r-   r-   r.   set_dataf  r`   zDecodedStreamObject.set_datac                 C   r  NgetDatarm  )r   rU  r+   r-   r-   r.   rp  i     
zDecodedStreamObject.getDataNc                 C   rH  NsetDatarn  r   rn  rV  r-   r-   r.   rs  m  rK  zDecodedStreamObject.setData)r2   rA   rB   r   rm  rn  rp  rs  r-   r-   r-   r.   rX  b  s
    rX  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`  r)   Nc                 C   s
   d | _ d S r<   )rS  r+   r-   r-   r.   r_   s  r`   zEncodedStreamObject.__init__rX  c                 C   r  rY  r[  r+   r-   r-   r.   rZ  v  r\  zEncodedStreamObject.decodedSelfr[   c                 C   r]  rY  r[  r^   r-   r-   r.   rZ  {  rX   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)rf  ru  rS  rm  rX  rU  r  rm   r)  r*  rb  ZDECODE_PARMS)r,   ru  decodedr   r[   r-   r-   r.   rm    s   


zEncodedStreamObject.get_datac                 C   r7   ro  )r   rm  r+   r-   r-   r.   rp    r9   zEncodedStreamObject.getDatarp   c                 C   s   t d)Nz7Creating EncodedStreamObject is not currently supported)r$   rV  r-   r-   r.   rn    r9  zEncodedStreamObject.set_datac                 C   s   t dd | |S rr  rt  rV  r-   r-   r.   rs       

zEncodedStreamObject.setDatarQ  )r2   rA   rB   r_   r   r	   rZ  rj  rX  r   rG   rF   rm  rp  r   rn  rs  r-   r-   r-   r.   r`  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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 )ContentStreamNr:   rq   rr   r)   c           	      C   s   || _ g | _| }t|tr%d}|D ]}|t|  7 }qt|}n| }|d us/J t|}t|}|| _| 	| d S )Nr   )
rq   
operationsr6   rb   rk   r   rm  r   rr   $_ContentStream__parse_content_stream)	r,   r:   rq   rr   rp   r/  Zstream_bytesZstream_dataZstream_data_bytesr-   r-   r.   r_     s   

zContentStream.__init__c                 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   )rv   r   isalphar   r   r   _read_inline_imagery  rw   rL   rx   rr   )r,   r:   operandspeekoperatoriir-   r-   r.   Z__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[|	| nc|	|d|	  ||	t
| d |d}|d}
|
dkr|d}||
 }d}|tv rd}||7 }|d}|tv s|dkr|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   Q)settingsrp   )r   r   rv   rx   rq   rL   r   r$   r   rJ   r   r   getvalue)r,   r:   r  r{   r   r[   rz   rp   buflocZtok2Ztok3infoZhas_q_whitespacer-   r-   r.   r    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 )Nr~  r}  r  r   s   ID rp   s   EIro   r   )r   ry  rJ   r?   r  r   )r,   newdatar  r  Zdicttextopr-   r-   r.   rU    s    

zContentStream._datar[   c                 C   s   |  tt| d S r<   )rz  r   r   r^   r-   r-   r.   rU  )  s   r<   )r2   rA   rB   r   r   rG   r   r   r   r_   r   rz  r  r   rF   rU  rj  r-   r-   r-   r.   rx    s"    
< rx  rq   c                 C   s\  |  d}| dd t|}|dkrt| |S |dkr9|  d}| dd |dkr4t| ||S t| |S |dkrDt| ||S |dksL|dkrQt	| S |d	krZt
| |S |d
krct| S |dkr|dvr~|  d}t|dkrztd|dvskt| }| dd t| ||S |  d}| t| d t|d urt| |S t| S )Nr   rs   r   r   r  r"  r  rK   r%        r  zFile ended unexpectedly.   )rL   rv   ObjectPrefixr   r   rM   r   r   rk   rZ   r   rH   r   r&   r   rx   IndirectPatternmatchr   r   )r:   rq   rr   r{   idxr  r-   r-   r.   rx   .  sB   









rx   c                   @   sF  e Zd ZdZdeeeeef ddfddZdedee	e
f fdd	Zd
e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ede	fddZede	fddZede	fddZede	fddZde	fddZde	fddZde	fddZde	fd d!Zde	fd"d#Zde	fd$d%Zde	fd&d'Zde	fd(d)Zedeejejf fd*d+Zej de!e ddfd,d+Zedeejejf fd-d.Z"e"j de!e ddfd/d.Z"edeejejf fd0d1Z#e#j de!e ddfd2d1Z#edeejejf fd3d4Z$e$j de!e ddfd5d4Z$deejejf fd6d7Z%deejejf fd8d9Z&deejejf fd:d;Z'deejejf fd<d=Z(deeef ddfd>d?Z)deeef ddfd@dAZ*deeef ddfdBdCZ+deeef ddfdDdEZ,edejfdFdGZ-dejfdHdIZ.edejfdJdKZ/dejfdLdMZ0edeejejf fdNdOZ1e1j deejejf ddfdPdOZ1edeejejf fdQdRZ2e2j deejejf ddfdSdRZ2edeejejf fdTdUZ3e3j deejejf ddfdVdUZ3edeejejf fdWdXZ4e4j deejejf ddfdYdXZ4dS )ZRectangleObjecta  
    This class is used to represent *page boxes* in PyPDF2. These boxes include:
        * :attr:`artbox <PyPDF2._page.PageObject.artbox>`
        * :attr:`bleedbox <PyPDF2._page.PageObject.bleedbox>`
        * :attr:`cropbox <PyPDF2._page.PageObject.cropbox>`
        * :attr:`mediabox <PyPDF2._page.PageObject.mediabox>`
        * :attr:`trimbox <PyPDF2._page.PageObject.trimbox>`
    ry   r)   Nc                    s.   t |dksJ t  fdd|D  d S )NrK   c                    s   g | ]}  |qS r-   _ensure_is_number.0r   r+   r-   r.   
<listcomp>l  s    z,RectangleObject.__init__.<locals>.<listcomp>)r   rk   r_   )r,   ry   r-   r+   r.   r_   h  s   zRectangleObject.__init__r[   c                 C   s   t |ttfst|}|S r<   )rb   r   r   r^   r-   r-   r.   r  n  s   z!RectangleObject._ensure_is_numbersxsyc                 C   s8   t t| j| t| j| t| j| t| j| fS r<   )r  r   leftbottomrighttop)r,   r  r  r-   r-   r.   scales  s   zRectangleObject.scalec                 C   s   t d | |S )NensureIsNumber)r   r  r^   r-   r-   r.   r  }  s   
zRectangleObject.ensureIsNumberc                 C   s   dt t|  dS )NzRectangleObject(r   )r   r  r+   r-   r-   r.   rS     s   zRectangleObject.__repr__c                 C      | d S r   r-   r+   r-   r-   r.   r       zRectangleObject.leftc                 C   r  )Nr   r-   r+   r-   r-   r.   r    r  zRectangleObject.bottomc                 C   r  )Nr   r-   r+   r-   r-   r.   r    r  zRectangleObject.rightc                 C   r  )Nr  r-   r+   r-   r-   r.   r    r  zRectangleObject.topc                 C   r  )NgetLowerLeft_xr  r   r  r+   r-   r-   r.   r    rq  zRectangleObject.getLowerLeft_xc                 C   r  )NgetLowerLeft_yr  r   r  r+   r-   r-   r.   r    rq  zRectangleObject.getLowerLeft_yc                 C   r  )NgetUpperRight_xr  r   r  r+   r-   r-   r.   r    rq  zRectangleObject.getUpperRight_xc                 C   r  )NgetUpperRight_yr  r   r  r+   r-   r-   r.   r    rq  zRectangleObject.getUpperRight_yc                 C   r  )NgetUpperLeft_xr  r  r+   r-   r-   r.   r    rq  zRectangleObject.getUpperLeft_xc                 C   r  )NgetUpperLeft_yr  r  r+   r-   r-   r.   r    rq  zRectangleObject.getUpperLeft_yc                 C   r  )NgetLowerRight_xr  r  r+   r-   r-   r.   r    rq  zRectangleObject.getLowerRight_xc                 C   r  )NgetLowerRight_yr  r  r+   r-   r-   r.   r    rq  zRectangleObject.getLowerRight_yc                 C      | j | jfS )zj
        Property to read and modify the lower left coordinate of this box
        in (x,y) form.
        )r  r  r+   r-   r-   r.   
lower_left     zRectangleObject.lower_leftc                    "    fdd|D \ d<  d< d S )Nc                 3       | ]}  |V  qd S r<   r  r  r+   r-   r.   	<genexpr>      z-RectangleObject.lower_left.<locals>.<genexpr>r   r   r-   r^   r-   r+   r.   r       "c                 C   r  )zk
        Property to read and modify the lower right coordinate of this box
        in (x,y) form.
        )r  r  r+   r-   r-   r.   lower_right  r  zRectangleObject.lower_rightc                    r  )Nc                 3   r  r<   r  r  r+   r-   r.   r    r  z.RectangleObject.lower_right.<locals>.<genexpr>r   r   r-   r^   r-   r+   r.   r    r  c                 C   r  )zj
        Property to read and modify the upper left coordinate of this box
        in (x,y) form.
        )r  r  r+   r-   r-   r.   
upper_left  r  zRectangleObject.upper_leftc                    r  )Nc                 3   r  r<   r  r  r+   r-   r.   r    r  z-RectangleObject.upper_left.<locals>.<genexpr>r   r  r-   r^   r-   r+   r.   r    r  c                 C   r  )zk
        Property to read and modify the upper right coordinate of this box
        in (x,y) form.
        )r  r  r+   r-   r-   r.   upper_right  r  zRectangleObject.upper_rightc                    r  )Nc                 3   r  r<   r  r  r+   r-   r.   r    r  z.RectangleObject.upper_right.<locals>.<genexpr>r   r  r-   r^   r-   r+   r.   r    r  c                 C   r  )NgetLowerLeftr  r   r  r+   r-   r-   r.   r       
zRectangleObject.getLowerLeftc                 C   r  )NgetLowerRightr  r   r  r+   r-   r-   r.   r    r  zRectangleObject.getLowerRightc                 C   r  )NgetUpperLeftr  r   r  r+   r-   r-   r.   r    r  zRectangleObject.getUpperLeftc                 C   r  )NgetUpperRightr  r   r  r+   r-   r-   r.   r    r  zRectangleObject.getUpperRightc                 C   r]  )NsetLowerLeftr  r  r^   r-   r-   r.   r    rw  zRectangleObject.setLowerLeftc                    ,   t dd  fdd|D \ d<  d< d S )NsetLowerRightr  c                 3   r  r<   r  r  r+   r-   r.   r    r  z0RectangleObject.setLowerRight.<locals>.<genexpr>r   r   r   r^   r-   r+   r.   r       
"zRectangleObject.setLowerRightc                    r  )NsetUpperLeftr  c                 3   r  r<   r  r  r+   r-   r.   r    r  z/RectangleObject.setUpperLeft.<locals>.<genexpr>r   r  r  r^   r-   r+   r.   r    r  zRectangleObject.setUpperLeftc                    r  )NsetUpperRightr  c                 3   r  r<   r  r  r+   r-   r.   r    r  z0RectangleObject.setUpperRight.<locals>.<genexpr>r   r  r  r^   r-   r+   r.   r  
  r  zRectangleObject.setUpperRightc                 C      | j | j S r<   )r  r  r+   r-   r-   r.   width     zRectangleObject.widthc                 C   r  )NgetWidthr  )r   r  r+   r-   r-   r.   r    rq  zRectangleObject.getWidthc                 C   r  r<   )r  r  r+   r-   r-   r.   height  r  zRectangleObject.heightc                 C   r  )N	getHeightr  )r   r  r+   r-   r-   r.   r    rq  zRectangleObject.getHeightc                 C   r  N	lowerLeftr  r  r+   r-   r-   r.   r    r\  zRectangleObject.lowerLeftc                 C   r]  r  r  r^   r-   r-   r.   r  #  r   c                 C   r  N
lowerRightr  r  r+   r-   r-   r.   r  *  r\  zRectangleObject.lowerRightc                 C   r]  r  r  r^   r-   r-   r.   r  /  r   c                 C   r  N	upperLeftr  r  r+   r-   r-   r.   r  6  r\  zRectangleObject.upperLeftc                 C   r]  r  r  r^   r-   r-   r.   r  ;  r   c                 C   r  N
upperRightr  r  r+   r-   r-   r.   r  B  r\  zRectangleObject.upperRightc                 C   r]  r  r  r^   r-   r-   r.   r  G  r   )5r2   rA   rB   r   r
   r   r_   r   r   r   r   r  r  r  rG   rS   r   r  r  r  r  r  r  r  r  r  r  r  r  r   r   r  rj  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r-   r-   r-   r.   r  ^  s    	






r  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	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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>`
    rp   r)   Nc              	   C   sN   t |  t t  }|D ]}z
|| | t|< W q ty$   Y qw d S r<   )r   r_   r   
attributesr   r   r   )r,   rp   Zfield_attributesattrr-   r-   r.   r_   W  s   
zField.__init__c                 C      |  tjS )z4Read-only property accessing the type of this field.)r  r   rh  r+   r-   r-   r.   
field_typed     zField.field_typec                 C   r  )zX
        .. deprecated:: 1.28.3

            Use :py:attr:`field_type` instead.
        	fieldTyper  )r   r  r+   r-   r-   r.   r  i  r  zField.fieldTypec                 C   r  )z6Read-only property accessing the parent of this field.)r  r   ZParentr+   r-   r-   r.   parents  r  zField.parentc                 C   r  )z4Read-only property accessing the kids of this field.)r  r   ZKidsr+   r-   r-   r.   kidsx  r  z
Field.kidsc                 C   r  )z4Read-only property accessing the name of this field.)r  r   Tr+   r-   r-   r.   r   }  r  z
Field.namec                 C   r  )z>Read-only property accessing the alternate name of this field.)r  r   ZTUr+   r-   r-   r.   alternate_name  r  zField.alternate_namec                 C   r  )z\
        .. deprecated:: 1.28.3

            Use :py:attr:`alternate_name` instead.
        altNamer  )r   r  r+   r-   r-   r.   r    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   ZTMr+   r-   r-   r.   mapping_name     zField.mapping_namec                 C   r  )zZ
        .. deprecated:: 1.28.3

            Use :py:attr:`mapping_name` instead.
        mappingNamer  )r   r  r+   r-   r-   r.   r    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   ZFfr+   r-   r-   r.   flags  r  zField.flagsc                 C   r  )zr
        Read-only property accessing the value of this field. Format
        varies based on field type.
        )r  r   Vr+   r-   r-   r.   r[     r  zField.valuec                 C   r  )z=Read-only property accessing the default value of this field.)r  r   ZDVr+   r-   r-   r.   default_value  r  zField.default_valuec                 C   r  )z[
        .. deprecated:: 1.28.3

            Use :py:attr:`default_value` instead.
        defaultValuer  )r   r  r+   r-   r-   r.   r    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   ZAAr+   r-   r-   r.   additional_actions  r  zField.additional_actionsc                 C   r  )z`
        .. deprecated:: 1.28.3

            Use :py:attr:`additional_actions` instead.
        additionalActionsr  )r   r  r+   r-   r-   r.   r    r  zField.additionalActions)r2   rA   rB   r   r   rG   r   r_   r   r	   r   r  r  r   r  rk   r  r   r  r  r  r  r   r  r[   r  r  r  r  r-   r-   r-   r.   r  O  sB    				r  c                   @   s   e Zd ZdZdZdZdS )OutlineFontFlagzK
    A class used as an enumerable flag for formatting an outline font
    r   r   N)r2   rA   rB   r   italicboldr-   r-   r-   r.   r    s    r  c                
   @   st  e Zd ZdZdedeeeee	f deeef de
ddf
dd	Zedefd
dZdef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e 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 str typ: How the destination is displayed.
    :param args: Additional arguments may be necessary depending on the type.
    :raises PdfReadError: If destination type is invalid.

    .. list-table:: Valid ``typ`` arguments (see PDF spec for details)
       :widths: 50 50

       * - /Fit
         - No additional arguments
       * - /XYZ
         - [left] [top] [zoomFactor]
       * - /FitH
         - [top]
       * - /FitV
         - [left]
       * - /FitR
         - [left] [bottom] [right] [top]
       * - /FitB
         - No additional arguments
       * - /FitBH
         - [top]
       * - /FitBV
         - [left]
    titlepagetypargsr)   Nc                 G   s\  t |  || td< || td< || td< |dkr0|\| ttj< | ttj< | td< d S |tjkrQ|\| ttj< | ttj< | ttj	< | ttj< d S |tj
tjfv rwz|\| ttj< W d S  tyv   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: )r   r_   r   TAZLEFTZTOPTFZFIT_RZBOTTOMZRIGHTZFIT_HZFIT_BHr   rH   ZFIT_VZFIT_BVZFITZFIT_Br$   )r,   r  r  r  r  r-   r-   r.   r_     s@   

zDestination.__init__c                    s(   t  d d g fdddD  S )Nr  r  c                    s   g | ]
}| v r | qS r-   r-   r  r+   r-   r.   r  .  
    z*Destination.dest_array.<locals>.<listcomp>)/Left/Bottom/Right/Topr  )rk   r   r+   r-   r+   r.   
dest_array*  s   
zDestination.dest_arrayc                 C   r  )zX
        .. deprecated:: 1.28.3

            Use :py:attr:`dest_array` instead.
        getDestArrayr  )r   r  r+   r-   r-   r.   r  5  s   
zDestination.getDestArrayr:   r;   c                 C   s   | d td}||| | d | j}||| td}||| | d td}||| | d | d d S )Nr  z/Dro   z/Sz/GoTor   r  )rJ   r   r?   r  )r,   r:   r;   r   r[   Zvalue_sr-   r-   r.   r?   >  s   



zDestination.write_to_streamc                 C   
   |  dS )z3Read-only property accessing the destination title.r  r  r+   r-   r-   r.   r  Q     
zDestination.titlec                 C   r  )z9Read-only property accessing the destination page number.r  r	  r+   r-   r-   r.   r  V  r
  zDestination.pagec                 C   r  )z2Read-only property accessing the destination type.r  r	  r+   r-   r-   r.   r  [  r
  zDestination.typc                 C      |  ddS )z-Read-only property accessing the zoom factor.r  Nr	  r+   r-   r-   r.   zoom`  r  zDestination.zoomc                 C   r  )z<Read-only property accessing the left horizontal coordinate.r  Nr	  r+   r-   r-   r.   r  e  r  zDestination.leftc                 C   r  )z=Read-only property accessing the right horizontal coordinate.r  Nr	  r+   r-   r-   r.   r  j  r  zDestination.rightc                 C   r  )z9Read-only property accessing the top vertical coordinate.r  Nr	  r+   r-   r-   r.   r  o  r  zDestination.topc                 C   r  )z<Read-only property accessing the bottom vertical coordinate.r  Nr	  r+   r-   r-   r.   r  t  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.0/Cr   )r  rk   r   r+   r-   r-   r.   colory  s   zDestination.colorc                 C   r  )zDRead-only property accessing the font type. 1=italic, 2=bold, 3=both/Fr   r	  r+   r-   r-   r.   font_format  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
        rB  Nr	  r+   r-   r-   r.   outline_count  s   zDestination.outline_count)"r2   rA   rB   r   rG   r   r   r   rH   r   r   r_   r   rk   r  r  r   rF   r?   r	   r  r   r  r  r  r   r  r  r  r  r  r  r  r  r-   r-   r-   r.   r    sZ     

)
	
r  c                   @   s,   e Zd Zdededeef ddfddZdS )Bookmarkr:   r;   Nr)   c                    s   | d  fdddD D ]}||| | d  |}||| | d qtd}||| | d  j}||| | d | d d S )	Nr  c                    s   g | ]
}| v rt |qS r-   )r   r  r+   r-   r.   r    r  z,Bookmark.write_to_stream.<locals>.<listcomp>)r  rD  r8  r<  r=  rC  ro   r   z/Destr  )rJ   r?   r   r   r  r  r-   r+   r.   r?     s    






zBookmark.write_to_stream)r2   rA   rB   r   r   rG   rF   r?   r-   r-   r-   r.   r    s    r  stringc                 C   r   )NcreateStringObjectr   r   )r   r   )r  rr   r-   r-   r.   r    s   
r  c              	   C   s   t | tr	t| S t | tr|t |ttfr;d}| D ]}z||| 7 }W q ty6   |t|fd7 }Y qw t|S t |trO|dkrHt| S t| |S z| 	t
jrct| d}d|_|W S tt| }d|_|W S  ty{   t|  Y S w td)z
    Create a ByteStringObject or a TextStringObject from a string to represent the string.

    :param string: A string

    :raises TypeError: If string is not of type str or bytes.
    r   charmaprF   zutf-16Tz3create_string_object should have str or unicode arg)rb   rG   r   rF   r  r   r   r   r   
startswithr   r   r   decode_pdfdocencodingr   r   	TypeError)r  rr   outr   r4  r-   r-   r.   r     s8   


r   
action_refr  r  r  r  c                 C   s   t  }|td| tdt|i |d ur&|tdtdd |D i d}|r.|d7 }|r4|d7 }|rA|td	t|i |S )
Nz/Ar  r  c                 S      g | ]}t |qS r-   r   )r  r   r-   r-   r.   r        z$_create_bookmark.<locals>.<listcomp>r   r   r   r  )r5  r-  r   r   rk   r   )r  r  r  r  r  bookmarkZformat_flagr-   r-   r.   _create_bookmark  s$   r  unicode_stringc              
   C   sH   d}| D ]}z|t tt| 7 }W q ty!   td|dddw |S )Nr   pdfdocencodingrs   #does not exist in translation table)r   r   r   r   r   )r   r4  r   r-   r-   r.   r     s   
r   
byte_arrayc                 C   s>   d}| D ]}t | }|dkrtdt|ddd||7 }q|S )Nr    r!  rs   r"  )r   r   	bytearray)r#  r4  br   r-   r-   r.   r  	  s   
r  r[   c                    s   t  fdddD S )Nc                 3   s*    | ]}t  ||d   dd V  qdS )r   r   g     o@N)r   )r  ir]   r-   r.   r    s   ( zhex_to_rgb.<locals>.<genexpr>)r   r   rK   )tupler]   r-   r]   r.   
hex_to_rgb  s   r)  c                   @   s   e Zd Ze							ddedeeeeef ded	ed
edededededefddZ	e		ddeeef deeef deeeeef dededefddZ
dS )AnnotationBuilder	HelveticaF14pt000000fffffftextrectfontr  r  	font_size
font_colorborder_colorbackground_colorr)   c	                 C   s   d}	|du r
|	d }	|du r|	d }	|	| d | }	|	d | }	d}
t |D ]
}|
t| d }
q&|
d }
t }|td	td
tdtdtdt|tdt| tdt|	tdt|
tdtdd t |D i |S )z"Add text in a rectangle to a page.zfont: Tzbold zitalic r   z;text-align:left;color:#r   Zrgr  /Annot/Subtypez	/FreeText/Rect	/Contentsz/DSz/DAr  c                 S   r  r-   r  )r  nr-   r-   r.   r  E  r  z/AnnotationBuilder.free_text.<locals>.<listcomp>)r)  rG   r   r-  r   r  r   rk   )r/  r0  r1  r  r  r2  r3  r4  r5  Zfont_strZbg_color_strst	free_textr-   r-   r.   r<    s2   zAnnotationBuilder.free_textr   r  p2	title_barc                 C   s   t tdtdtdtdtdt|tdt|tdtt| d t| d	 t|d t|d	 gtd
ttdtdgtdttdtdtdgtdt|i}|S )aU  
        Draw a line on the PDF.

        :param p1: First point
        :param p2: Second point
        :param rect: Rectangle
        :param text: Text to be displayed as the line annotation
        :param title_bar: Text to be displayed in the title bar of the
            annotation; by convention this is the name of the author
        r  r6  r7  z/Liner8  z/Tz/Lr   r   z/LENz/ICg      ?r9  )r   r   r  r   rk   r   )r  r=  r0  r/  r>  Zline_objr-   r-   r.   lineK  s6   



zAnnotationBuilder.lineN)r+  FFr,  r-  r-  r.  )r   r   )r2   rA   rB   rY   rG   r
   r   rc   r   r<  r?  r-   r-   r-   r.   r*    s\    	
,

r*  r<   )hr   
__author____author_email__r   r   rC   loggingr   r'  enumr   ior   typingr   r   r   r   r   r	   r
   r   r   _codecsr   r   r   Z_utilsr   r   r   r   r   r   r   r   r   r   r   r   	constantsr   r   r   rh  r    r)  r!   r  r"   r   errorsr#   r$   r%   r&   	getLoggerr2   loggerr  ZNumberSignsr   r  r'   rH   rZ   r  rk   r   r   r   r   r   r   rG   r   r   r   rF   r   r   r   r   r   r5  r+  rX  r`  rx  rx   r  r  r  r  r  r  r   r   rc   r  r   r  r)  r*  r-   r-   r-   r.   <module>   s   ,8

.8I)'



J F, [ X+ 
0 r 		 1






.
