
    mj{                     T   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& dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/e*de+de,de-de/de.diZ0 ejb                  dejd                        Z3 ed       Z4d!e) d"e* d#e+ d$e, d%e- d&e/ d'e. d(Z5d)e4d*e4fd+Z6d)e7d*ej                  fd,Z8d)ej                  d*e7fd-Z9e6fd.ed/d0d1e7d2e
e	ge	f   d*ee:e7      f
d3Z; G d4 d5e      Z< G d6 d0ee&      Z=y)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   )XmpInformationProtocol)
StreamTypedeprecate_with_replacementdeprecation_no_replacement)LimitReachedErrorPdfReadErrorXmpDocumentError)ContentStream	PdfObjecti@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xmppdfxmpMMpdfaid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                     | S N r#   s    </root/.hermes/venv/lib/python3.12/site-packages/pypdf/xmp.py	_identityr*   p   s    L    c           	      0   t         j                  |       }|t        d|        t        |j	                  d            }t        |j	                  d      xs d      }t        |j	                  d      xs d      }t        |j	                  d      xs d      }t        |j	                  d      xs d      }t        j                  |j	                  d	      xs d      }|j                  t
        j                        }||z
  d
z  }	t        |      }
t        |	      }|j	                  d      xs d}t        j                  ||||||
|      }|dk7  rDd |j                  d      D        \  }}|dz  }|dk  r|dz  }|t        j                  ||      z   }|S )NzInvalid date format: yearmonth1dayhour0minutesecondi@B tzdZc              3   2   K   | ]  }t        |        y wr&   )int).0xs     r)   	<genexpr>z"_converter_date.<locals>.<genexpr>   s     !AQ#a&!As   :r   )hoursminutes)iso8601match
ValueErrorr8   groupdecimalDecimalto_integralROUND_FLOORdatetimesplit	timedelta)r#   matchesr-   r.   r0   r1   r3   r4   seconds_decmilliseconds_decsecondsmillisecondsr5   dt	tzd_hourstzd_minutess                   r)   _converter_daterS   t   su   mmE"G0899w}}V$%Dg&-#.E
gmmE")c
*Cw}}V$+,Dx(/C0F__W]]84;<F$$W%8%89K,	9+G'(L
--

%#C			4T67L	QB
cz!A#))C.!A	;R	q=2K($$9kJJIr+   c                     | j                   9| j                         )| j                  t        j                  j
                        } | j                  d      } | j                  d      S )zFormat 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)rU   	utcoffset
astimezonerH   timezoneutcreplacestrftimer(   s    r)   _format_datetime_utcr\      sV     ||EOO$5$A  !2!2!6!67MMM&E>>122r+   elementselfXmpInformation	list_type	converterc                     | j                  t        |      }g }t        |      rN|D ]G  }|j                  t        d      D ],  }|j                  |      } ||      }|j	                  |       . I |S y )Nli)getElementsByTagNameNSRDF_NAMESPACElen	_get_textappend)	r]   r^   r`   ra   
containersretval	containeritemr#   s	            r)   _generic_getrm      s{     //yIJF
:# 	%I!88M %t,!%(e$%	%
 r+   c                        e Zd ZdZddee   ddf fdZdededee   d	ee   d
edee   dee   ddfdZ	dede
e   ddf fdZdeddf fdZ x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                 4    t         |   |       d| _        y )N)rp   r   )super__init___element_count)r^   rp   	__class__s     r)   rs   z_XmpBuilder.__init__   s    )r+   entity_nameis_parameter_entityr#   base	system_id	public_idnotation_namec                     t        d|      )NzForbidden entities: )r   )r^   rv   rw   r#   rx   ry   rz   r{   s           r)   !custom_entity_declaration_handlerz-_XmpBuilder.custom_entity_declaration_handler   s     /?@@r+   name
attributesc                     | xj                   dz  c_         | j                   t        kD  rt        dt         d      t        |   ||       y )Nr   zXMP metadata exceeds limit of z
 elements.)r~   r   )rt   XMP_MAX_ELEMENT_COUNTr   rr   start_element_handler)r^   r~   r   ru   s      r)   r   z!_XmpBuilder.start_element_handler   sM    q !66#&DEZD[[e$fgg%4J%Gr+   parserc                 h    t         |   |       | j                  |_        | j                  |_        y r&   )rr   installr}   EntityDeclHandlerr   StartElementHandler)r^   r   ru   s     r)   r   z_XmpBuilder.install   s+    #'#I#I %)%?%?"r+   r&   )__name__
__module____qualname____doc__r   r   rs   strboolr}   listr   r   r   __classcell__)ru   s   @r)   ro   ro      s      1  T  
A
A "&
A C=	
A
 3-
A 
A  }
A $C=
A 

AH# H49 H H@m @ @ @r+   ro   c                      e Zd ZdZdeddfdZedTd       Z	 dUdede	de
ef   ddfdZd	e
d
e
de
dee   fdZd	e
d
e
dee   fdZdede
fdZefd
e
de
dee
gef   dee   fdZd
e
de
deee
      fdZefd
e
de
deegef   deee      fdZd
e
de
deeeef      fdZedeee
      fd       Zej<                  deee
      ddfd       Zedee
   fd       Zej<                  dee
   ddfd       Zedeee
      fd       Z e j<                  deee
      ddfd       Z edeee!jB                        fd       Z"e"j<                  deee	e
e!jB                  f         ddfd       Z"edeee
e
f      fd       Z#e#j<                  deee
e
f      ddfd        Z#edee
   fd!       Z$e$j<                  dee
   ddfd"       Z$edee
   fd#       Z%e%j<                  dee
   ddfd$       Z%edeee
      fd%       Z&e&j<                  deee
      ddfd&       Z&edeee
      fd'       Z'e'j<                  deee
      ddfd(       Z'edeee
      fd)       Z(e(j<                  deee
      ddfd*       Z(edeee
e
f      fd+       Z)e)j<                  deee
e
f      ddfd,       Z)edee
   fd-       Z*e*j<                  dee
   ddfd.       Z*edeee
      fd/       Z+e+j<                  deee
      ddfd0       Z+edeee
e
f      fd1       Z,e,j<                  deee
e
f      ddfd2       Z,edeee
      fd3       Z-e-j<                  deee
      ddfd4       Z-edee
   fd5       Z.e.j<                  dee
   ddfd6       Z.edee
   fd7       Z/e/j<                  dee
   ddfd8       Z/edee
   fd9       Z0e0j<                  dee
   ddfd:       Z0edee!jB                     fd;       Z1e1j<                  dee!jB                     ddfd<       Z1edee!jB                     fd=       Z2e2j<                  dee!jB                     ddfd>       Z2edee!jB                     fd?       Z3e3j<                  dee!jB                     ddfd@       Z3edee
   fdA       Z4e4j<                  dee
   ddfdB       Z4edee
   fdC       Z5e5j<                  dee
   ddfdD       Z5edee
   fdE       Z6e6j<                  dee
   ddfdF       Z6edee
   fdG       Z7e7j<                  dee
   ddfdH       Z7edee
   fdI       Z8e8j<                  dee
   ddfdJ       Z8edeeef   fdK       Z9dVd	e
defdLZ:d
e
de
ddfdMZ;d
e
de
dee
   ddfdNZ<d
e
de
deee
      ddfdOZ=d
e
de
deee
      ddfdPZ>d
e
de
deee
e
f      ddfdQZ?d
e
de
fdRZ@dWdSZAy)Xr_   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

    streamr$   Nc                    || _         	 | j                   j                         }t        |      x}t        kD  rt	        d| dt         d      t               j                  |      }|j                  t        d      }|st        d      |d   | _        i | _        y # t        t        f$ r}t        d|       d }~ww xY w)NzXMP stream size z exceeds limit of .z#XML in XmpInformation was invalid: RDFz?XML in XmpInformation was invalid: Missing rdf:RDF root elementr   )r   get_datarf   XMP_MAX_INPUT_LENGTHr   ro   parseStringAttributeErrorr   r   rd   re   rdf_rootcache)r^   r   datalengthdoc_roote	rdf_rootss          r)   rs   zXmpInformation.__init__   s    	J;;'')Dd)#';;'*:6(BTUiTjjk(lmm!,!:!:4!@H 33M5I	Q  %.aL%'
 
+ 	J!DQCHII	Js   AB B=*B88B=c                 r    t        dd      }|j                  t        j                  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   s     r)   createzXmpInformation.create   s1     tT*++G456{r+   encryption_keyc                 p    t        ddd       |t        dd       | j                  j                  |       y )Nz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)r^   r   r   s      r)   r   zXmpInformation.write_to_stream   s>     	#,$	

 %&A7 	##F+r+   	about_uri	namespacer~   c              #      K   | j                   j                  t        d      D ]N  }|j                  t        d      |k(  s|j	                  ||      }|| |j                  ||      E d {    P y 7 wNDescriptionabout)r   rd   re   getAttributeNSgetAttributeNodeNS)r^   r   r   r~   descattrs         r)   get_elementzXmpInformation.get_element  sv     MM88V 	HD""=':iG..y$?#J66y$GGG	H
 Hs   =A7 -A7-A5.A7c              #     K   | j                   j                  t        d      D ]  }|j                  t        d      |k(  st	        |j
                  j                        D ]4  }|j
                  j                  |      }|s!|j                  |k(  s1| 6 |j                  D ]  }|j                  |k(  s|   y wr   )
r   rd   re   r   ranger   r   rl   namespaceURI
childNodes)r^   r   r   r   ir   childs          r)   get_nodes_in_namespacez%XmpInformation.get_nodes_in_namespace  s     MM88V 	$D""=':iGt556 #A??//2D 1 1Y >"
# "__ $E))Y6#$	$s   =B> ?B> B>$B>5	B>r]   c                 ~    d}|j                   D ]+  }|j                  |j                  k(  s||j                  z  }- |S N )r   nodeType	TEXT_NODEr   )r^   r]   textr   s       r)   rg   zXmpInformation._get_text  sA    '' 	#E~~0

"	# r+   ra   c                 ^   | j                   j                  |i       j                  |      }|r|S d }| j                  d||      D ]:  }|j                  |j                  k(  r|j
                  }n| j                  |      } n | ||      }| j                   j                  |i       }|||<   |S r   )r   getr   r   ATTRIBUTE_NODE	nodeValuerg   
setdefault)r^   r   r~   ra   cachedr#   r]   ns_caches           r)   _get_single_valuez XmpInformation._get_single_value!  s     	2.2248M''It< 	G7#9#99))w/	 e$E::((B7r+   c                    | j                   j                  |i       j                  |      }|rt        t        t           |      S g }| j                  d||      D ]F  }t        || d      x}|j                  |       %| j                  |      }|j                  |       H | j                   j                  |i       }|||<   |S )Nr   Bagr`   )r   r   r   r   r   r   rm   extendrg   rh   r   )	r^   r   r~   r   rj   r]   bagsr#   r   s	            r)   _getter_bagzXmpInformation._getter_bag7  s    	2.2248S	6**''It< 	%G$WdeDDQd#w/e$	% ::((B7r+   c                    | j                   j                  |i       j                  |      }|rt        t        t           |      S g }| j                  d||      D ]o  }t        || d|      x}|j                  |       &t        || d      x}|j                  |       H || j                  |            }	|j                  |	       q | j                   j                  |i       }
||
|<   |S )Nr   Seq)r`   ra   r   r   )r   r   r   r   r   r   rm   r   rg   rh   r   )r^   r   r~   ra   r   rj   r]   seqsr   r#   r   s              r)   _get_seq_valueszXmpInformation._get_seq_valuesF  s     	2.2248S	6**''It< 	%G$WdeyYYfd#&wFF$S d#!$.."9:e$	% ::((B7r+   c                 
   | j                   j                  |i       j                  |      }|rt        t        t        t        f   |      S i }| j                  d||      D ]  }|j                  t        d      }t        |      rH|D ]B  }|j                  t        d      D ]'  }| j                  |      }	|	||j                  d      <   ) D l| j                  |      |d<    | j                   j                  |i       }
||
|<   |S )Nr   Altrc   xml:langz	x-default)r   r   r   dictr   r   rd   re   rf   rg   getAttributer   )r^   r   r~   r   rj   r]   altsaltrl   r#   r   s              r)   _get_langalt_valuesz"XmpInformation._get_langalt_valuesc  s   	2.2248S#X//!#''It< 	>G11-GD4y FC # : :=$ O F $t 4@Et00<=FF
 '+nnW&={#	> ::((B7r+   c                 .    | j                  t        d      S )z6Contributors to the resource (other than the authors).contributorr   DC_NAMESPACEr^   s    r)   dc_contributorzXmpInformation.dc_contributoru  s     m<<r+   valuesc                 2    | j                  t        d|       y )Nr   _set_bag_valuesr   r^   r   s     r)   r   zXmpInformation.dc_contributorz  s    \=&Ar+   c                 .    | j                  t        d      S )z4Text describing the extent or scope of the resource.coverager   r   r   s    r)   dc_coveragezXmpInformation.dc_coverage~  s     %%lJ??r+   r#   c                 2    | j                  t        d|       y )Nr   _set_single_valuer   r^   r#   s     r)   r   zXmpInformation.dc_coverage  s    |Z?r+   c                 .    | j                  t        d      S )zVA sorted array of names of the authors of the resource, listed in order of precedence.creator)r   r   r   s    r)   
dc_creatorzXmpInformation.dc_creator  s     ##L)<<r+   c                 2    | j                  t        d|       y )Nr   )_set_seq_valuesr   r   s     r)   r   zXmpInformation.dc_creator      \9f=r+   c                 8    | j                  t        dt              S )zXA sorted array of dates of significance to the resource. The dates and times are in UTC.date)r   r   rS   r   s    r)   dc_datezXmpInformation.dc_date  s     ##L&/JJr+   c                    || j                  t        dd        y g }|D ]Q  }t        |t        j                        r|j	                  t        |             8|j	                  t        |             S | j                  t        d|       y )Nr   )r   r   
isinstancerH   rh   r\   r   )r^   r   date_stringsr#   s       r)   r   zXmpInformation.dc_date  sw    >  vt<L 4eX%6%67 ''(<U(CD ''E
3	4
   v|Dr+   c                 .    | j                  t        d      S )zSA language-keyed dictionary of textual descriptions of the content of the resource.descriptionr   r   r   s    r)   dc_descriptionzXmpInformation.dc_description  s     ''mDDr+   c                 2    | j                  t        d|       y )Nr   _set_langalt_valuesr   r   s     r)   r   zXmpInformation.dc_description  s      }fEr+   c                 .    | j                  t        d      S )zThe mime-type of the resource.formatr   r   s    r)   	dc_formatzXmpInformation.dc_format       %%lH==r+   c                 2    | j                  t        d|       y )Nr  r   r   s     r)   r  zXmpInformation.dc_format      |Xu=r+   c                 .    | j                  t        d      S )z"Unique identifier of the resource.
identifierr   r   s    r)   dc_identifierzXmpInformation.dc_identifier  s     %%lLAAr+   c                 2    | j                  t        d|       y )Nr	  r   r   s     r)   r
  zXmpInformation.dc_identifier  s    |\5Ar+   c                 .    | j                  t        d      S )zAAn unordered array specifying the languages used in the resource.languager   r   s    r)   dc_languagezXmpInformation.dc_language       j99r+   c                 2    | j                  t        d|       y )Nr  r   r   s     r)   r  zXmpInformation.dc_language      \:v>r+   c                 .    | j                  t        d      S )z&An unordered array of publisher names.	publisherr   r   s    r)   dc_publisherzXmpInformation.dc_publisher  s     k::r+   c                 2    | j                  t        d|       y )Nr  r   r   s     r)   r  zXmpInformation.dc_publisher  s    \;?r+   c                 .    | j                  t        d      S )zLAn unordered array of text descriptions of relationships to other documents.relationr   r   s    r)   dc_relationzXmpInformation.dc_relation  r  r+   c                 2    | j                  t        d|       y )Nr  r   r   s     r)   r  zXmpInformation.dc_relation  r  r+   c                 .    | j                  t        d      S )z`A language-keyed dictionary of textual descriptions of the rights the user has to this resource.rightsr   r   s    r)   	dc_rightszXmpInformation.dc_rights  s     ''h??r+   c                 2    | j                  t        d|       y )Nr  r   r   s     r)   r  zXmpInformation.dc_rights  s      x@r+   c                 .    | j                  t        d      S )zCUnique identifier of the work from which this resource was derived.sourcer   r   s    r)   	dc_sourcezXmpInformation.dc_source  r  r+   c                 2    | j                  t        d|       y )Nr  r   r   s     r)   r   zXmpInformation.dc_source  r  r+   c                 .    | j                  t        d      S )z\An unordered array of descriptive phrases or keywords that specify the topic of the content.subjectr   r   s    r)   
dc_subjectzXmpInformation.dc_subject  s     i88r+   c                 2    | j                  t        d|       y )Nr#  r   r   s     r)   r$  zXmpInformation.dc_subject  r   r+   c                 .    | j                  t        d      S )z9A language-keyed dictionary of the title of the resource.titler   r   s    r)   dc_titlezXmpInformation.dc_title  s     ''g>>r+   c                 2    | j                  t        d|       y )Nr'  r   r   s     r)   r(  zXmpInformation.dc_title  s      w?r+   c                 .    | j                  t        d      S )z@An unordered array of textual descriptions of the document type.typer   r   s    r)   dc_typezXmpInformation.dc_type  s     f55r+   c                 2    | j                  t        d|       y )Nr+  r   r   s     r)   r,  zXmpInformation.dc_type  s    \66:r+   c                 .    | j                  t        d      S )z:An unformatted text string representing document keywords.Keywordsr   PDF_NAMESPACEr   s    r)   pdf_keywordszXmpInformation.pdf_keywords       %%mZ@@r+   c                 2    | j                  t        d|       y )Nr/  r   r1  r   s     r)   r2  zXmpInformation.pdf_keywords
      }j%@r+   c                 .    | j                  t        d      S )z-The PDF file version, for example 1.0 or 1.3.
PDFVersionr0  r   s    r)   pdf_pdfversionzXmpInformation.pdf_pdfversion  s     %%m\BBr+   c                 2    | j                  t        d|       y )Nr8  r5  r   s     r)   r9  zXmpInformation.pdf_pdfversion  s    }lEBr+   c                 .    | j                  t        d      S )z6The name of the tool that saved the document as a PDF.Producerr0  r   s    r)   pdf_producerzXmpInformation.pdf_producer  r3  r+   c                 2    | j                  t        d|       y )Nr<  r5  r   s     r)   r=  zXmpInformation.pdf_producer  r6  r+   c                 8    | j                  t        dt              S )zYThe date and time the resource was originally created. Returned as a UTC datetime object.
CreateDater   XMP_NAMESPACErS   r   s    r)   xmp_create_datezXmpInformation.xmp_create_date        %%m\?SSr+   c                 |    |r#t        |      }| j                  t        d|       y | j                  t        dd        y )Nr@  r\   r   rB  r^   r#   date_strs      r)   rC  zXmpInformation.xmp_create_date%  3    +E2H""=,I""=,Er+   c                 8    | j                  t        dt              S )zTThe date and time the resource was last modified. Returned as a UTC datetime object.
ModifyDaterA  r   s    r)   xmp_modify_datezXmpInformation.xmp_modify_date-  rD  r+   c                 |    |r#t        |      }| j                  t        d|       y | j                  t        dd        y )NrK  rF  rG  s      r)   rL  zXmpInformation.xmp_modify_date2  rI  r+   c                 8    | j                  t        dt              S )zjThe date and time that any metadata for this resource was last changed. Returned as a UTC datetime object.MetadataDaterA  r   s    r)   xmp_metadata_datez XmpInformation.xmp_metadata_date:  s     %%m^_UUr+   c                 |    |r#t        |      }| j                  t        d|       y | j                  t        dd        y )NrO  rF  rG  s      r)   rP  z XmpInformation.xmp_metadata_date?  s3    +E2H""=.(K""=.$Gr+   c                 .    | j                  t        d      S )z=The name of the first known tool used to create the resource.CreatorTool)r   rB  r   s    r)   xmp_creator_toolzXmpInformation.xmp_creator_toolG  s     %%m]CCr+   c                 2    | j                  t        d|       y )NrS  )r   rB  r   s     r)   rT  zXmpInformation.xmp_creator_toolL  s    }mUCr+   c                 .    | j                  t        d      S )zGThe common identifier for all versions and renditions of this resource.
DocumentIDr   XMPMM_NAMESPACEr   s    r)   xmpmm_document_idz XmpInformation.xmpmm_document_idP       %%o|DDr+   c                 2    | j                  t        d|       y )NrW  r   rY  r   s     r)   rZ  z XmpInformation.xmpmm_document_idU      eDr+   c                 .    | j                  t        d      S )zZAn identifier for a specific incarnation of a document, updated each time a file is saved.
InstanceIDrX  r   s    r)   xmpmm_instance_idz XmpInformation.xmpmm_instance_idY  r[  r+   c                 2    | j                  t        d|       y )Nr`  r]  r   s     r)   ra  z XmpInformation.xmpmm_instance_id^  r^  r+   c                 .    | j                  t        d      S )zMThe part of the PDF/A standard that the document conforms to (e.g., 1, 2, 3).partr   PDFAID_NAMESPACEr   s    r)   pdfaid_partzXmpInformation.pdfaid_partb  s     %%&6??r+   c                 2    | j                  t        d|       y )Nrd  r   rf  r   s     r)   rg  zXmpInformation.pdfaid_partg  s    /?r+   c                 .    | j                  t        d      S )zFThe conformance level within the PDF/A standard (e.g., 'A', 'B', 'U').conformancere  r   s    r)   pdfaid_conformancez!XmpInformation.pdfaid_conformancek  s     %%&6FFr+   c                 2    | j                  t        d|       y )Nrk  ri  r   s     r)   rl  z!XmpInformation.pdfaid_conformancep  s    /Fr+   c                    t        | d      si | _        | j                  dt              D ]  }|j                  }d}	 |j                  d|      }|dk(  rn\||dz   |dz    }t        |      dk7  st        d	 |D              s|dz   }J|d
| t        t        |d            z   ||dz   d
 z   }|dz   }t|j                  |j                  k(  r|j                  }n| j                  |      }|| j                  |<    | 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=   r         c              3   ,   K   | ]  }|t         v   y wr&   r   )r9   cs     r)   r;   z3XmpInformation.custom_properties.<locals>.<genexpr>  s     2Ra1	>2Rs   N   )rx   )hasattrro  r   PDFX_NAMESPACE	localNamefindrf   allchrr8   r   r   r   rg   )r^   nodekeystartidxhex_idr#   s          r)   custom_propertiesz XmpInformation.custom_propertiest  s    t12&(D#33BG 5nn((8U3Cby q373F6{a's2R62R/R !$a ds)c#f2*>&??#cAgi.PC!GE  ==D$7$77 NNE NN40E/4'',)5* &&&r+   c                 `   | j                   j                  t        d      D ]  }|j                  t        d      |k(  s|c S  | j                   j                  }|t        d      |j                  t        d      }|j                  t        d|       | j                   j                  |       |S )zBGet or create an rdf:Description element with the given about URI.r   r   XMP Document is Nonezrdf:Descriptionz	rdf:about)	r   rd   re   r   ownerDocumentr   createElementNSsetAttributeNSappendChild)r^   r   r   docs       r)   _get_or_create_descriptionz)XmpInformation._get_or_create_description  s    MM88V 	D""=':iG	 mm));"#9::""=2CDM;	B!!$'r+   c                 P    | j                   j                  |      }|r	||v r||= yyy)z<Remove a cached value for a given namespace/name if present.N)r   r   )r^   r   r~   r   s       r)   _clear_cache_entryz!XmpInformation._clear_cache_entry  s,    ::>>),( )8r+   c                 *   | j                  ||       | j                         }t        |j                  ||            }|D ]  }|j	                  |        |j                  ||      x}r|j                  |       || j                  j                  }|t        d      | j                  |      }	|j                  ||	 d|       }|j                  t        |            }
|j                  |
       |j                  |       | j                          y)z&Set or remove a single metadata value.Nr  r<   )r  r  r   rd   removeChildr   removeAttributeNoder   r  r   _get_namespace_prefixr  createTextNoder   r  _update_stream)r^   r   r~   r#   r   existing_elementselemexisting_attrr  prefix	text_nodes              r)   r   z XmpInformation._set_single_value  s   	40..0 !<!<Y!MN% 	#DT"	# !33ItDD=D$$]3----C{&'=>>//	:F&&yVHAdV2DED**3u:6IY'T"r+   c                    | j                  ||       | j                         }t        |j                  ||            }|D ]  }|j	                  |        |r| j
                  j                  }|t        d      | j                  |      }|j                  || d|       }|j                  t        d      }	|D ]T  }
|j                  t        d      }|j                  t        |
            }|j                  |       |	j                  |       V |j                  |	       |j                  |       | j                          y)z+Set or remove bag values (unordered array).Nr  r<   zrdf:Bagrdf:lir  r  r   rd   r  r   r  r   r  r  re   r  r   r  r  )r^   r   r~   r   r   r  r  r  r  bagr#   rc   r  s                r)   r   zXmpInformation._set_bag_values  0   	40..0 !<!<Y!MN% 	#DT"	# ----C{&'=>>//	:F&&yVHAdV2DED%%mY?C $((A..s5z:	y)#	$ S!T"r+   c                    | j                  ||       | j                         }t        |j                  ||            }|D ]  }|j	                  |        |r| j
                  j                  }|t        d      | j                  |      }|j                  || d|       }|j                  t        d      }	|D ]T  }
|j                  t        d      }|j                  t        |
            }|j                  |       |	j                  |       V |j                  |	       |j                  |       | j                          y)z.Set or remove sequence values (ordered array).Nr  r<   zrdf:Seqr  r  )r^   r   r~   r   r   r  r  r  r  seqr#   rc   r  s                r)   r   zXmpInformation._set_seq_values  r  r+   c                    | j                  ||       | j                         }t        |j                  ||            }|D ]  }|j	                  |        |r| j
                  j                  }|t        d      | j                  |      }|j                  || d|       }|j                  t        d      }	|j                         D ]i  \  }
}|j                  t        d      }|j                  d|
       |j                  t        |            }|j                  |       |	j                  |       k |j                  |	       |j                  |       | j!                          y)z*Set or remove language alternative values.Nr  r<   zrdf:Altr  r   )r  r  r   rd   r  r   r  r   r  r  re   itemssetAttributer  r   r  r  )r^   r   r~   r   r   r  r  r  r  r   langr#   rc   r  s                 r)   r  z"XmpInformation._set_langalt_values  sH   	40..0 !<!<Y!MN% 	#DT"	# ----C{&'=>>//	:F&&yVHAdV2DED%%mY?C%||~ $e((A
D1..s5z:	y)#$ S!T"r+   c                 .    t         j                  |d      S )z?Get the appropriate namespace prefix for a given namespace URI.unknown)_NAMESPACE_PREFIX_MAPr   )r^   r   s     r)   r  z$XmpInformation._get_namespace_prefix  s    $((I>>r+   c                     | j                   j                  }|t        d      |j                  d      }| j                  j                  |       y)z/Update the stream with the current XML content.Nr  r   )encoding)r   r  r   toxmlr   r   )r^   r  xml_datas      r)   r  zXmpInformation._update_stream  sD    mm));"#9::99g9.X&r+   )r$   r_   r&   )r   )r$   N)Br   r   r   r   r   rs   classmethodr   r   r
   r   bytesr   r   r   r   r   
XmlElementrg   r*   r   r   r   r   r   r   r   r   propertyr   setterr   r   rH   r   r   r  r
  r  r  r  r  r   r$  r(  r,  r2  r9  r=  rC  rL  rP  rT  rZ  ra  rg  rl  r  r  r  r   r   r   r  r  r  r'   r+   r)   r_   r_      s}   (} ( (" 	 	 MQ, ,27c58H2I,	,HS HS H HQT H	$ 	$ 	$QT 	$   +4	  SE3J'	
 
#,S  c8K & +4	  SE3J'	
 
$s)	:S  cSVh@X $ =c 3 = = BXd3i%8 BT B B @Xc] @ @ @# @4 @ @ =HT#Y/ = = >$s)!4 > > > K$x'8'8"9: K K ^^
EhtE#x7H7H2H,I'JK 
EPT 
E 
E Ec3h 8 E E FXd38n%= F$ F F >8C= > > >x} > > > Bx} B B B8C= BT B B :Xd3i0 : : ?(49"5 ?$ ? ? ;htCy1 ; ; @8DI#6 @4 @ @ :Xd3i0 : : ?(49"5 ?$ ? ? @8DcN3 @ @ Ac3h 8 AT A A >8C= > > >x} > > > 9HT#Y/ 9 9 >$s)!4 > > > ?(4S>2 ? ? __@xS#X7 @D @ @ 6$s), 6 6 ^^;htCy1 ;d ; ; Ahsm A A A(3- AD A A C C C CHSM Cd C C Ahsm A A A(3- AD A A T(*;*;!< T T FXh.?.?%@ FT F F T(*;*;!< T T FXh.?.?%@ FT F F V8H,=,=#> V V Hx0A0A'B Ht H H D(3- D D Dhsm D D D E8C= E E Ex} E E E E8C= E E Ex} E E E @Xc] @ @ @# @4 @ @ GHSM G G G G$ G G  '4S>  '  'DC  C s t 3 c (3- TX 0 C $s)AT Y] 8 C $s)AT Y] 8S  XdSVX[S[nE] bf :?s ?s ?'r+   )>r   rH   rD   recollections.abcr   stringr   typingr   r   r   r	   r
   r   xml.dom.expatbuilderr   xml.dom.minidomr   r   r  xml.dom.xmlbuilderr   xml.parsers.expatr   r   
_protocolsr   _utilsr   r   r   errorsr   r   r   genericr   r   r   r   re   r   rB  r1  rY  rv  rf  r  compileVERBOSEr@   r"   r   r*   r   rS   r\   r   rm   ro   r_   r'   r+   r)   <module>r     s     	 $   0 $ 1 & 7 . V V E E -   =1..3( 1 5  $55WhF  "** JJ!( CL& (#n %% '% ')* ++, -'( ) Q 1 3 8#4#4 6
3 1 1 
3c 
3 hq#3@CPXZ]Y^`cYcPdd3i$@. $@NQ	'+Y Q	'r+   