a
    ˜ëj~  ã                   @   sæ  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	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 ddlmZ ddlmZmZmZ ddl m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z' dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0e+de,de-de.de0de/diZ1e 2dej3¡Z4ed ƒZ5d!e*› d"e+› d#e,› d$e-› d%e.› d&e0› d'e/› d(�Z6e5e5d)œd*d+„Z7e8ejd)œd,d-„Z9eje8d)œd.d/„Z:e7fed0e8e
e	ge	f ee;e8  d1œd2d3„Z<G d4d5„ d5eƒZ=G d6d0„ d0e&ƒZ>dS )7z~
Anything related to Extensible Metadata Platform (XMP) metadata.

https://en.wikipedia.org/wiki/Extensible_Metadata_Platform
é    N)ÚIterator©Ú	hexdigits)ÚAnyÚCallableÚOptionalÚTypeVarÚUnionÚcast)ÚExpatBuilderNS)ÚDocument)ÚElement)ÚOptions)Ú
ExpatErrorÚXMLParserTypeé   )Úget_configuration)Ú
StreamTypeÚdeprecate_with_replacementÚdeprecation_no_replacement)ÚLimitReachedErrorÚPdfReadErrorÚXmpDocumentError)ÚContentStreamÚ	PdfObjectÚStreamObjecti@KL i † z+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/zhttp://www.aiim.org/pdfa/ns/id/ÚdcÚxmpZpdfZxmpMMZpdfaidZpdfxa{  
        (?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})
                )?
            )?
        )?
        ÚKuƒ   <?xpacket begin="ï»¿" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="pypdf">
    <rdf:RDF xmlns:rdf="z?">
        <rdf:Description rdf:about=""
            xmlns:dc="z"
            xmlns:xmp="z"
            xmlns:pdf="z"
            xmlns:xmpMM="z"
            xmlns:pdfaid="z"
            xmlns:pdfx="zM">
        </rdf:Description>
    </rdf:RDF>
</x:xmpmeta>
<?xpacket end="r"?>©ÚvalueÚreturnc                 C   s   | S ©N© ©r    r#   r#   úH/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pypdf/xmp.pyÚ	_identityp   s    r&   c              
   C   sp  t  | ¡}|d u r td| › �ƒ‚t| d¡ƒ}t| d¡p<dƒ}t| d¡pNdƒ}t| d¡p`dƒ}t| d¡prdƒ}t | d	¡p†d¡}| tj¡}|| d
 }	t|ƒ}
t|	ƒ}| d¡p¾d}zt	 	||||||
|¡}W n< t�y } z"td| ›d|› �ƒ|‚W Y d }~n
d }~0 0 |dk�rldd„ |dd …  
d¡D ƒ\}}t	j||d�}| d¡�rd|| n|| }|S )NzInvalid date format: ÚyearÚmonthÚ1ÚdayÚhourÚ0ÚminuteÚsecondi@B ÚtzdÚZzInvalid date z: c                 s   s   | ]}t |ƒV  qd S r"   )Úint)Ú.0Úxr#   r#   r%   Ú	<genexpr>Š   ó    z"_converter_date.<locals>.<genexpr>r   ú:)ÚhoursÚminutesú+)Úiso8601ÚmatchÚ
ValueErrorr1   ÚgroupÚdecimalÚDecimalÚto_integralÚROUND_FLOORÚdatetimeÚsplitÚ	timedeltaÚ
startswith)r    Úmatchesr'   r(   r*   r+   r-   r.   Zseconds_decZmilliseconds_decÚsecondsZmillisecondsr/   ÚdtÚexcZ	tzd_hoursZtzd_minutesÚoffsetr#   r#   r%   Ú_converter_datet   s.    
,
 rK   c                 C   s:   | j dur$|  ¡ dur$|  tjj¡} | jdd�} |  d¡S )z‰Format a datetime as UTC with trailing 'Z'.

    - If the input is timezone-aware, convert to UTC first.
    - If naive, assume UTC.
    N)Útzinfoz%Y-%m-%dT%H:%M:%S.%fZ)rL   Ú	utcoffsetÚ
astimezonerB   ÚtimezoneÚutcÚreplaceÚstrftimer$   r#   r#   r%   Ú_format_datetime_utc�   s    rS   ÚXmpInformation)ÚelementÚselfÚ	list_typeÚ	converterr!   c           	      C   sX   |   t|¡}g }t|ƒrT|D ]2}|  td¡D ] }| |¡}||ƒ}| |¡ q,q|S d S )NÚli)ÚgetElementsByTagNameNSÚRDF_NAMESPACEÚlenÚ	_get_textÚappend)	rU   rV   rW   rX   Z
containersÚretvalÚ	containerÚitemr    r#   r#   r%   Ú_generic_get�   s    
rb   c                	       sˆ   e Zd ZdZdee ddœ‡ fdd„Zeeee ee eee ee ddœdd„Z	ee
e dd	œ‡ fd
d„Zeddœ‡ fdd„Z‡  ZS )Ú_XmpBuilderac  
    Custom XML parser denying all entity declarations.

    This is a stripped down and typed version inspired by what *defusedxml* does.

    Why do we need this? The default limits of *libexpat* used by Python only block exponential entity expansion,
    but not cases like quadratic entity expansion which can still cause quite some memory usage.
    N)Úoptionsr!   c                    s    t ƒ j|d� d| _tƒ | _d S )N)rd   r   )ÚsuperÚ__init__Ú_element_countr   Ú_configuration)rV   rd   ©Ú	__class__r#   r%   rf   ¶   s    z_XmpBuilder.__init__)Úentity_nameÚis_parameter_entityr    ÚbaseÚ	system_idÚ	public_idÚnotation_namer!   c                 C   s   t d|›�ƒ‚d S )NzForbidden entities: )r   )rV   rk   rl   r    rm   rn   ro   rp   r#   r#   r%   Ú!custom_entity_declaration_handler»   s    z-_XmpBuilder.custom_entity_declaration_handler)ÚnameÚ
attributesr!   c                    sD   |  j d7  _ | j | jjkr0td| jj› d�ƒ‚tƒ j||d� d S )Nr   zXMP metadata exceeds limit of z
 elements.)rr   rs   )rg   rh   Zxmp_maximum_element_countr   re   Ústart_element_handler)rV   rr   rs   ri   r#   r%   rt   É   s    ÿz!_XmpBuilder.start_element_handler)Úparserr!   c                    s    t ƒ  |¡ | j|_| j|_d S r"   )re   Úinstallrq   ÚEntityDeclHandlerrt   ÚStartElementHandler)rV   ru   ri   r#   r%   rv   Ñ   s    z_XmpBuilder.install)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   rf   ÚstrÚboolrq   Úlistrt   r   rv   Ú__classcell__r#   r#   ri   r%   rc   ¬   s   	õrc   c                   @   sJ  e Zd ZdZeddœdd„Zed dœdd„ƒZd†ee	e
edf dd	œd
d„Ze
e
e
ee dœdd„Ze
e
ee dœdd„Zee
dœdd„Zefe
e
ee
gef ee dœdd„Ze
e
eee
  dœdd„Zefe
e
eegef eee  dœdd„Ze
e
eeeef  dœdd„Zeeee
  dœdd „ƒZejeee
  dd!œd"d „ƒZeee
 dœd#d$„ƒZejee
 dd%œd&d$„ƒZeeee
  dœd'd(„ƒZ e jeee
  dd!œd)d(„ƒZ eeee!j!  dœd*d+„ƒZ"e"jeee	e
e!j!f   dd!œd,d+„ƒZ"eeee
e
f  dœd-d.„ƒZ#e#jeee
e
f  dd!œd/d.„ƒZ#eee
 dœd0d1„ƒZ$e$jee
 dd%œd2d1„ƒZ$eee
 dœd3d4„ƒZ%e%jee
 dd%œd5d4„ƒZ%eeee
  dœd6d7„ƒZ&e&jeee
  dd!œd8d7„ƒZ&eeee
  dœd9d:„ƒZ'e'jeee
  dd!œd;d:„ƒZ'eeee
  dœd<d=„ƒZ(e(jeee
  dd!œd>d=„ƒZ(eeee
e
f  dœd?d@„ƒZ)e)jeee
e
f  dd!œdAd@„ƒZ)eee
 dœdBdC„ƒZ*e*jee
 dd%œdDdC„ƒZ*eeee
  dœdEdF„ƒZ+e+jeee
  dd!œdGdF„ƒZ+eeee
e
f  dœdHdI„ƒZ,e,jeee
e
f  dd!œdJdI„ƒZ,eeee
  dœdKdL„ƒZ-e-jeee
  dd!œdMdL„ƒZ-eee
 dœdNdO„ƒZ.e.jee
 dd%œdPdO„ƒZ.eee
 dœdQdR„ƒZ/e/jee
 dd%œdSdR„ƒZ/eee
 dœdTdU„ƒZ0e0jee
 dd%œdVdU„ƒZ0eee!j! dœdWdX„ƒZ1e1jee!j! dd%œdYdX„ƒZ1eee!j! dœdZd[„ƒZ2e2jee!j! dd%œd\d[„ƒZ2eee!j! dœd]d^„ƒZ3e3jee!j! dd%œd_d^„ƒZ3eee
 dœd`da„ƒZ4e4jee
 dd%œdbda„ƒZ4eee
 dœdcdd„ƒZ5e5jee
 dd%œdedd„ƒZ5eee
 dœdfdg„ƒZ6e6jee
 dd%œdhdg„ƒZ6eee
 dœdidj„ƒZ7e7jee
 dd%œdkdj„ƒZ7eee
 dœdldm„ƒZ8e8jee
 dd%œdndm„ƒZ8eeeef dœdodp„ƒZ9d‡e
edrœdsdt„Z:e
e
ddœdudv„Z;e
e
ee
 ddwœdxdy„Z<e
e
eee
  ddzœd{d|„Z=e
e
eee
  ddzœd}d~„Z>e
e
eee
e
f  ddzœdd€„Z?e
e
d�œd‚dƒ„Z@ddœd„d…„ZAdS )ˆrT   zÕ
    An object that represents Extensible Metadata Platform (XMP) metadata.
    Usually accessed by :py:attr:`xmp_metadata()<pypdf.PdfReader.xmp_metadata>`.

    Raises:
      PdfReadError: if XML is invalid

    N)Ústreamr!   c              
   C   s¶   || _ zJ| j  ¡ }tƒ }t|ƒ }|jkrBtd|› d|j› d�ƒ‚tƒ  |¡}W n8 tt	fyˆ } zt
d|› �ƒ|‚W Y d }~n
d }~0 0 | td¡}|s¢t
dƒ‚|d | _i | _d S )NzXMP stream size z exceeds limit of Ú.z#XML in XmpInformation was invalid: ZRDFz?XML in XmpInformation was invalid: Missing rdf:RDF root elementr   )r�   Úget_datar   r\   Zxmp_maximum_input_lengthr   rc   ÚparseStringÚAttributeErrorr   r   rZ   r[   Úrdf_rootÚcache)rV   r�   ÚdataÚconfigurationÚlengthZdoc_rootÚ	exceptionZ	rdf_rootsr#   r#   r%   rf   â   s$    
ÿ&ÿ
zXmpInformation.__init__)r!   c                 C   s"   t ddƒ}| t d¡¡ | |ƒS )z¤
        Create a new XmpInformation object with minimal structure.

        Returns:
            A new XmpInformation instance with empty metadata fields.
        Núutf-8)r   Úset_dataÚ_MINIMAL_XMPÚencode)Úclsr�   r#   r#   r%   Úcreateö   s    
zXmpInformation.create)r�   Úencryption_keyr!   c                 C   s.   t dddƒ |d urtddƒ | j |¡ d S )NúXmpInformation.write_to_streamzPdfWriter.xmp_metadataz6.0.0z/the encryption_key parameter of write_to_streamz5.0.0)r   r   r�   Úwrite_to_stream)rV   r�   r’   r#   r#   r%   r”     s    ýÿr“   )Ú	about_uriÚ	namespacerr   r!   c                 c   sT   | j  td¡D ]@}| td¡|kr| ||¡}|d ur<|V  | ||¡E d H  qd S ©NÚDescriptionÚabout)r†   rZ   r[   ÚgetAttributeNSÚgetAttributeNodeNS)rV   r•   r–   rr   ÚdescÚattrr#   r#   r%   Úget_element  s    zXmpInformation.get_element)r•   r–   r!   c                 c   sv   | j  td¡D ]b}| td¡|krt|jjƒD ]$}|j |¡}|r.|j|kr.|V  q.|j	D ]}|j|krZ|V  qZqd S r—   )
r†   rZ   r[   rš   Úrangers   rŠ   ra   ZnamespaceURIÚ
childNodes)rV   r•   r–   rœ   Úir�   Úchildr#   r#   r%   Úget_nodes_in_namespace  s    

z%XmpInformation.get_nodes_in_namespace)rU   r!   c                 C   s*   d}|j D ]}|j|jkr
||j7 }q
|S ©NÚ )r    ÚnodeTypeZ	TEXT_NODErˆ   )rV   rU   Útextr¢   r#   r#   r%   r]   #  s
    
zXmpInformation._get_text)r–   rr   rX   r!   c                 C   s€   | j  |i ¡ |¡}|r|S d }|  d||¡D ]&}|j|jkrF|j}n
|  |¡} qVq.|d urf||ƒ}| j  |i ¡}|||< |S r¤   )r‡   Úgetrž   r¦   ÚATTRIBUTE_NODEÚ	nodeValuer]   Ú
setdefault)rV   r–   rr   rX   Úcachedr    rU   Úns_cacher#   r#   r%   Ú_get_single_value*  s    
z XmpInformation._get_single_value)r–   rr   r!   c           	      C   sŽ   | j  |i ¡ |¡}|r&ttt |ƒS g }|  d||¡D ]:}t|| dd� }d ur^| |¡ q8|  |¡}| 	|¡ q8| j  
|i ¡}|||< |S )Nr¥   ÚBag©rW   )r‡   r¨   r
   r   r}   rž   rb   Úextendr]   r^   r«   )	rV   r–   rr   r¬   r_   rU   Úbagsr    r­   r#   r#   r%   Ú_getter_bag@  s    
zXmpInformation._getter_bagc                 C   s¶   | j  |i ¡ |¡}|r&ttt |ƒS g }|  d||¡D ]b}t|| d|d� }d ur`| |¡ q8t|| dd� }d ur‚| |¡ q8||  |¡ƒ}	| 	|	¡ q8| j  
|i ¡}
||
|< |S )Nr¥   ZSeq)rW   rX   r¯   r°   )r‡   r¨   r
   r   r   rž   rb   r±   r]   r^   r«   )rV   r–   rr   rX   r¬   r_   rU   Zseqsr²   r    r­   r#   r#   r%   Ú_get_seq_valuesO  s    zXmpInformation._get_seq_valuesc                 C   s´   | j  |i ¡ |¡}|r*ttttf |ƒS i }|  d||¡D ]\}| td¡}t|ƒrŠ|D ].}| td¡D ]}|  	|¡}	|	|| 
d¡< qhqXq<|  	|¡|d< q<| j  |i ¡}
||
|< |S )Nr¥   ZAltrY   úxml:langz	x-default)r‡   r¨   r
   Údictr   rž   rZ   r[   r\   r]   ÚgetAttributer«   )rV   r–   rr   r¬   r_   rU   ZaltsÚaltra   r    r­   r#   r#   r%   Ú_get_langalt_valuesl  s    
z"XmpInformation._get_langalt_valuesc                 C   s   |   td¡S )z6Contributors to the resource (other than the authors).Úcontributor©r³   ÚDC_NAMESPACE©rV   r#   r#   r%   Údc_contributor~  s    zXmpInformation.dc_contributor)Úvaluesr!   c                 C   s   |   td|¡ d S )Nrº   ©Ú_set_bag_valuesr¼   ©rV   r¿   r#   r#   r%   r¾   ƒ  s    c                 C   s   |   td¡S )z4Text describing the extent or scope of the resource.Úcoverage©r®   r¼   r½   r#   r#   r%   Údc_coverage‡  s    zXmpInformation.dc_coverager   c                 C   s   |   td|¡ d S )NrÃ   ©Ú_set_single_valuer¼   ©rV   r    r#   r#   r%   rÅ   Œ  s    c                 C   s   |   td¡S )zVA sorted array of names of the authors of the resource, listed in order of precedence.Úcreator)r´   r¼   r½   r#   r#   r%   Ú
dc_creator�  s    zXmpInformation.dc_creatorc                 C   s   |   td|¡ d S )NrÉ   )Ú_set_seq_valuesr¼   rÂ   r#   r#   r%   rÊ   •  s    c                 C   s   |   tdt¡S )zXA sorted array of dates of significance to the resource. The dates and times are in UTC.Údate)r´   r¼   rK   r½   r#   r#   r%   Údc_date™  s    zXmpInformation.dc_datec                 C   sb   |d u r|   tdd ¡ nFg }|D ].}t|tjƒr@| t|ƒ¡ q | t|ƒ¡ q |   td|¡ d S )NrÌ   )rË   r¼   Ú
isinstancerB   r^   rS   r}   )rV   r¿   Zdate_stringsr    r#   r#   r%   rÍ   ž  s    c                 C   s   |   td¡S )zSA language-keyed dictionary of textual descriptions of the content of the resource.Údescription©r¹   r¼   r½   r#   r#   r%   Údc_description«  s    zXmpInformation.dc_descriptionc                 C   s   |   td|¡ d S )NrÏ   ©Ú_set_langalt_valuesr¼   rÂ   r#   r#   r%   rÑ   °  s    c                 C   s   |   td¡S )zThe mime-type of the resource.ÚformatrÄ   r½   r#   r#   r%   Ú	dc_format´  s    zXmpInformation.dc_formatc                 C   s   |   td|¡ d S )NrÔ   rÆ   rÈ   r#   r#   r%   rÕ   ¹  s    c                 C   s   |   td¡S )z"Unique identifier of the resource.Ú
identifierrÄ   r½   r#   r#   r%   Údc_identifier½  s    zXmpInformation.dc_identifierc                 C   s   |   td|¡ d S )NrÖ   rÆ   rÈ   r#   r#   r%   r×   Â  s    c                 C   s   |   td¡S )zAAn unordered array specifying the languages used in the resource.Úlanguager»   r½   r#   r#   r%   Údc_languageÆ  s    zXmpInformation.dc_languagec                 C   s   |   td|¡ d S )NrØ   rÀ   rÂ   r#   r#   r%   rÙ   Ë  s    c                 C   s   |   td¡S )z&An unordered array of publisher names.Ú	publisherr»   r½   r#   r#   r%   Údc_publisherÏ  s    zXmpInformation.dc_publisherc                 C   s   |   td|¡ d S )NrÚ   rÀ   rÂ   r#   r#   r%   rÛ   Ô  s    c                 C   s   |   td¡S )zLAn unordered array of text descriptions of relationships to other documents.Úrelationr»   r½   r#   r#   r%   Údc_relationØ  s    zXmpInformation.dc_relationc                 C   s   |   td|¡ d S )NrÜ   rÀ   rÂ   r#   r#   r%   rÝ   Ý  s    c                 C   s   |   td¡S )z`A language-keyed dictionary of textual descriptions of the rights the user has to this resource.ÚrightsrÐ   r½   r#   r#   r%   Ú	dc_rightsá  s    zXmpInformation.dc_rightsc                 C   s   |   td|¡ d S )NrÞ   rÒ   rÂ   r#   r#   r%   rß   æ  s    c                 C   s   |   td¡S )zCUnique identifier of the work from which this resource was derived.ÚsourcerÄ   r½   r#   r#   r%   Ú	dc_sourceê  s    zXmpInformation.dc_sourcec                 C   s   |   td|¡ d S )Nrà   rÆ   rÈ   r#   r#   r%   rá   ï  s    c                 C   s   |   td¡S )z\An unordered array of descriptive phrases or keywords that specify the topic of the content.Úsubjectr»   r½   r#   r#   r%   Ú
dc_subjectó  s    zXmpInformation.dc_subjectc                 C   s   |   td|¡ d S )Nrâ   rÀ   rÂ   r#   r#   r%   rã   ø  s    c                 C   s   |   td¡S )z9A language-keyed dictionary of the title of the resource.ÚtitlerÐ   r½   r#   r#   r%   Údc_titleü  s    zXmpInformation.dc_titlec                 C   s   |   td|¡ d S )Nrä   rÒ   rÂ   r#   r#   r%   rå     s    c                 C   s   |   td¡S )z@An unordered array of textual descriptions of the document type.Útyper»   r½   r#   r#   r%   Údc_type  s    zXmpInformation.dc_typec                 C   s   |   td|¡ d S )Nræ   rÀ   rÂ   r#   r#   r%   rç   
  s    c                 C   s   |   td¡S )z:An unformatted text string representing document keywords.ÚKeywords©r®   ÚPDF_NAMESPACEr½   r#   r#   r%   Úpdf_keywords  s    zXmpInformation.pdf_keywordsc                 C   s   |   td|¡ d S )Nrè   ©rÇ   rê   rÈ   r#   r#   r%   rë     s    c                 C   s   |   td¡S )z-The PDF file version, for example 1.0 or 1.3.Ú
PDFVersionré   r½   r#   r#   r%   Úpdf_pdfversion  s    zXmpInformation.pdf_pdfversionc                 C   s   |   td|¡ d S )Nrí   rì   rÈ   r#   r#   r%   rî     s    c                 C   s   |   td¡S )z6The name of the tool that saved the document as a PDF.ÚProducerré   r½   r#   r#   r%   Úpdf_producer   s    zXmpInformation.pdf_producerc                 C   s   |   td|¡ d S )Nrï   rì   rÈ   r#   r#   r%   rð   %  s    c                 C   s   |   tdt¡S )zYThe date and time the resource was originally created. Returned as a UTC datetime object.Ú
CreateDate©r®   ÚXMP_NAMESPACErK   r½   r#   r#   r%   Úxmp_create_date)  s    zXmpInformation.xmp_create_datec                 C   s.   |rt |ƒ}|  td|¡ n|  tdd ¡ d S )Nrñ   ©rS   rÇ   ró   ©rV   r    Zdate_strr#   r#   r%   rô   .  s    c                 C   s   |   tdt¡S )zTThe date and time the resource was last modified. Returned as a UTC datetime object.Ú
ModifyDaterò   r½   r#   r#   r%   Úxmp_modify_date6  s    zXmpInformation.xmp_modify_datec                 C   s.   |rt |ƒ}|  td|¡ n|  tdd ¡ d S )Nr÷   rõ   rö   r#   r#   r%   rø   ;  s    c                 C   s   |   tdt¡S )zjThe date and time that any metadata for this resource was last changed. Returned as a UTC datetime object.ÚMetadataDaterò   r½   r#   r#   r%   Úxmp_metadata_dateC  s    z XmpInformation.xmp_metadata_datec                 C   s.   |rt |ƒ}|  td|¡ n|  tdd ¡ d S )Nrù   rõ   rö   r#   r#   r%   rú   H  s    c                 C   s   |   td¡S )z=The name of the first known tool used to create the resource.ÚCreatorTool)r®   ró   r½   r#   r#   r%   Úxmp_creator_toolP  s    zXmpInformation.xmp_creator_toolc                 C   s   |   td|¡ d S )Nrû   )rÇ   ró   rÈ   r#   r#   r%   rü   U  s    c                 C   s   |   td¡S )zGThe common identifier for all versions and renditions of this resource.Ú
DocumentID©r®   ÚXMPMM_NAMESPACEr½   r#   r#   r%   Úxmpmm_document_idY  s    z XmpInformation.xmpmm_document_idc                 C   s   |   td|¡ d S )Nrý   ©rÇ   rÿ   rÈ   r#   r#   r%   r   ^  s    c                 C   s   |   td¡S )zZAn identifier for a specific incarnation of a document, updated each time a file is saved.Ú
InstanceIDrþ   r½   r#   r#   r%   Úxmpmm_instance_idb  s    z XmpInformation.xmpmm_instance_idc                 C   s   |   td|¡ d S )Nr  r  rÈ   r#   r#   r%   r  g  s    c                 C   s   |   td¡S )zMThe part of the PDF/A standard that the document conforms to (e.g., 1, 2, 3).Úpart©r®   ÚPDFAID_NAMESPACEr½   r#   r#   r%   Úpdfaid_partk  s    zXmpInformation.pdfaid_partc                 C   s   |   td|¡ d S )Nr  ©rÇ   r  rÈ   r#   r#   r%   r  p  s    c                 C   s   |   td¡S )zFThe conformance level within the PDF/A standard (e.g., 'A', 'B', 'U').Úconformancer  r½   r#   r#   r%   Úpdfaid_conformancet  s    z!XmpInformation.pdfaid_conformancec                 C   s   |   td|¡ d S )Nr	  r  rÈ   r#   r#   r%   r
  y  s    c                 C   sâ   t | dƒsÜi | _|  dt¡D ]¾}|j}d}| d|¡}|dkr@q²||d |d … }t|ƒdksrtd	d
„ |D ƒƒs||d }q*|d|… tt	|dd�ƒ ||d d…  }|d }q*|j
|jkrÆ|j}n
|  |¡}|| j|< q| jS )zÎ
        Retrieve custom metadata properties defined in the undocumented pdfx
        metadata schema.

        Returns:
            A dictionary of key/value items for custom metadata properties.

        Ú_custom_propertiesr¥   r   u   â†‚éÿÿÿÿr   é   é   c                 s   s   | ]}|t v V  qd S r"   r   )r2   Úcr#   r#   r%   r4   ’  r5   z3XmpInformation.custom_properties.<locals>.<genexpr>Né   )rm   )Úhasattrr  r£   ÚPDFX_NAMESPACEZ	localNameÚfindr\   ÚallÚchrr1   r¦   r©   rª   r]   )rV   ÚnodeÚkeyÚstartÚidxZhex_idr    r#   r#   r%   Úcustom_properties}  s&    

,

z XmpInformation.custom_propertiesr¥   )r•   r!   c                 C   sn   | j  td¡D ]}| td¡|kr|  S q| j j}|du rDtdƒ‚| td¡}| td|¡ | j  |¡ |S )zBGet or create an rdf:Description element with the given about URI.r˜   r™   NúXMP Document is Nonezrdf:Descriptionz	rdf:about)	r†   rZ   r[   rš   ÚownerDocumentr   ÚcreateElementNSZsetAttributeNSÚappendChild)rV   r•   rœ   Údocr#   r#   r%   Ú_get_or_create_description   s    
z)XmpInformation._get_or_create_descriptionc                 C   s"   | j  |¡}|r||v r||= dS )z<Remove a cached value for a given namespace/name if present.N)r‡   r¨   )rV   r–   rr   r­   r#   r#   r%   Ú_clear_cache_entry®  s    z!XmpInformation._clear_cache_entry)r–   rr   r    r!   c                 C   sÀ   |   ||¡ |  ¡ }t| ||¡ƒ}|D ]}| |¡ q(| ||¡ }rR| |¡ |dur´| jj}|du rrt	dƒ‚|  
|¡}	| ||	› d|› �¡}| t|ƒ¡}
| |
¡ | |¡ |  ¡  dS )z&Set or remove a single metadata value.Nr  r6   )r!  r   r   rZ   ÚremoveChildr›   ZremoveAttributeNoder†   r  r   Ú_get_namespace_prefixr  ÚcreateTextNoder}   r  Ú_update_stream)rV   r–   rr   r    rœ   Úexisting_elementsÚelemZexisting_attrr  ÚprefixÚ	text_noder#   r#   r%   rÇ   ´  s"    



z XmpInformation._set_single_value)r–   rr   r¿   r!   c                 C   sØ   |   ||¡ |  ¡ }t| ||¡ƒ}|D ]}| |¡ q(|rÌ| jj}|du rTtdƒ‚|  |¡}| 	||› d|› �¡}| 	t
d¡}	|D ]2}
| 	t
d¡}| t|
ƒ¡}| |¡ |	 |¡ q„| |	¡ | |¡ |  ¡  dS )z+Set or remove bag values (unordered array).Nr  r6   zrdf:Bagúrdf:li©r!  r   r   rZ   r"  r†   r  r   r#  r  r[   r$  r}   r  r%  )rV   r–   rr   r¿   rœ   r&  r'  r  r(  Zbagr    rY   r)  r#   r#   r%   rÁ   Ì  s(    



zXmpInformation._set_bag_valuesc                 C   sØ   |   ||¡ |  ¡ }t| ||¡ƒ}|D ]}| |¡ q(|rÌ| jj}|du rTtdƒ‚|  |¡}| 	||› d|› �¡}| 	t
d¡}	|D ]2}
| 	t
d¡}| t|
ƒ¡}| |¡ |	 |¡ q„| |	¡ | |¡ |  ¡  dS )z.Set or remove sequence values (ordered array).Nr  r6   zrdf:Seqr*  r+  )rV   r–   rr   r¿   rœ   r&  r'  r  r(  Úseqr    rY   r)  r#   r#   r%   rË   è  s(    



zXmpInformation._set_seq_valuesc                 C   sì   |   ||¡ |  ¡ }t| ||¡ƒ}|D ]}| |¡ q(|rà| jj}|du rTtdƒ‚|  |¡}| 	||› d|› �¡}| 	t
d¡}	| ¡ D ]B\}
}| 	t
d¡}| d|
¡ | t|ƒ¡}| |¡ |	 |¡ qˆ| |	¡ | |¡ |  ¡  dS )z*Set or remove language alternative values.Nr  r6   zrdf:Altr*  rµ   )r!  r   r   rZ   r"  r†   r  r   r#  r  r[   ÚitemsZsetAttributer$  r}   r  r%  )rV   r–   rr   r¿   rœ   r&  r'  r  r(  r¸   Úlangr    rY   r)  r#   r#   r%   rÓ     s*    



z"XmpInformation._set_langalt_values)r–   r!   c                 C   s   t  |d¡S )z?Get the appropriate namespace prefix for a given namespace URI.Úunknown)Ú_NAMESPACE_PREFIX_MAPr¨   )rV   r–   r#   r#   r%   r#  !  s    z$XmpInformation._get_namespace_prefixc                 C   s4   | j j}|du rtdƒ‚|jdd�}| j |¡ dS )z/Update the stream with the current XML content.Nr  rŒ   )Úencoding)r†   r  r   Ztoxmlr�   r�   )rV   r  Úxml_datar#   r#   r%   r%  %  s
    zXmpInformation._update_stream)N)r¥   )Bry   rz   r{   r|   r   rf   Úclassmethodr‘   r   r	   r}   Úbytesr”   r   r   rž   r£   Ú
XmlElementr]   r&   r   r   r®   r   r³   r´   r¶   r¹   Úpropertyr¾   ÚsetterrÅ   rÊ   rB   rÍ   rÑ   rÕ   r×   rÙ   rÛ   rÝ   rß   rá   rã   rå   rç   rë   rî   rð   rô   rø   rú   rü   r   r  r  r
  r  r   r!  rÇ   rÁ   rË   rÓ   r#  r%  r#   r#   r#   r%   rT   Ø   s  	 ÿþüûü
û$" )?r|   rB   r>   ÚreÚcollections.abcr   Ústringr   Útypingr   r   r   r   r	   r
   Zxml.dom.expatbuilderr   Zxml.dom.minidomr   r   r5  Zxml.dom.xmlbuilderr   Úxml.parsers.expatr   r   rh   r   Ú_utilsr   r   r   Úerrorsr   r   r   Zgenericr   r   r   ZXMP_MAX_INPUT_LENGTHZXMP_MAX_ELEMENT_COUNTr[   r¼   ró   rê   rÿ   r  r  r0  ÚcompileÚVERBOSEr:   r   rŽ   r&   r}   rK   rS   r   rb   rc   rT   r#   r#   r#   r%   Ú<module>   sz    ú	ðþüûúùø	÷ÿ
þ,