o
    gik                     @   sv   d 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 ddl	m
Z
 ddlmZ eeZG dd	 d	e
ZdS )
ay  
The cross-reference table contains information that permits random access to indirect objects within the file so
that the entire file need not be read to locate any particular object.
This implementation of PlainTextXREF is invoked whenever the XREF could not be loaded properly.
This implementation will then loop over the entire PDF file to find obj declaration statements.
    N)HighLevelTokenizer)Name)	Reference)PlainTextXREF)XREFc                	   @   sF   e Zd ZdZ	d
dejejejej	f de
deje ddfdd	ZdS )RebuiltXREFa  
    The cross-reference table contains information that permits random access to indirect objects within the file so
    that the entire file need not be read to locate any particular object.
    This implementation of PlainTextXREF is invoked whenever the XREF could not be loaded properly.
    This implementation will then loop over the entire PDF file to find obj declaration statements.
    Nsrctokinitial_offsetreturnr   c           	      C   s  t d | }|d d}d}| }|dusJ d|t|k r5d||   kr1dkrn nf||d  dkrd||d	    krIdkrn nN||d
  dkr||d  dkr||d  dkr||d  dkrt d|| d ||d  d |f  | jt	|| d ||d	  d |d |d7 }qd||   krdkr9n nd||d    krdkr9n n||d	  dkr9d||d
    krdkr9n nf||d  dkr9||d  dkr9||d  dkr9||d  dkr9t d|| d d ||d  d  ||d
  d |f  | jt	|| d d ||d  d  ||d
  d |d |d7 }qd||   krGdkrn nd||d    krYdkrn nd||d	    krkdkrn n||d
  dkrd||d    krdkrn nd||d  dkr||d  dkr||d  dkr||d  dkr|| d d ||d  d d  ||d	  d  }t d|||d  d |f  | jt	|||d  d |d |d7 }q|| dkr+||d  dkr+||d	  dkr+||d
  dkr+||d  dkr+||d  dkr+||d  dkr+|}|d7 }|t|k s%|dus<J || | 
||| td< | td |  || | S )z
        This method attempts to read a plaintext XREF from the given io_source.
        It will either throw an exception, or return this XREF
        z!Switching to RebuiltXREF parsing.r   NzIrebuilding an XREF is only possible if all the bytes of the PDF are known0   9                   o      b      j   z%d %d obj at %d)object_numbergeneration_numberbyte_offset   
      d   	   t   r   a   i   l   e   Trailer)loggerinfotellseekreadlendebug_entriesappendr   _read_trailerr   
set_parent)	selfr   r	   r
   
pos_beforeitrailer_posbytes_in_pdfobj_nr r8   N/home/ubuntu/.local/lib/python3.10/site-packages/borb/pdf/xref/rebuilt_xref.pyr+   +   s   


 
"" $$$ c

zRebuiltXREF.read)N)__name__
__module____qualname____doc__typingUnionioBufferedIOBase	RawIOBaseBytesIOr   Optionalintr+   r8   r8   r8   r9   r      s    r   )r=   r@   loggingr>   *borb.io.read.tokenize.high_level_tokenizerr   borb.io.read.typesr   r   borb.pdf.xref.plaintext_xrefr   borb.pdf.xref.xrefr   	getLoggerr:   r'   r   r8   r8   r8   r9   <module>   s   
