o
    Wf~                  	   @  s@  d dl m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l	Z	d dl
mZmZmZmZm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/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQZdRdS ZG dTdU dUeZdVdW ZG dXdY dYeZG dZd[ d[eZG d\d] d]eZG d^d_ d_ZG d`da daZG dbdc dcee Zerejeeef ef ZnejZG ddde deeZ G dfdg dgZ!G dhdi diZ"djdk Z#G dldm dmZ$dS )n    )annotationsN)TYPE_CHECKINGAnyList
NamedTupleUnionc                 C  s   t j| d S )N	utf_16_be)codecsBOM_UTF16_BEencode)s r   u/media/darth/New Volume E/PROJECTS/DRIVERZZ/DRIVERZZ_CUSTOMER_APIS/venv/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).0byter   r   r   	<genexpr>E   s    zdecode_text.<locals>.<genexpr>)lenr	   r
   decodejoin)br   r   r   decode_textA   s   rG   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   rH   H   s    rH   c                 C  s   | st |d S r<   )rH   )	conditionerror_messager   r   r   check_format_conditionO   s   rO   c                   @  s   e Zd ZU ded< ded< dS )IndirectReferenceTupleint	object_id
generationN)rI   rJ   rK   __annotations__r   r   r   r   rP   T   s   
 rP   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     | j  d| j dS )N z RrR   rS   selfr   r   r   __str__Z      zIndirectReference.__str__c                 C  s   |   dS Nus-ascii)r[   r   rY   r   r   r   	__bytes__]   s   zIndirectReference.__bytes__c                 C  s$   |j | j u o|j| jko|j| jkS r<   )	__class__rR   rS   rZ   otherr   r   r   __eq__`   s
   

zIndirectReference.__eq__c                 C  s
   | |k S r<   r   ra   r   r   r   __ne__g      
zIndirectReference.__ne__c                 C  s   t | j| jfS r<   )hashrR   rS   rY   r   r   r   __hash__j   r   zIndirectReference.__hash__N)rI   rJ   rK   r[   r_   rc   rd   rg   r   r   r   r   rU   Y   s    rU   c                   @     e Zd Zdd ZdS )IndirectObjectDefc                 C  rV   )NrW   z objrX   rY   r   r   r   r[   o   r\   zIndirectObjectDef.__str__N)rI   rJ   rK   r[   r   r   r   r   ri   n       ri   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_finishedrY   r   r   r   __init__t   s   

zXrefTable.__init__c                 C  s6   | j r	|| j|< n|| j|< || jv r| j|= d S d S r<   )ro   rm   rl   rn   rZ   keyvaluer   r   r   __setitem__z   s   

zXrefTable.__setitem__c                 C  s*   z| j | W S  ty   | j|  Y S w r<   )rm   KeyErrorrl   rZ   rr   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)rm   rn   rl   str
IndexError)rZ   rr   rS   msgr   r   r   __delitem__   s   


zXrefTable.__delitem__c                 C  s   || j v p	|| jv S r<   )rl   rm   rv   r   r   r   __contains__   r\   zXrefTable.__contains__c                 C  s.   t t| j t| j B t| j B S r<   )rC   setrl   keysrm   rn   rY   r   r   r   __len__   s   zXrefTable.__len__c                 C  s*   t | j t | j  t | j B S r<   )r~   rl   r   rn   rm   rY   r   r   r   r      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
rx   s   %d %d
r   s   %010d %05d n 
z*expected the next deleted object ID to be z, instead found s   %010d %05d f 
)sortedr~   rm   r   rn   tellwrite	enumeraterC   poprO   rz   )rZ   fr   deleted_keys	startxrefprevindexrr   contiguous_keysrR   this_deleted_object_idnext_in_linked_listr   r   r   r      sJ    


 zXrefTable.writeN)rI   rJ   rK   rp   rt   rw   r|   r}   r   r   r   r   r   r   r   rk   s   s    rk   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 r]   )
isinstancer   namebytesr   )rZ   r   r   r   r   rp      s
   


zPdfName.__init__c                 C  s   | j dS r]   )r   rD   rY   r   r   r   name_as_str   s   zPdfName.name_as_strc                 C  s    t |to
|j| jkp|| jkS r<   )r   r   r   ra   r   r   r   rc      s   zPdfName.__eq__c                 C  s
   t | jS r<   )rf   r   rY   r   r   r   rg      re   zPdfName.__hash__c                 C  s   dt | j dS )NzPdfName())reprr   rY   r   r   r   __repr__   s   zPdfName.__repr__c                 C  s   | t |S r<   )	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   )rZ   resultrF   r   r   r   r_      s   

zPdfName.__bytes__N)rI   rJ   rK   rp   r   rc   rg   r   classmethodr   r~   ranger   r_   r   r   r   r   r      s    
r   c                   @  rh   )PdfArrayc                 C  s   dd dd | D  d S )Ns   [     c                 s  s    | ]}t |V  qd S r<   )pdf_repr)r@   xr   r   r   rB          z%PdfArray.__bytes__.<locals>.<genexpr>s    ])rE   rY   r   r   r   r_         zPdfArray.__bytes__N)rI   rJ   rK   r_   r   r   r   r   r      rj   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   r^   )collectionsUserDict__setattr__r   rq   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 )Nr^   DatezD:   Z         <         z%Y%m%d%H%M%S)+-r   )r   ru   AttributeErrorr   r   rG   endswith
startswithrC   rQ   timestrptimegmtimecalendartimegm)rZ   rr   rs   e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   )rZ   outrr   rs   r   r   r   r_   #  s   


zPdfDict.__bytes__N)rI   rJ   rK   r   r   r_   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 r<   )r   )rZ   r   r   r   r   rp   2  re   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@   rF   r   r   r   rB   6  r   z&PdfBinary.__bytes__.<locals>.<genexpr>)rE   r   rY   r   r   r   r_   5  s   zPdfBinary.__bytes__N)rI   rJ   rK   rp   r_   r   r   r   r   r   1  s    r   c                   @  r   )	PdfStreamc                 C  s   || _ || _d S r<   )
dictionarybuf)rZ   r   r   r   r   r   rp   :  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   Filterr   r   DLLengthzlib
decompressrQ   r   NotImplementedError)rZ   filterexpected_lengthr{   r   r   r   rD   >  s   
zPdfStream.decodeN)rI   rJ   rK   rp   rD   r   r   r   r   r   9  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tfr-t| 	dS t | t
jr@dt
d| 	d d	 S t | trKtt| S t | trVtt| S t | tratt| S t | tr~| d
d} | dd} | d	d} d|  d	 S t| S )NTs   trueFs   falses   nullr^   s   (D:z%Y%m%d%H%M%SZ   )   \s   \\   (   \(s   \))r   r   r   r   r   r   rQ   floatry   r   r   struct_timestrftimedictlistr   r   replace)r   r   r   r   r   N  s0   



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   r   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_dictrk   
xref_tablero   seek_end)rZ   r   r   r   r   moder{   r   r   r   rp   q  sH   
zPdfParser.__init__c                 C  s   | S r<   r   rY   r   r   r   	__enter__  s   zPdfParser.__enter__c                 C  s   |    dS )NF)close)rZ   exc_type	exc_value	tracebackr   r   r   __exit__  s   zPdfParser.__exit__c                 C  s   |    |   d S r<   )	close_bufr  rY   r   r   r   start_writing  s   zPdfParser.start_writingc                 C  s,   z| j   W n	 ty   Y nw d | _ d S r<   )r   r  r   rY   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 r<   )r   r	  r   r   r  rY   r   r   r   r    s   

zPdfParser.closec                 C  s   | j dtj d S )Nr   )r   seekosSEEK_ENDrY   r   r   r   r    r\   zPdfParser.seek_endc                 C  s   | j d d S )Ns	   %PDF-1.4
)r   r   rY   r   r   r   write_header  r   zPdfParser.write_headerc                 C  s   | j d| d  d S )Nz% 
)r   r   r   )rZ   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)TypePages   Pages)r  CountKids)del_rootnext_object_idr   r   r   r   rewrite_pages	write_objr   rC   r   rY   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Parentr<   )r   r   r   r   rR   r   r   r   r   r   r   
write_pager>   )rZ   pages_tree_nodes_to_deleteipage_ref	page_infostringified_page_inforr   rs   new_page_refjcur_page_refpages_tree_node_ref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   r   r   rC   r   r   r   )rZ   new_root_ref
start_xref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   rQ   r   r   r   r  )rZ   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
)r   r  r   rS   r   rR   r   r   ri   r   rC   r   )rZ   r1  r2  r3  r   r4  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   rR   r   rY   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   r6  r7  mmapfilenoACCESS_READ
ValueError)r   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)rC   r   r   r   r   read_trailerr   r   r>   r   r   read_indirectr   r   rO   r   rU   r   r   linearize_page_treer   r   rY   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 )Nrx   r   )rU   maxr   r   r<  rR   )rZ   r   	referencer   r   r   r  D  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   rx   r   xref_section_offsetr*  )rC   r   r   re_trailer_endsearchrO   startgrouprQ   r   interpret_trailerr   rk   r   read_xref_tableread_prev_trailer)rZ   search_start_offsetm
last_matchtrailer_datar   r   r   r>  v  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 )NrH  rF  zprevious trailer not foundrx   r   zGxref section offset in previous trailer doesn't match what was expectedr*  )	rO  re_trailer_prevrK  r   rO   rM  rQ   rN  rP  )rZ   rI  trailer_offsetrR  rT  r   r   r   r   rP    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: rx   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_endrO   endrC   r   r   rM  	get_valuer   rQ   rU   )r   rT  trailerr   rR  rr   rs   r   r   r   rN    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      rx   r^   zutf-8)re_hashes_in_namefinditerrM  r   fromhexrD   r   )r   rawas_textr   rR  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   )NNrx   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   rB   l  s    
z&PdfParser.get_value.<locals>.<genexpr>   0r^   zunrecognized object:     )+
re_commentrX  rZ  re_indirect_def_startrO   rQ   rM  rU   r[  re_indirect_def_endre_indirect_referencere_dict_startrY  re_stream_start	TypeErrorru   r<  r>   rH   re_stream_endr   r   re_array_startre_array_endr   re_nullre_truere_falserW  r   r   re_intre_realr   re_string_hexr   rC   r   r`  rD   re_string_litget_literal_stringr   )r   r   r   expect_indirectrd  rR  objectr   rr   rs   
stream_lenr   r{   stream_data
hex_stringr   r   r   r[    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   rx   r      r]     r      r      r   zunfinished literal string)r   re_lit_str_tokenr_  r   rL  rM  escaped_charsr   rQ   r   rZ  rH   )r   r   r   nesting_depthr   rR  r{   r   r   r   rx    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 ]6}| j
| j|}t|d | }|dd	k}|szt|d}	t|d|	f}
|| jvrz|
| j|< qDq)
NFzxref section start not foundTzxref subsection start not foundrx   r   zxref entry not foundr]  r  )re_xref_section_startrX  r   r   rO   rZ  re_xref_subsection_startrQ   rM  r   re_xref_entryr   )rZ   rI  subsection_foundrR  r   first_objectnum_objectsr  is_freerS   	new_entryr   r   r   rO    s<   



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   rx   zexpected to find generation z for object ID z) in xref table, instead found generation z at offset )ry  rd  )r   rO   r[  r   r   rU   r   )rZ   r1  rd  r   rS   rs   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   Kidsr0  )node)r   rO   r?  r   r   r@  )rZ   r  r   kid
kid_objectr   r   r   r@    s   
zPdfParser.linearize_page_tree)NNNr   r   r<   )F)Nr   )r   )IrI   rJ   rK   rL   rp   r  r  r
  r	  r  r  r  r  r  r  r/  r  r  r  staticmethodr   r   r  	delimiterdelimiter_or_ws
whitespacewhitespace_or_hexwhitespace_optionalwhitespace_mandatorywhitespace_optional_no_nlnewline_onlynewlinerecompileDOTALLrJ  rU  r>  rP  re_whitespace_optionalrW  rk  rY  r   rN  r^  r   rq  rr  rs  rt  ru  ro  rp  rv  rw  rj  rh  ri  rg  rl  rn  r[  r  r   r  rx  r  r  r  rO  r?  r@  r   r   r   r   r   k  s   
&
	


	
	





z	



r   )%
__future__r   r   r	   r   r9  r  r  r   r   typingr   r   r   r   r   r   r=   rG   r   rH   rO   rP   rU   ri   rk   r   r   r   ry   r   	_DictBaser   r   r   r   r   r   r   r   r   <module>   s    	
 !"#-\'0