o
    ë6Wj²G  ã                   @   sÔ  d 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	m
Z
mZmZm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mZmZ dd
lmZ ddlmZmZ dZdZdZ dZ!dZ"dZ#e $dej%¡Z&edƒZ'de'de'fdd„Z(de)dejfdd„Z*de)de)dedge
e	e)  f fdd„Z+e(fde)de)deegef dedge
e	e  f fd d!„Z,de)de)dedge
eeef  f fd"d#„Z-e(fde)de)dee)gef dedge
e f fd$d%„Z.G d&d„ deƒZ/dS )'zc
Anything related to XMP metadata.

See https://en.wikipedia.org/wiki/Extensible_Metadata_Platform
é    N)	ÚAnyÚCallableÚDictÚIteratorÚListÚOptionalÚTypeVarÚUnionÚcast)ÚDocument)ÚElement)ÚparseString)Ú
ExpatErroré   )Ú
StreamTypeÚdeprecate_with_replacementÚdeprecation_with_replacement)ÚPdfReadError)ÚContentStreamÚ	PdfObjectz+http://www.w3.org/1999/02/22-rdf-syntax-ns#z http://purl.org/dc/elements/1.1/zhttp://ns.adobe.com/xap/1.0/zhttp://ns.adobe.com/pdf/1.3/zhttp://ns.adobe.com/xap/1.0/mm/zhttp://ns.adobe.com/pdfx/1.3/a{  
        (?P<year>[0-9]{4})
        (-
            (?P<month>[0-9]{2})
            (-
                (?P<day>[0-9]+)
                (T
                    (?P<hour>[0-9]{2}):
                    (?P<minute>[0-9]{2})
                    (:(?P<second>[0-9]{2}(.[0-9]+)?))?
                    (?P<tzd>Z|[-+][0-9]{2}:[0-9]{2})
                )?
            )?
        )?
        ÚKÚvalueÚreturnc                 C   s   | S ©N© )r   r   r   úY/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/PyPDF2/xmp.pyÚ	_identityU   s   r   c              	   C   s$  t  | ¡}|d u rtd| › �ƒ‚t| d¡ƒ}t| d¡pdƒ}t| d¡p'dƒ}t| d¡p0dƒ}t| d¡p9dƒ}t | d	¡pCd¡}| tj¡}|| d
 }	t|ƒ}
t|	ƒ}| d¡p_d}t	 	||||||
|¡}|dkr�dd„ | 
d¡D ƒ\}}|d9 }|dk r‡|d9 }|t	j||d� }|S )NzInvalid date format: ÚyearÚmonthÚ1ÚdayÚhourÚ0ÚminuteÚsecondi@B ÚtzdÚZc                 s   s   � | ]}t |ƒV  qd S r   )Úint)Ú.0Úxr   r   r   Ú	<genexpr>l   s   € z"_converter_date.<locals>.<genexpr>ú:éÿÿÿÿr   )ÚhoursÚminutes)Úiso8601ÚmatchÚ
ValueErrorr'   ÚgroupÚdecimalÚDecimalÚto_integralÚROUND_FLOORÚdatetimeÚsplitÚ	timedelta)r   Úmatchesr   r   r    r!   r#   r$   Úseconds_decÚmilliseconds_decÚsecondsÚmillisecondsr%   ÚdtÚ	tzd_hoursÚtzd_minutesr   r   r   Ú_converter_dateY   s,   
rB   Ú	namespaceÚnameÚXmpInformationc                    s$   dddt tt  f‡ ‡fdd„}|S )NÚselfrE   r   c           	         s’   | j  ˆi ¡ ˆ ¡}|r|S g }|  dˆˆ ¡D ]$}| td¡}t|ƒr;|D ]}| td¡D ]}|  |¡}| |¡ q-q%q| j  ˆi ¡}||ˆ < |S )NÚ ÚBagÚli©	ÚcacheÚgetÚget_elementÚgetElementsByTagNameNSÚRDF_NAMESPACEÚlenÚ	_get_textÚappendÚ
setdefault)	rF   ÚcachedÚretvalÚelementÚbagsÚbagÚitemr   Úns_cache©rD   rC   r   r   rL   w   s    
þ€z_getter_bag.<locals>.get)r   r   Ústr©rC   rD   rL   r   r[   r   Ú_getter_bagt   s    r^   Ú	converterc                    s&   dddt tt  f‡ ‡‡fdd„}|S )NrF   rE   r   c           	         s´   | j  ˆi ¡ ˆ¡}|r|S g }|  dˆˆ¡D ]5}| td¡}t|ƒr@|D ]}| td¡D ]}|  |¡}ˆ |ƒ}| |¡ q-q%qˆ |  |¡ƒ}| |¡ q| j  ˆi ¡}||ˆ< |S )NrG   ÚSeqrI   rJ   )	rF   rT   rU   rV   ÚseqsÚseqrY   r   rZ   ©r_   rD   rC   r   r   rL   �   s&   
ýÿz_getter_seq.<locals>.get)r   r   r   ©rC   rD   r_   rL   r   rc   r   Ú_getter_seqŠ   s   "re   c                    s(   dddt tttf  f‡ ‡fdd„}|S )NrF   rE   r   c           	         s¦   | j  ˆi ¡ ˆ ¡}|r|S i }|  dˆˆ ¡D ].}| td¡}t|ƒr>|D ]}| td¡D ]}|  |¡}||| d¡< q-q%q|  |¡|d< q| j  ˆi ¡}||ˆ < |S )NrG   ÚAltrI   zxml:langz	x-default)	rK   rL   rM   rN   rO   rP   rQ   ÚgetAttributerS   )	rF   rT   rU   rV   ÚaltsÚaltrY   r   rZ   r[   r   r   rL   §   s"   
þÿz_getter_langalt.<locals>.get)r   r   r   r]   r   r[   r   Ú_getter_langalt¤   s   $rj   c                    s"   dddt t f‡ ‡‡fdd„}|S )NrF   rE   r   c                    s|   | j  ˆi ¡ ˆ¡}|r|S d }|  dˆˆ¡D ]}|j|jkr#|j}n|  |¡} |d ur1ˆ |ƒ}| j  ˆi ¡}||ˆ< |S ©NrG   )rK   rL   rM   ÚnodeTypeÚATTRIBUTE_NODEÚ	nodeValuerQ   rS   )rF   rT   r   rV   rZ   rc   r   r   rL   ¿   s   
z_getter_single.<locals>.get)r   r   rd   r   rc   r   Ú_getter_single¼   s   ro   c                	   @   s   e Zd ZdZdeddfd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edededee fdd„Zdedededee fdd„Zdededee fdd„Zdededee fdd„Zdedefdd„ZeeedƒƒZ	 eeedƒƒZ	 eeedƒƒZ	 eeed eƒƒZ	 eeed!ƒƒZ 	 eeed"ƒƒZ!	 eeed#ƒƒZ"	 eeed$ƒƒZ#	 eeed%ƒƒZ$	 eeed&ƒƒZ%	 eeed'ƒƒZ&	 eeed(ƒƒZ'	 eeed)ƒƒZ(	 eeed*ƒƒZ)	 eeed+ƒƒZ*	 eee+d,ƒƒZ,	 eee+d-ƒƒZ-	 eee+d.ƒƒZ.	 eee/d/eƒƒZ0	 ede1j1fd0d1„ƒZ2e2j3d2e1j1ddfd3d1„ƒZ2eee/d4eƒƒZ4	 ede1j1fd5d6„ƒZ5e5j3d2e1j1ddfd7d6„ƒZ5eee/d8eƒƒZ6	 ede1j1fd9d:„ƒZ7e7j3d2e1j1ddfd;d:„ƒZ7eee/d<ƒƒZ8	 edefd=d>„ƒZ9e9j3d2eddfd?d>„ƒZ9eee:d@ƒƒZ;	 edefdAdB„ƒZ<e<j3d2eddfdCdB„ƒZ<eee:dDƒƒZ=	 edefdEdF„ƒZ>e>j3d2eddfdGdF„ƒZ>ede?eef fdHdI„ƒZ@dS )JrE   zµ
    An object that represents Adobe XMP metadata.
    Usually accessed by :py:attr:`xmp_metadata()<PyPDF2.PdfReader.xmp_metadata>`

    :raises PdfReadError: if XML is invalid
    Ústreamr   Nc              
   C   s`   || _ z| j  ¡ }t|ƒ}W n ty! } ztd|› �ƒ‚d }~ww | td¡d | _i | _d S )Nz#XML in XmpInformation was invalid: ÚRDFr   )	rp   Úget_datar   r   r   rN   rO   Úrdf_rootrK   )rF   rp   ÚdataÚdoc_rootÚer   r   r   Ú__init__Û   s   
€ÿÿþ
zXmpInformation.__init__c                 C   ó   t dddƒ | jS )NÚrdfRootrs   ú4.0.0)r   rs   ©rF   r   r   r   ry   ç   ó   zXmpInformation.rdfRootÚencryption_keyc                 C   s   | j  ||¡ d S r   )rp   Úwrite_to_stream©rF   rp   r}   r   r   r   r~   ì   s   zXmpInformation.write_to_streamc                 C   s   t dddƒ |  ||¡ dS )zZ
        .. deprecated:: 1.28.0

            Use :meth:`write_to_stream` instead.
        ÚwriteToStreamr~   ú3.0.0N)r   r~   r   r   r   r   r€   ñ   s   zXmpInformation.writeToStreamÚ	about_urirC   rD   c                 c   sV   � | j  td¡D ] }| td¡|kr(| ||¡}|d ur|V  | ||¡E d H  qd S ©NÚDescriptionÚabout)rs   rN   rO   ÚgetAttributeNSÚgetAttributeNodeNS)rF   r‚   rC   rD   ÚdescÚattrr   r   r   rM   ü   s   €€ûzXmpInformation.get_elementÚaboutUric                 C   s   t dddƒ |  |||¡S )zV
        .. deprecated:: 1.28.0

            Use :meth:`get_element` instead.
        Ú
getElementrM   r�   )r   rM   )rF   rŠ   rC   rD   r   r   r   r‹     s   zXmpInformation.getElementc                 c   st   � | j  td¡D ]/}| td¡|kr7t|jjƒD ]}|j |¡}|j|kr(|V  q|j	D ]
}|j|kr6|V  q,qd S rƒ   )
rs   rN   rO   r†   ÚrangeÚ
attributesÚlengthrY   ÚnamespaceURIÚ
childNodes)rF   r‚   rC   rˆ   Úir‰   Úchildr   r   r   Úget_nodes_in_namespace  s   €
€

€øz%XmpInformation.get_nodes_in_namespacec                 C   s   t dddƒ |  ||¡S )za
        .. deprecated:: 1.28.0

            Use :meth:`get_nodes_in_namespace` instead.
        ÚgetNodesInNamespacer“   r�   )r   r“   )rF   rŠ   rC   r   r   r   r”     s   ÿz"XmpInformation.getNodesInNamespacerV   c                 C   s*   d}|j D ]}|j|jkr||j7 }q|S rk   )r�   rl   Ú	TEXT_NODErt   )rF   rV   Útextr’   r   r   r   rQ   '  s   

€zXmpInformation._get_textÚcontributorÚcoverageÚcreatorÚdateÚdescriptionÚformatÚ
identifierÚlanguageÚ	publisherÚrelationÚrightsÚsourceÚsubjectÚtitleÚtypeÚKeywordsÚ
PDFVersionÚProducerÚ
CreateDatec                 C   rx   ©NÚxmp_createDateÚxmp_create_daterz   ©r   r¬   r{   r   r   r   r«   —  r|   zXmpInformation.xmp_createDater   c                 C   ó   t dddƒ || _d S rª   r­   ©rF   r   r   r   r   r«   œ  ó   
Ú
ModifyDatec                 C   rx   ©NÚxmp_modifyDateÚxmp_modify_daterz   ©r   r´   r{   r   r   r   r³   ©  r|   zXmpInformation.xmp_modifyDatec                 C   r®   r²   rµ   r¯   r   r   r   r³   ®  r°   ÚMetadataDatec                 C   rx   ©NÚxmp_metadataDateÚxmp_metadata_daterz   ©r   r¹   r{   r   r   r   r¸   ¼  r|   zXmpInformation.xmp_metadataDatec                 C   r®   r·   rº   r¯   r   r   r   r¸   Á  r°   ÚCreatorToolc                 C   rx   ©NÚxmp_creatorToolÚxmp_creator_toolr�   ©r   r¾   r{   r   r   r   r½   É  r|   zXmpInformation.xmp_creatorToolc                 C   r®   r¼   r¿   r¯   r   r   r   r½   Î  r°   Ú
DocumentIDc                 C   rx   ©NÚxmpmm_documentIdÚxmpmm_document_idr�   ©r   rÃ   r{   r   r   r   rÂ   Ø  r|   zXmpInformation.xmpmm_documentIdc                 C   r®   rÁ   rÄ   r¯   r   r   r   rÂ   Ý  r°   Ú
InstanceIDc                 C   s   t dddƒ tt| jƒS ©NÚxmpmm_instanceIdÚxmpmm_instance_idr�   )r   r
   r\   rÈ   r{   r   r   r   rÇ   è  s   zXmpInformation.xmpmm_instanceIdc                 C   r®   rÆ   )r   rÈ   r¯   r   r   r   rÇ   í  r°   c                 C   sª   t | dƒsRi | _|  dt¡D ]C}|j}	 | d¡}|dkrn|d|… tt||d |d … d	d
�ƒ ||d d…  }q|j|j	krG|j
}n|  |¡}|| j|< q| jS )zÁ
        Retrieve custom metadata properties defined in the undocumented pdfx
        metadata schema.

        :return: a dictionary of key/value items for custom metadata properties.
        Ú_custom_propertiesrG   Tu   â†‚r,   Nr   é   é   )Úbase)ÚhasattrrÉ   r“   ÚPDFX_NAMESPACEÚ	localNameÚfindÚchrr'   rl   rm   rn   rQ   )rF   ÚnodeÚkeyÚidxr   r   r   r   Úcustom_propertiesò  s(   


ÿþÿû

z XmpInformation.custom_properties)AÚ__name__Ú
__module__Ú__qualname__Ú__doc__r   rw   ÚpropertyÚ
XmlElementry   r   r	   r\   Úbytesr~   r€   r   r   rM   r‹   r“   r”   rQ   r^   ÚDC_NAMESPACEÚdc_contributorro   Údc_coveragere   Ú
dc_creatorrB   Údc_daterj   Údc_descriptionÚ	dc_formatÚdc_identifierÚdc_languageÚdc_publisherÚdc_relationÚ	dc_rightsÚ	dc_sourceÚ
dc_subjectÚdc_titleÚdc_typeÚPDF_NAMESPACEÚpdf_keywordsÚpdf_pdfversionÚpdf_producerÚXMP_NAMESPACEr¬   r7   r«   Úsetterr´   r³   r¹   r¸   r¾   r½   ÚXMPMM_NAMESPACErÃ   rÂ   rÈ   rÇ   r   rÕ   r   r   r   r   rE   Ó   sì    ÿÿ
þÿÿ
þÿÿÿ
þÿÿ
þ
ÿ
ÿ
ÿ)0rÙ   r7   r3   ÚreÚtypingr   r   r   r   r   r   r   r	   r
   Úxml.dom.minidomr   r   rÛ   r   Úxml.parsers.expatr   Ú_utilsr   r   r   Úerrorsr   Úgenericr   r   rO   rÝ   rñ   rí   ró   rÎ   ÚcompileÚVERBOSEr/   r   r   r\   rB   r^   re   rj   ro   rE   r   r   r   r   Ú<module>   sx    ,ðÿÿ
þÿÿÿÿ
þÿÿ
þÿÿÿÿ
þ