o
    ¾Ùøi¢   ã                   @   sÐ   d dl Z d dlZd dlmZmZ d dlmZmZmZ d dl	m
Z
 d dlmZmZmZ d dlmZmZ d dlmZ d dlmZmZmZmZ d d	lmZ d d
lmZmZ e e¡Z edƒZ!edƒZ"G dd„ dƒZ#dS )é    N)Ú	ContainerÚIterator)ÚAnyÚBinaryIOÚClassVar)Úsettings)ÚPDFDocumentÚPDFNoPageLabelsÚPDFTextExtractionNotAllowed)ÚPDFObjectNotFoundÚPDFValueError)Ú	PDFParser)Ú
dict_valueÚ	int_valueÚ
list_valueÚresolve1)ÚLIT)ÚRectÚ
parse_rectÚPageÚPagesc                   @   sô   e Zd ZU dZdededededB ddf
dd	„Zdefd
d„Zh d£Z	e
ee  ed< ededed  fdd„ƒZe					d%dedee dB dededededed  fdd„ƒZdedefdd„Zded edefd!d"„Zdedee fd#d$„ZdS )&ÚPDFPageaz  An object that holds the information about a page.

    A PDFPage object is merely a convenience class that has a set
    of keys and values, which describe the properties of a page
    and point to its contents.

    Attributes
    ----------
      doc: a PDFDocument object.
      pageid: any Python object that can uniquely identify the page.
      attrs: a dictionary of page attributes.
      contents: a list of PDFStream objects that represents the page content.
      lastmod: the last modified time of the page.
      resources: a dictionary of resources used by the page.
      mediabox: the physical size of the page.
      cropbox: the crop rectangle of the page.
      rotate: the page rotation (in degree).
      annots: the page annotations.
      beads: a chain that represents natural reading order.
      label: the page's label (typically, the logical page number).

    ÚdocÚpageidÚattrsÚlabelNÚreturnc                 C   s¾   || _ || _t|ƒ| _|| _t| j d¡ƒ| _t| j di ¡ƒ| _|  	| j d¡¡| _
|  | j d¡| j
¡| _|  | j d¡¡| _t| j dd¡ƒd d | _| j d	¡| _| j d
¡| _dS )zßInitialize a page object.

        doc: a PDFDocument object.
        pageid: any Python object that can uniquely identify the page.
        attrs: a dictionary of page attributes.
        label: page label string.
        ÚLastModifiedÚ	ResourcesÚMediaBoxÚCropBoxÚContentsÚRotater   ih  ÚAnnotsÚBN)r   r   r   r   r   r   ÚgetÚlastmodÚ	resourcesÚ_parse_mediaboxÚmediaboxÚ_parse_cropboxÚcropboxÚ_parse_contentsÚcontentsr   ÚrotateÚannotsÚbeads)Úselfr   r   r   r   © r2   ú]/home/develop/edictos_py/central_edictos/env/lib/python3.10/site-packages/pdfminer/pdfpage.pyÚ__init__1   s   
ÿzPDFPage.__init__c                 C   s   d| j ›d| j›d�S )Nz<PDFPage: Resources=z, MediaBox=ú>)r'   r)   )r1   r2   r2   r3   Ú__repr__P   s   zPDFPage.__repr__>   r"   r    r   r   ÚINHERITABLE_ATTRSÚdocumentc           	      #   s6  � 	 ddt dttt f dtt  d B dttttt tt t f f f  f‡ ‡‡fdd„‰zˆ ¡ }W n ty>   t	 
d ¡}Y nw d}dˆjv rbˆˆjd ˆjƒ}|D ]\}}ˆ ˆ||t|ƒƒV  d	}qQ|s—ˆjD ]1}| ¡ D ](}zˆ |¡}t|tƒr‹| d
¡tu r‹ˆ ˆ||t|ƒƒV  W qm ty•   Y qmw qgd S d S )NÚobjÚparentÚvisitedr   c           	      3   s  � t | tƒr| }tˆ |¡ƒ ¡ }n	| j}t| ƒ ¡ }|d u r"tƒ }||v r(d S | |¡ | ¡ D ]\}}|ˆ j	v rB||vrB|||< q1| 
d¡}|d u rTtjsT| 
d¡}|tu rxd|v rxt d|d ¡ t|d ƒD ]}ˆ|||ƒE d H  qjd S |tu r‰t d|¡ ||fV  d S d S )NÚTypeÚtypeÚKidszPages: Kids=%rzPage: %r)Ú
isinstanceÚintr   ÚgetobjÚcopyÚobjidÚsetÚaddÚitemsr7   r%   r   ÚSTRICTÚLITERAL_PAGESÚlogÚdebugr   ÚLITERAL_PAGE)	r9   r:   r;   Ú	object_idÚobject_propertiesÚkÚvÚobject_typeÚchild©ÚclsÚdepth_first_searchr8   r2   r3   rT   \   s6   €

€

ÿþz0PDFPage.create_pages.<locals>.depth_first_searchFr   Tr<   ©N)r   ÚdictÚstrrD   r   Útupler@   Úget_page_labelsr	   Ú	itertoolsÚrepeatÚcatalogÚnextÚxrefsÚ
get_objidsrA   r?   r%   rK   r   )	rS   r8   Úpage_labelsÚpagesÚobjectsrC   ÚtreeÚxrefr9   r2   rR   r3   Úcreate_pagesZ   sH   €ýÿ
þ
ýü&ÿ


€ÿûýzPDFPage.create_pagesr   Ú TFÚfpÚpagenosÚmaxpagesÚpasswordÚcachingÚcheck_extractablec                 c   s�   � t |ƒ}t|||d�}|js%|rd|›�}	t|	ƒ‚d|›d�}
t |
¡ t|  |¡ƒD ]\}}|r7||vr7q,|V  |rE||d krE d S q,d S )N)rj   rk   z Text extraction is not allowed: zThe PDF z¸ contains a metadata field indicating that it should not allow text extraction. Ignoring this field and proceeding. Use the check_extractable if you want to raise an error in this caseé   )r   r   Úis_extractabler
   rI   ÚwarningÚ	enumeratere   )rS   rg   rh   ri   rj   rk   rl   Úparserr   Ú	error_msgÚwarning_msgÚpagenoÚpager2   r2   r3   Ú	get_pages˜   s$   €

ÿ
€ûzPDFPage.get_pagesÚvaluec                 C   sT   d}|d u rt  d¡ |S ztdd„ t|ƒD ƒƒW S  ty)   t  d¡ | Y S w )N)ç        rx   g      ƒ@g     Àˆ@zHMediaBox missing from /Page (and not inherited), defaulting to US Letterc                 s   ó   � | ]}t |ƒV  qd S rU   ©r   ©Ú.0Úvalr2   r2   r3   Ú	<genexpr>È   ó   € z*PDFPage._parse_mediabox.<locals>.<genexpr>z2Invalid MediaBox in /Page, defaulting to US Letter)rI   ro   r   r   r   )r1   rw   Ú	us_letterr2   r2   r3   r(   ½   s   ÿ
þzPDFPage._parse_mediaboxr)   c                 C   sF   |d u r|S zt dd„ t|ƒD ƒƒW S  ty"   t d¡ | Y S w )Nc                 s   ry   rU   rz   r{   r2   r2   r3   r~   Ô   r   z)PDFPage._parse_cropbox.<locals>.<genexpr>z0Invalid CropBox in /Page, defaulting to MediaBox)r   r   r   rI   ro   )r1   rw   r)   r2   r2   r3   r*   Î   s   
þzPDFPage._parse_cropboxc                 C   s(   g }|d urt |ƒ}t|tƒs|g}|S rU   )r   r?   Úlist)r1   rw   r-   r2   r2   r3   r,   Ú   s   
zPDFPage._parse_contents)Nr   rf   TF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚobjectrW   r4   r6   r7   r   rD   Ú__annotations__Úclassmethodr   re   r   r   r@   Úboolrv   r   r   r(   r*   r�   r,   r2   r2   r2   r3   r      sR   
 þýüû
ú=ùþ
ýüûúùø$r   )$rZ   ÚloggingÚcollections.abcr   r   Útypingr   r   r   Úpdfminerr   Úpdfminer.pdfdocumentr   r	   r
   Úpdfminer.pdfexceptionsr   r   Úpdfminer.pdfparserr   Úpdfminer.pdftypesr   r   r   r   Úpdfminer.psparserr   Úpdfminer.utilsr   r   Ú	getLoggerr‚   rI   rK   rH   r   r2   r2   r2   r3   Ú<module>   s    
