o
    pcC                  	   @   s  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Zd dlZdd Z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%i d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOZ	dPdQ Z
G dRdS dSeZdTdU ZG dVdW dWedXdYdZgZG d[d\ d\eZG d]d^ d^ZG d_d` d`ZG dadb dbeZG dcdd ddejZG dedf dfZG dgdh dhZdidj ZG dkdl dlZdS )m    Nc                 C   s   t j| d S )N	utf_16_be)codecsBOM_UTF16_BEencode)s r   -lib/python3.10/site-packages/PIL/PdfParser.pyencode_text      r	         u   ˘   u   ˇ   u   ˆ   u   ˙   u   ˝   u   ˛   u   ˚   u   ˜   u   •   u   †   u   ‡   u   …   u   —   u   –   u   ƒ   u   ⁄   u   ‹   u   ›   u   −   u   ‰   u   „   u   “   u   ”   u   ‘   u   ’   u   ‚   u   ™   u   ﬁ   u   ﬂ   u   Ł   u   Œ   u   Š   u   Ÿu   Žu   ıu   łu   œu   šu   žu   €)                     c                 C   sD   | d t tj tjkr| t tjd  dS ddd | D S )Nr    c                 s   s     | ]}t |t|V  qd S N)PDFDocEncodinggetchr).0Zbyter   r   r   	<genexpr>B   s    zdecode_text.<locals>.<genexpr>)lenr   r   decodejoin)br   r   r   decode_text>   s   r@   c                   @   s   e Zd ZdZdS )PdfFormatErrorz\An error that probably indicates a syntactic or semantic error in the
    PDF file structureN)__name__
__module____qualname____doc__r   r   r   r   rA   E   s    rA   c                 C   s   | st |d S r6   )rA   )Z	conditionZerror_messager   r   r   check_format_conditionL   s   rF   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )IndirectReferencec                 C      d|  S )Nz%s %s Rr   selfr   r   r   __str__T      zIndirectReference.__str__c                 C   s   |   dS Nus-ascii)rK   r   rI   r   r   r   	__bytes__W   s   zIndirectReference.__bytes__c                 C   s$   |j | j u o|j| jko|j| jkS r6   )	__class__	object_id
generationrJ   otherr   r   r   __eq__Z   s
   

zIndirectReference.__eq__c                 C   s
   | |k S r6   r   rS   r   r   r   __ne__a      
zIndirectReference.__ne__c                 C   s   t | j| jfS r6   )hashrQ   rR   rI   r   r   r   __hash__d   r
   zIndirectReference.__hash__N)rB   rC   rD   rK   rO   rU   rV   rY   r   r   r   r   rG   Q   s    rG   ZIndirectReferenceTuplerQ   rR   c                   @      e Zd Zdd ZdS )IndirectObjectDefc                 C   rH   )Nz	%s %s objr   rI   r   r   r   rK   i   rL   zIndirectObjectDef.__str__N)rB   rC   rD   rK   r   r   r   r   r[   h       r[   c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )	XrefTablec                 C   s    i | _ i | _ddi| _d| _d S )Nr   i   F)existing_entriesnew_entriesdeleted_entriesreading_finishedrI   r   r   r   __init__n   s   

zXrefTable.__init__c                 C   s6   | j r	|| j|< n|| j|< || jv r| j|= d S d S r6   )ra   r_   r^   r`   rJ   keyvaluer   r   r   __setitem__t   s   

zXrefTable.__setitem__c                 C   s*   z| j | W S  ty   | j|  Y S w r6   )r_   KeyErrorr^   rJ   rd   r   r   r   __getitem__|   s
   zXrefTable.__getitem__c                 C   s   || j v r| j | d d }| j |= || j|< d S || jv r.| j| d d }|| j|< d S || jv r:| j| }d S dt| d }t|)N   z
object ID z+ cannot be deleted because it doesn't exist)r_   r`   r^   str
IndexError)rJ   rd   rR   msgr   r   r   __delitem__   s   


zXrefTable.__delitem__c                 C   s   || j v p	|| jv S r6   )r^   r_   rh   r   r   r   __contains__      zXrefTable.__contains__c                 C   s.   t t| j t| j B t| j B S r6   )r<   setr^   keysr_   r`   rI   r   r   r   __len__   s   zXrefTable.__len__c                 C   s*   t | j t | j  t | j B S r6   )rq   r^   rr   r`   r_   rI   r   r   r   rr      s   zXrefTable.keysc              	   C   sF  t t| j t| j B }t t| j }| }|d |rd }t|D ]\}}|d u s8|d |kr;|}q*|d | }||d  } n|}d }|d|d t|f  |D ]B}	|	| jv rn|d| j|	   q\|	d}
t
|	|
kd|	 d|
  z|d }W n ty   d}Y nw |d|| j|	 f  q\|s$|S )	Ns   xref
rj   s   %d %d
r   s   %010d %05d n 
z*expected the next deleted object ID to be z, instead found s   %010d %05d f 
)sortedrq   r_   rr   r`   tellwrite	enumerater<   poprF   rl   )rJ   frr   Zdeleted_keysZ	startxrefprevindexrd   Zcontiguous_keysrQ   Zthis_deleted_object_idZnext_in_linked_listr   r   r   rv      sJ    


 zXrefTable.writeN)rB   rC   rD   rb   rf   ri   rn   ro   rs   rr   rv   r   r   r   r   r]   m   s    r]   c                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zedd Z	e
edddd dD  Zdd ZdS )PdfNamec                 C   s:   t |tr|j| _d S t |tr|| _d S |d| _d S rM   )
isinstancer|   namebytesr   )rJ   r~   r   r   r   rb      s
   


zPdfName.__init__c                 C   s   | j dS rM   )r~   r=   rI   r   r   r   name_as_str   s   zPdfName.name_as_strc                 C   s    t |to
|j| jkp|| jkS r6   )r}   r|   r~   rS   r   r   r   rU      s   zPdfName.__eq__c                 C   s
   t | jS r6   )rX   r~   rI   r   r   r   rY      rW   zPdfName.__hash__c                 C   s   dt | j dS )NzPdfName())reprr~   rI   r   r   r   __repr__   s   zPdfName.__repr__c                 C   s   | t |S r6   )	PdfParserinterpret_name)clsdatar   r   r   from_pdf_stream   s   zPdfName.from_pdf_stream!      c                 C   s   h | ]}t |qS r   )ord)r:   cr   r   r   	<setcomp>   s    zPdfName.<setcomp>z#%/()<>[]{}c                 C   s@   t d}| jD ]}|| jv r|| q|d|  qt|S )N   /s   #%02X)	bytearrayr~   allowed_charsappendextendr   )rJ   resultr?   r   r   r   rO      s   

zPdfName.__bytes__N)rB   rC   rD   rb   r   rU   rY   r   classmethodr   rq   ranger   rO   r   r   r   r   r|      s    
r|   c                   @   rZ   )PdfArrayc                 C   s   dd dd | D  d S )Ns   [     c                 s   s    | ]}t |V  qd S r6   )pdf_repr)r:   xr   r   r   r;          z%PdfArray.__bytes__.<locals>.<genexpr>s    ])r>   rI   r   r   r   rO         zPdfArray.__bytes__N)rB   rC   rD   rO   r   r   r   r   r      r\   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )PdfDictc                 C   s.   |dkrt j| || d S || |d< d S )Nr   rN   )collectionsUserDict__setattr__r   rc   r   r   r   r      s   zPdfDict.__setattr__c              
   C   s  z	| | d }W n ty } zt||d }~ww t|tr$t|}|dr|dr4|dd  }d}t|dkrZ|d }t	|dd d	 }t|d
krZ|t	|dd
 7 }dd t|d  }t
|d t|d  |}|dv r|d	9 }|dkr|d9 }t
t|| }|S )NrN   ZDatezD:   Z         <         z%Y%m%d%H%M%S)+-r   )r   rg   AttributeErrorr}   r   r@   endswith
startswithr<   inttimestrptimegmtimecalendarZtimegm)rJ   rd   re   eZrelationshipoffsetformatr   r   r   __getattr__   s2   



zPdfDict.__getattr__c                 C   sn   t d}|  D ]%\}}|d u rqt|}|d |tt| |d || q|d t|S )N   <<   
r   s   
>>)r   itemsr   r   r   r|   )rJ   outrd   re   r   r   r   rO     s   


zPdfDict.__bytes__N)rB   rC   rD   r   r   rO   r   r   r   r   r      s    r   c                   @      e Zd Zdd Zdd ZdS )	PdfBinaryc                 C   s
   || _ d S r6   )r   )rJ   r   r   r   r   rb   &  rW   zPdfBinary.__init__c                 C   s   dd dd | jD  S )Ns   <%s>    c                 s   s    | ]}d | V  qdS )s   %02XNr   r:   r?   r   r   r   r;   *  r   z&PdfBinary.__bytes__.<locals>.<genexpr>)r>   r   rI   r   r   r   rO   )  s   zPdfBinary.__bytes__N)rB   rC   rD   rb   rO   r   r   r   r   r   %  s    r   c                   @   r   )	PdfStreamc                 C   s   || _ || _d S r6   )
dictionarybuf)rJ   r   r   r   r   r   rb   .  s   
zPdfStream.__init__c                 C   s   z| j j}W n ty   | j Y S w |dkr5z| j j}W n ty*   | j j}Y nw tj| jt|dS dt	| j j d}t
|)Ns   FlateDecode)bufsizezstream filter z unknown/unsupported)r   ZFilterr   r   ZDLLengthzlib
decompressr   r   NotImplementedError)rJ   filterZexpected_lengthrm   r   r   r   r=   2  s   
zPdfStream.decodeN)rB   rC   rD   rb   r=   r   r   r   r   r   -  s    r   c                 C   s  | du rdS | du rdS | d u rdS t | ttttfrt| S t | tr+t| dS t | t	r7t| dS t | t
jrJdt
d| d d	 S t | trUtt| S t | tr`tt| S t | trktt| S t | tr| d
d} | dd} | d	d} d|  d	 S t| S )NTs   trueFs   falses   nullrN   s   (D:z%Y%m%d%H%M%SZ   )   \s   \\   (   \(s   \))r}   r|   r   r   r   r   r   rk   r   floatr   struct_timestrftimedictlistr   r	   replace)r   r   r   r   r   B  s4   





r   c                   @   s  e Zd ZdZdrddZdd Zd	d
 Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdsddZdd Zdd  Zd!d" Zed#d$ Zd%d& Zdsd'd(Zd)Zd*Zd+Zd,Zed- Zed. Zd/Zd0Zee e Ze !ed1 e d2 e d3 e d4 e d5 e d6 e j"Z#e !ed1 e d7 e d3 e d4 e d5 e e j"Z$d8d9 Z%d:d; Z&e !eZ'e !ed< e d= Z(e !ed> Z)e !ed? e Z*e+d@dA Z,e !dBZ-e+dtdDdEZ.e !edF e d= Z/e !edG e d= Z0e !edH e d= Z1e !edI e d= Z2e !edJ e d= Z3e !edK Z4e !edL Z5e !edM e dN Z6e !edO Z7e !edP e dP e dQ e d= Z8e !edP e dP e dR e d= Z9e !edS e d= Z:e !dTe dU e dV Z;e !edW Z<e !edX e d= Z=e+dudZd[Z>e !d\Z?i d]d^d_d`dadbdcdddedfdTdTd=d=dgdge@d]d^e@d_d`e@dadbe@dcdde@dedfe@dTdTe@d=d=e@dgdgZAe+dhdi ZBe !edj e ZCe !ed4 e d4 e e ZDe !dkZEdldm ZFdvdndoZGdsdpdqZHdS )wr   z|Based on
    https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf
    Supports PDF up to 1.4
    Nr   rbc                 C   s  |r
|r
d}t ||| _|| _|| _|| _d| _d| _|d ur/|d u r/t|| | _}d| _|d urI| | | _}d| _|sIt	|drI|j
| _i | _|rS|   n*d | _| _t | _d | _t | _d | _i | _g | _g | _d | _d | _i | _t | _d| j_|r|   d S d S )Nz4specify buf or f or filename, but not both buf and fFTr~   r   )RuntimeErrorfilenamer   ry   start_offsetshould_close_bufshould_close_fileopenget_buf_from_filehasattrr~   cached_objectsread_pdf_infofile_size_totalfile_size_thisr   rootroot_refinfoinfo_refpage_tree_rootpages
orig_pages	pages_reflast_xref_section_offsettrailer_dictr]   
xref_tablera   seek_end)rJ   r   ry   r   r   moderm   r   r   r   rb   g  sH   
zPdfParser.__init__c                 C   s   | S r6   r   rI   r   r   r   	__enter__  s   zPdfParser.__enter__c                 C   s   |    dS )NF)close)rJ   exc_type	exc_value	tracebackr   r   r   __exit__  s   zPdfParser.__exit__c                 C   s   |    |   d S r6   )	close_bufr   rI   r   r   r   start_writing  s   zPdfParser.start_writingc                 C   s,   z| j   W n	 ty   Y nw d | _ d S r6   )r   r   r   rI   r   r   r   r     s   
zPdfParser.close_bufc                 C   s:   | j r|   | jd ur| jr| j  d | _d S d S d S r6   )r   r   ry   r   r   rI   r   r   r   r     s   

zPdfParser.closec                 C   s   | j dtj d S )Nr   )ry   seekosSEEK_ENDrI   r   r   r   r     rp   zPdfParser.seek_endc                 C   s   | j d d S )Ns	   %PDF-1.4
)ry   rv   rI   r   r   r   write_header  r
   zPdfParser.write_headerc                 C   s   | j d| d  d S )Nz% 
)ry   rv   r   )rJ   r   r   r   r   write_comment  r   zPdfParser.write_commentc                 C   sl   |    | | j | _| d| _|   | j| jtd| jd | j| jtdt	| j
| j
d | jS )Nr      Catalog)TypeZPages   Pages)r   ZCountZKids)del_rootnext_object_idry   ru   r   r   rewrite_pages	write_objr|   r<   r   rI   r   r   r   write_catalog  s   zPdfParser.write_catalogc                 C   s   g }t | jD ]N\}}| j| }| j|j= ||td  || jvr$qi }| D ]
\}}|||	 < q*| j
|d< | jdi |}t | jD ]\}	}
|
|krT|| j|	< qGq|D ]}|rt| j| }|j| jv rl| j|j= |dd }|s\qXg | _d S )Ns   ParentParentr6   )rw   r   r   r   rQ   r   r|   r   r   r   r   
write_pager8   )rJ   Zpages_tree_nodes_to_deleteiZpage_refZ	page_infoZstringified_page_inford   re   Znew_page_refjZcur_page_refZpages_tree_node_refZpages_tree_noder   r   r   r     s4   







zPdfParser.rewrite_pagesc                 C   s   |r	|    || _| jr| d | j| _| j| j}t| j}| j|d}| j	d ur0| j	|d< | jr8| j|d< || _	| jdt
t| d|   d S )N)   Root   Size   Prev   Infos   trailer
s   
startxref
%d
%%%%EOF)r   r   r   r   r   r   rv   ry   r<   r   r   r   )rJ   Znew_root_refZ
start_xrefZnum_entriesr   r   r   r   write_xref_and_trailer  s(   




z PdfParser.write_xref_and_trailerc                 O   sR   t |tr
| j| }d|vrtd|d< d|vr| j|d< | j|g|R i |S )Nr      Pager  )r}   r   r   r|   r   r   )rJ   refobjsdict_objr   r   r   r    s   


zPdfParser.write_pagec                 O   s   | j }|d u r| | }n| |jf| j|j< |tt|  |	dd }|d ur3t
||d< |r<|t| |D ]	}|t| q>|d ur[|d || |d |d |S )Nstreamr   s   stream
s   
endstream
s   endobj
)ry   r   ru   rR   r   rQ   rv   r   r[   rx   r<   r   )rJ   r  r  r  ry   r  objr   r   r   r     s$   



zPdfParser.write_objc                 C   s.   | j d u rd S | j| j j= | j| jd j= d S )Nr   )r   r   rQ   r   rI   r   r   r   r     s   
zPdfParser.del_rootc                 C   sR   t | dr	|  S t | dr|  S ztj|  dtjdW S  ty(   Y dS w )N	getbuffergetvaluer   )accessr   )r   r  r  mmapfilenoZACCESS_READ
ValueError)ry   r   r   r   r     s   

zPdfParser.get_buf_from_filec                 C   s   t | j| _| j| j | _|   | jd | _| jdd | _	t
| | j| _| j	d u r2t
 | _n	t
| | j	| _td| jv d t| jd dkd td| jv d tt| jd td	 | jd | _| | j| _| | j| _| jd d  | _d S )
Nr  r	     Typez/Type missing in Rootr   z/Type in Root is not /Catalogr   z/Pages missing in Rootz+/Pages in Root is not an indirect reference)r<   r   r   r   r   read_trailerr   r   r8   r   r   read_indirectr   r   rF   r}   rG   r   r   linearize_page_treer   r   rI   r   r   r   r     s,   

zPdfParser.read_pdf_infoc                 C   sV   zt t| j d d}W n ty   t dd}Y nw |d ur)|df| j|j< |S )Nrj   r   )rG   maxr   rr   r  rQ   )rJ   r   Z	referencer   r   r   r   :  s   zPdfParser.next_object_ids   [][()<>{}/%]s$   [][()<>{}/%\000\011\012\014\015\040]s   [\000\011\012\014\015\040]s#   [\000\011\012\014\015\0400-9a-fA-F]   *   +s   [\000\011\014\040]*s   [\r\n]+s   trailers   <<(.*>>)s	   startxrefs   ([0-9]+)s   %%EOF   $s	   <<(.*?>>)c                 C   s   t | jd }|| jk r| j}| j| j|}t|d |}|r0|}| j| j| d }|s |s4|}|d}t|d| _	| 
|| _t | _| j| j	d d| jv ra| | jd  d S d S )N @  ztrailer end not found   rj   r   xref_section_offsetr  )r<   r   r   re_trailer_endsearchrF   startgroupr   r   interpret_trailerr   r]   r   read_xref_tableread_prev_trailer)rJ   Zsearch_start_offsetmZ
last_matchtrailer_datar   r   r   r  l  s(   



zPdfParser.read_trailerc                 C   sz   | j |d}| j| j||d  }t|d |d}tt|d|kd | |}d|v r;| |d  d S d S )Nr!  r  zprevious trailer not foundrj   r   zGxref section offset in previous trailer doesn't match what was expectedr  )	r(  re_trailer_prevr$  r   rF   r&  r   r'  r)  )rJ   r"  Ztrailer_offsetr*  r+  r   r   r   r   r)    s   


zPdfParser.read_prev_trailers   /([!-$&'*-.0-;=?-Z\\^-z|~]+)(?=r   r   s   >>c                 C   s   i }d}	 | j ||}|s+| j||}t|o| t|kdt||d    n| |d}| 	|| \}}|||< qtd|v oMt
|d td td|v o[t
|d td |S )	Nr   Tz+name not found in trailer, remaining data: rj   r  z&/Size not in trailer or not an integerr  z1/Root not in trailer or not an indirect reference)re_namematchre_dict_endrF   endr<   r   r   r&  	get_valuer}   r   rG   )r   r+  Ztrailerr   r*  rd   re   r   r   r   r'    s4   zPdfParser.interpret_trailers   ([^#]*)(#([0-9a-fA-F]{2}))?Fc                 C   sj   d}| j |D ]!}|dr"||dt|dd 7 }q||d7 }q|r1|dS t|S )Nr      rj   rN   zutf-8)re_hashes_in_namefinditerr&  r   fromhexr=   r   )r   rawZas_textr~   r*  r   r   r   r     s   
&
zPdfParser.interpret_names   null(?=s   true(?=s   false(?=s   ([-+]?[0-9]+)(?=s)   ([-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+))(?=s   \[   ]s   <(s   *)>r   s   ([-+]?[0-9]+)s   R(?=s   obj(?=s	   endobj(?=r   s	   %[^\r\n]*s   )*s   stream\r?\ns   endstream(?=r   c              
   C   s  |dkrdS | j ||}|r| }| j||}|rttt|ddkd tt|ddkd t|d u pI|tt|dt|dkd | j|| |d d\}}|d u rb|d fS | j	||}t|d	 || fS t| d
 | j
||}|rtt|ddkd tt|ddkd tt|dt|d| fS | j||}|rc| }i }| j||}|s| j|||d d\}}|d u r|d fS | j|||d d\}	}|	||< |d u r|d fS | j||}|r| }| j||}|r[zt|d }
W n tttfy/ } zd|dd  }t||d }~ww || | |
  }| j|| |
 }t|d | }tt||}||fS t|}||fS | j||}|r| }g }| j||}|s| j|||d d\}	}||	 |d u r|d fS | j||}|r}|| fS | j||}|rd | fS | j||}|rd| fS | j||}|rd| fS | j||}|rt| |d| fS | j||}|rt|d| fS | j ||}|rt!|d| fS | j"||}|rKt#dd |dD }t$|d dkr?|t%d t#&|'d| fS | j(||}|r]| )|| S dt*|||d   }t|)Nr   )NNrj   z<indirect object definition: object ID must be greater than 0r   z;indirect object definition: generation must be non-negativez2indirect object definition different than expected)max_nestingz(indirect object definition end not foundz$indirect object definition not foundz;indirect object reference: object ID must be greater than 0z:indirect object reference: generation must be non-negatives   Lengthz)bad or missing Length in stream dict (%r)zstream end not foundTFc                 s   s    | ]	}|d v r|V  qdS )s   0123456789abcdefABCDEFNr   r   r   r   r   r;   b  s    z&PdfParser.get_value.<locals>.<genexpr>   0rN   zunrecognized object:     )+
re_commentr.  r0  re_indirect_def_startrF   r   r&  rG   r1  re_indirect_def_endre_indirect_referencere_dict_startr/  re_stream_start	TypeErrorrg   r  r8   rA   re_stream_endr   r   re_array_startre_array_endr   re_nullre_truere_falser-  r|   r   re_intre_realr   re_string_hexr   r<   r   r5  r=   re_string_litget_literal_stringr   )r   r   r   expect_indirectr8  r*  objectr   rd   re   Z
stream_lenr   rm   Zstream_dataZ
hex_stringr   r   r   r1    s   
&	



zPdfParser.get_valuesF   (\\[nrtbf()\\])|(\\[0-9]{1,3})|(\\(\r\n|\r|\n))|(\r\n|\r|\n)|(\()|(\))   nr      r      t   	   b      f   r   c                 C   s  d}t  }| j||D ]u}||||   |dr,|| j|dd   nQ|drA|t|ddd  d n<|drGn6|drR|d n+|dra|d	 |d7 }n|d
r}|dkrtt	||
 f  S |d |d8 }|
 }qd}t|)Nr   rj   r      r2     r      r      r   zunfinished literal string)r   re_lit_str_tokenr4  r   r%  r&  escaped_charsr   r   r   r0  rA   )r   r   r   Znesting_depthr   r*  rm   r   r   r   rL    s.   

 







zPdfParser.get_literal_strings   xrefs+   ([0-9]{10}) ([0-9]{5}) ([fn])( \r| \n|\r\n)c                 C   s  d}| j | j|| j }t|d | }	 | j| j|}|s)t|d 	 |S d}| }t|d}t|d}t	||| D ]@}| j
| j|}t|d | }|dd	k}t|d}	|st|d|	f}
t|| jvp|| j| |
kd
 |
| j|< qDq)NFzxref section start not foundTzxref subsection start not foundrj   r   zxref entry not foundr2  rV  z)xref entry duplicated (and not identical))re_xref_section_startr.  r   r   rF   r0  re_xref_subsection_startr   r&  r   re_xref_entryr   )rJ   r"  Zsubsection_foundr*  r   Zfirst_objectZnum_objectsr  Zis_freerR   Z	new_entryr   r   r   r(    sB   


zPdfParser.read_xref_tablec              
   C   st   | j |d  \}}t||d kd|d  d|d  d| d|  | j| j|| j t| |dd }|| j|< |S )Nr   rj   zexpected to find generation z for object ID z) in xref table, instead found generation z at offset )rM  r8  )r   rF   r1  r   r   rG   r   )rJ   r  r8  r   rR   re   r   r   r   r    s&   

zPdfParser.read_indirectc                 C   sj   |d u r| j }t|d dkd g }|d D ]}| |}|d dkr)|| q|| j|d q|S )Nr  r   z%/Type of page tree node is not /Pagess   Kidsr  )node)r   rF   r  r   r   r  )rJ   ra  r   ZkidZ
kid_objectr   r   r   r    s   
zPdfParser.linearize_page_tree)NNNr   r   r6   )F)Nr   )r   )IrB   rC   rD   rE   rb   r   r   r   r   r   r   r   r   r  r   r
  r  r   r   staticmethodr   r   r   Z	delimiterZdelimiter_or_wsZ
whitespaceZwhitespace_or_hexZwhitespace_optionalZwhitespace_mandatoryZwhitespace_optional_no_nlZnewline_onlynewlinerecompileDOTALLr#  r,  r  r)  Zre_whitespace_optionalr-  r?  r/  r   r'  r3  r   rE  rF  rG  rH  rI  rC  rD  rJ  rK  r>  r<  r=  r;  r@  rB  r1  r\  r   r]  rL  r^  r_  r`  r(  r  r  r   r   r   r   r   a  s   
&
	


	
	





z	



!r   )r   r   r   r  r   rd  r   r   r	   r7   r@   r   rA   rF   
namedtuplerG   r[   r]   r|   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s    	
 !"#-
\'0