
    OAi                     h   % S r SSKJr  SSKrSSKrSSKJrJr  SSKJ	r	J
r
JrJr  SSKJrJr  SSKJr  SSKJr  SS	KJrJrJr  SS
KJr  SSKJr  SSKJrJrJr  SSKJ r!  SSK"J#r#  SSK$J%r%J&r&J'r'  \(       a  SSK(J)r)  Sr*Sr+Sr,Sr-Sr.Sr/Sr0Sr1Sr2Sr3Sr4Sr5Sr6Sr7Sr8S r9S!\*S"4\+S#4\,S$4\-S%4\.S&4\/S'4\0S(4\1S)4\2S*4\3S+4\4S,4\5S-4\6S.4\7S/4\8S04\9S14S2S3S4S5/r:S6\;S7'   \: H  u  r<r=\R|                  " \=\<5        M     S8r?S9r@S:rAS;rB " S< S=\5      rC\R                  " \E5      rF " S> S?\G5      rH " S@ SA\I5      rJ\C" SB\J\JR                  5      \C" SC\L\LR                  5      \C" SD\I\IR                  5      /rN\O" \P" \" \*SE5      5      \P" \" \*SF5      5      \P" \" \*SG5      5      \P" \" \9SH5      5      /5      rQ\R                  " SI5      rS\R                  " SJ5      rTS]SK jrUS]SL jrVS]SM jrWS^S_SN jjrXS`SaSO jjrYSbSP jrZScSQ jr[ " SR SS\5      r\ " ST SU\\5      r] " SV SW\\5      r^ " SX SY\5      r_SZ r` " S[ S\\5      rag)dzPDF metadata handling.    )annotationsN)ABCabstractmethod)CallableIterableIteratorMutableMapping)datetimetimezonewraps)BytesIO)TYPE_CHECKINGAny
NamedTuple)warn)etree)QNameXMLSyntaxError_Element)__version__)	parse_xml)NameStreamString)Pdfz http://purl.org/dc/elements/1.1/zhttp://ns.adobe.com/pdf/1.3/zhttp://www.aiim.org/pdfa/ns/id/z&http://www.aiim.org/pdfa/ns/extension/z%http://www.aiim.org/pdfa/ns/property#z#http://www.aiim.org/pdfa/ns/schema#z http://www.aiim.org/pdfua/ns/id/zhttp://www.npes.org/pdfx/ns/id/z"http://ns.adobe.com/photoshop/1.0/z.http://prismstandard.org/namespaces/basic/1.0/z.http://prismstandard.org/namespaces/basic/2.0/z.http://prismstandard.org/namespaces/basic/3.0/z+http://www.w3.org/1999/02/22-rdf-syntax-ns#zhttp://ns.adobe.com/xap/1.0/zhttp://ns.adobe.com/xap/1.0/mm/z#http://ns.adobe.com/xap/1.0/rights/)zadobe:ns:meta/xdcpdfpdfaidpdfaExtensionpdfaProperty
pdfaSchemapdfuaidpdfxid	photoshopprismprism2prism3rdfxmpxmpMM	xmpRights)z"http://crossref.org/crossmark/1.0/	crossmark)z$http://www.niso.org/schemas/jav/1.0/jav)zhttp://ns.adobe.com/pdfx/1.3/pdfx)z$http://www.niso.org/schemas/ali/1.0/alizlist[tuple[str, str]]DEFAULT_NAMESPACESz$http://www.w3.org/XML/1998/namespaces6   <?xpacket begin="﻿" id="W5M0MpCehiHzreSzNTczkc9d"?>
s   <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="pikepdf">
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
 </rdf:RDF>
</x:xmpmeta>
s   
<?xpacket end="w"?>
c                  8    \ rS rSr% SrS\S'   S\S'   S\S'   S	rg
)XmpContainerW   z6Map XMP container object to suitable Python container.strrdf_typetypepy_typezCallable[..., None]	insert_fn N__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r;       S/var/www/html/land-ocr/venv/lib/python3.13/site-packages/pikepdf/models/metadata.pyr4   r4   W   s    @MM""rD   r4   c                      \ rS rSrSrSrg)
NeverRaiseb   z"An exception that is never raised.r;   Nr=   r>   r?   r@   rA   rC   r;   rD   rE   rG   rG   b   s    ,rD   rG   c                      \ rS rSrSrSrg)AltListf   zXMP AltList container.r;   NrI   r;   rD   rE   rK   rK   f   s     rD   rK   AltBagSeqtitledescriptionrights
UsageTermszL(?u)[^\x09\x0A\x0D\x20-\U0000D7FF\U0000E000-\U0000FFFD\U00010000-\U0010FFFF]s   [^\x09\x0A\x0D\x20-\xFF]|&#0;c                *    [        [        U 5      5      $ Nr   r   xmls    rE   _parser_basicrY      s    WS\""rD   c                R    [        [        [        R                  SU 5      5      5      $ NrD   )r   r   re_xml_illegal_bytessubrW   s    rE   _parser_strip_illegal_bytesr^      s     W155c3?@AArD   c                (    [        [        U 5      SS9$ )NT)recoverrV   rW   s    rE   _parser_recoveryra      s    WS\400rD   c                J    [         R                  S5        [        [        5      $ )Nz5Error occurred parsing XMP, replacing with empty XMP.)logwarningrY   	XMP_EMPTY)_xmls    rE   _parser_replace_with_empty_xmprg      s    KKGH##rD   c                8   [        U [        5      (       dp  [        U [        5      (       aP  [        SU  35        [        U [        5      (       a  UR                  [        U 5      5      n OUR                  U 5      n O[        S5      e[        R                  SU 5      $ )zEnsure an object can safely be inserted in a XML tag body.

If we still have a non-str object at this point, the best option is to
join it, because it's apparently calling for a new node in a place that
isn't allowed in the spec or not supported.
zMerging elements of z.object must be a string or iterable of strings )

isinstancer6   r   r   setjoinsorted	TypeErrorre_xml_illegal_charsr]   )sjoiners     rE   _cleanrr      sy     aa""'s+,!S!!KKq	*KKNLMM##B**rD   c                    SU R                   S 3nXR                  S5      -  nU R                  S5      nU(       a  US   USS USS pTnX U S	U 3-  nU$ )
a{  Encode Python datetime object as PDF date string.

From Adobe pdfmark manual:
(D:YYYYMMDDHHmmSSOHH'mm')
D: is an optional prefix. YYYY is the year. All fields after the year are
optional. MM is the month (01-12), DD is the day (01-31), HH is the
hour (00-23), mm are the minutes (00-59), and SS are the seconds
(00-59). The remainder of the string defines the relation of local
time to GMT. O is either + for a positive difference (local time is
later than GMT) or - (minus) for a negative difference. HH' is the
absolute value of the offset from GMT in hours, and mm' is the
absolute value of the offset in minutes. If no GMT information is
specified, the relation between the specified time and GMT is
considered unknown. Regardless of whether or not GMT
information is specified, the remainder of the string should specify
the local time.

'D:' is required in PDF/A, so we always add it.
D:04dz
%m%d%H%M%Sz%zr            ')yearstrftime)drp   tzsigntz_hourstz_minss         rE   encode_pdf_dater      so    . QVVCLAM	""A	
D	B	"$Q%Aa"Qq'	vhZq	**HrD   c                   [        U [        5      (       a  [        U 5      n U nUR                  S5      (       a  USS n/ SQnU H-  nUR	                  U5      (       d  M  UR                  US5      n  O   UR                  SS5      n/ SQnU H  n [        R                  " X5      s  $    [        S	U  S
U S35      e! [         a     M=  f = f)zDecode a pdfmark date to a Python datetime object.

A pdfmark date is a string in a particular format, as described in
:func:`encode_pdf_date`.
rt      N)zZ00'00'zZ00'00Zz+0000ry   ri   )z%Y%m%d%H%M%S%zz%Y%m%d%H%M%Sz%Y%m%dz-Date string does not match any known format: z
 (read as ))	rj   r   r6   
startswithendswithreplacer
   strptime
ValueError)rp   tutcsutcdate_formatsdate_formats         rE   decode_pdf_dater      s     !VF	A||DabED
 ::c??		#w'A  	
		#rAL
 $	$$Q44 $
 DQCzRSQTTUV
WW  		s   B==
C
Cc                  T    \ rS rSrSr\\SS j5       5       r\\SS j5       5       rSr	g)		Converter   zXMP <-> DocumentInfo converter.c                    g)z/Derive XMP metadata from a DocumentInfo string.Nr;   docinfo_vals    rE   xmp_from_docinfoConverter.xmp_from_docinfo       rD   c                    g)z9Derive a DocumentInfo value from equivalent XMP metadata.Nr;   xmp_vals    rE   docinfo_from_xmpConverter.docinfo_from_xmp   r   rD   r;   Nr   
str | Nonereturnr   )r   r   r   r   )
r=   r>   r?   r@   rA   staticmethodr   r   r   rC   r;   rD   rE   r   r      s=    )>  > H  HrD   r   c                  <    \ rS rSrSr\SS j5       r\S 5       rSrg)AuthorConverter   z-Convert XMP document authors to DocumentInfo.c                    U /$ )z*Derive XMP authors info from DocumentInfo.r;   r   s    rE   r    AuthorConverter.xmp_from_docinfo   s     }rD   c                v    [        U [        5      (       a  U $ U b  U S/:X  a  gSR                  S U  5       5      $ )zDerive DocumentInfo authors from XMP.

XMP supports multiple author values, while DocumentInfo has a string,
so we return the values separated by semi-colons.
N; c              3  .   #    U  H  oc  M  Uv   M     g 7frU   r;   ).0authors     rE   	<genexpr>3AuthorConverter.docinfo_from_xmp.<locals>.<genexpr>  s     LgFgs   	)rj   r6   rl   r   s    rE   r    AuthorConverter.docinfo_from_xmp  s<     gs##N?g$/yyLgLLLrD   r;   Nr   	r=   r>   r?   r@   rA   r   r   r   rC   r;   rD   rE   r   r      s-    7  
M 
MrD   r   c                  8    \ rS rSrSr\S 5       r\S 5       rSrg)DateConverteri  z"Convert XMP dates to DocumentInfo.c                B    U S:X  a  g[        U 5      R                  5       $ )z"Derive XMP date from DocumentInfo.ri   )r   	isoformatr   s    rE   r   DateConverter.xmp_from_docinfo  s#     "{+5577rD   c                    U R                  S5      (       a  U SS S-   n [        R                  " U 5      n[        U5      $ )zDerive DocumentInfo from XMP.r   Nz+00:00)r   r
   fromisoformatr   )r   dateobjs     rE   r   DateConverter.docinfo_from_xmp  s@     C  crlX-G((1w''rD   r;   Nr   r;   rD   rE   r   r     s+    ,8 8 ( (rD   r   c                  B    \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S
rg)DocinfoMappingi#  zEMap DocumentInfo keys to their XMP equivalents, along with converter.r6   nskeyr   nameztype[Converter] | None	converterr;   Nr<   r;   rD   rE   r   r   #  s    OG	H
J%%rD   r   c                0   ^  [        T 5      U 4S j5       nU$ )ztEnsure the XMP has been loaded and parsed.

TODO: Can this be removed? Why allow the uninit'ed state to even exist?
c                ^   > U R                   (       d  U R                  5         T" U /UQ70 UD6$ rU   )_xmp_load)selfargskwargsfns      rE   wrapperensure_loaded.<locals>.wrapper2  s(    yyJJL$((((rD   r   )r   r   s   ` rE   ensure_loadedr   ,  s"     2Y) )
 NrD   c                     \ rS rSr% Sr\" \S\R                  \	5      \" \S\R                  S5      \" \S\R                  S5      \" \S\R                  S5      \" \S\R                  S5      \" \S	\R                   \5      \" \S
\R$                  S5      \" \S\R&                  \5      /rS\S'   \ V VVs0 s H  u  pX!_M	     snnn rS\S'   \" \5      rS\S'   \\\\/rS\S'   \/rS\S'   \ S 5       r!   S3       S4S jjr" S5     S6S jjr#S7S jr$S8S jr%\&S 5       r'S r(S r)S9S jr*S r+\ S:S j5       r,S r-S;S  jr.S<S! jr/ S=   S>S" jjr0S=S?S# jjr1\&S@S$ j5       r2\&S@S% j5       r3\&S& 5       r4\&S' 5       r5 SA     SBS( jjr6SCS) jr7SDS* jr8S+ r9S, r:\&SES- j5       r;\&S@S. j5       r<\=SFS/ j5       r>\=SFS0 j5       r?\&S1 5       r@S2rAgs  snnn f )GPdfMetadatai;  a  Read and edit the metadata associated with a PDF.

The PDF specification contain two types of metadata, the newer XMP
(Extensible Metadata Platform, XML-based) and older DocumentInformation
dictionary. The PDF 2.0 specification removes the DocumentInformation
dictionary.

This primarily works with XMP metadata, but includes methods to generate
XMP from DocumentInformation and will also coordinate updates to
DocumentInformation so that the two are kept consistent.

XMP metadata fields may be accessed using the full XML namespace URI or
the short name. For example ``metadata['dc:description']``
and ``metadata['{http://purl.org/dc/elements/1.1/}description']``
both refer to the same field. Several common XML namespaces are registered
automatically.

See the XMP specification for details of allowable fields.

To update metadata, use a with block.

Example:
    >>> with pdf.open_metadata() as records:
    ...     records['dc:title'] = 'New Title'

See Also:
    :meth:`pikepdf.Pdf.open_metadata`
creatorrQ   NrP   KeywordsProducer
CreateDateCreatorTool
ModifyDatezlist[DocinfoMapping]DOCINFO_MAPPINGzdict[str, str]NS
REVERSE_NSz Iterable[Callable[[bytes], Any]]_PARSERS_OVERWRITE_INVALID_XML_PARSERS_STANDARDc                z    XR                   U'   X R                  U'   [        R                  " [        [
        5        g)zRegister a new XML/XMP namespace.

Arguments:
    uri: The long form of the namespace.
    prefix: The alias to use when interpreting XMP.
N)r   r   r   register_namespace_prefix_uri)clsuriprefixs      rE   register_xml_namespace"PdfMetadata.register_xml_namespaceo  s+     v$s  $/rD   c                P    Xl         X l        X0l        SU l        X@l        SU l        g)z7Construct PdfMetadata. Use Pdf.open_metadata() instead.FN)_pdfmarksync_docinfo	_updatingoverwrite_invalid_xmlr   )r   r   pikepdf_markr   r   s        rE   __init__PdfMetadata.__init__{  s(     	 	(%:"	rD   c                  ^ SU4S jjnU R                    H}  u  pVpx[        XV5      n	UR                  [        U5      5      n
U
c  U(       a  X;   a  X		 M>   [        U
5      n
U(       a  UR	                  U
5      n
U
(       d  Mk  U R                  XS5        M     U R                    VVs1 s H  u    pn[        U5      iM     nnnUR                  5        Vs1 s H  n[        U5      iM     snU-
  nU H*  nU" SU S[        UR                  U5      5       S35        M,     g! [        [        [        4 a  nU" SU S3U5         SnAGM3  SnAff = fs  snnf s  snf )	a  Populate the XMP metadata object with DocumentInfo.

Arguments:
    docinfo: a DocumentInfo, e.g pdf.docinfo
    delete_missing: if the entry is not DocumentInfo, delete the equivalent
        from XMP
    raise_failure: if True, raise any failure to convert docinfo;
        otherwise warn and continue

A few entries in the deprecated DocumentInfo dictionary are considered
approximately equivalent to certain XMP records. This method copies
those entries into the XMP metadata.
Nc                B   > T(       a  [        U 5      Ue[        U 5        g rU   )r   r   )msgeraise_failures     rE   warn_or_raise4PdfMetadata.load_from_docinfo.<locals>.warn_or_raise  s     o1,IrD   TzThe metadata field z could not be copied to XMPz with value 'z,' has no XMP equivalent, so it was discardedrU   )r   r   getr6   r   _setitemr   AttributeErrorNotImplementedErrorkeysrepr)r   docinfodelete_missingr   r   r   shortkeydocinfo_namer   qnamevalr   _valid_docinfo_nameskextra_docinfo_namesextras      `             rE   load_from_docinfoPdfMetadata.load_from_docinfo  sZ   "	
 7;6J6J2C<#(E ++c,/0C{!em
#h#44S9Ce$/ 7K* <@;O;O
;O"7!QaC;O 	 
 07||~>~!s1v~>ATT(E%eWM$w{{5?Q:R9S T= = ) 0CD ),7RSUV 
 ?s*   *D D &EE E5E		Ec                     U R                   R                  R                  R                  5       nU R                  U5        g ! [         a    Sn N f = fr[   )r   RootMetadata
read_bytesr   
_load_from)r   datas     rE   r   PdfMetadata._load  sG    	99>>**557D 	  	D	s   .A AAc                   UR                  5       S:X  a  [        nU R                  (       a  U R                  OU R                  nU H  n U" U5      U l          O   U R
                  ba   U R
                  R                  S5      nU H.  n[        R                  " U R
                  UR                  5        M0     U R                  5         g ["        R%                  S5        [        5       U l        g ! U R                  (       a  [        O[         aa  n[        U5      R                  S5      (       d  [        U5      R                  S5      (       a  [        5       U l         S nA  GM	   S nAGM%  S nAff = f! U R                  (       a  [         O[         a-  n["        R%                  SUS9  [        5       U l         S nAg S nAff = f)NrD   z!Start tag expected, '<' not foundzDocument is emptyz/processing-instruction()zError occurred parsing XMP)exc_info)stripre   r   r   r   r   r   rG   r6   r   rg   xpathr   
strip_tagstag_get_rdf_root	Exceptionrc   rd   )r   r
  parsersparserr   pispis          rE   r	  PdfMetadata._load_from  sh   ::<3D )) //'' 	 F"4L	   99 =iioo&ABB$$TYY7 ""$ KK4568DI3 #'"<"<* q6$$%HIISN*01N2 !? @DI	N2& -- =
 81E:<		=s2   
C.)AE3 .!E0AE++E03!G#F<<Gc                    SU l         U $ )zOpen metadata for editing.T)r   r   s    rE   	__enter__PdfMetadata.__enter__  s     rD   c                d     Ub	   SU l         gU R                  5         SU l         g! SU l         f = f)z!Close metadata and apply changes.NF)r   _apply_changes)r   exc_typeexc_valexc_tbs       rE   __exit__PdfMetadata.__exit__  s6    	## #DN !"DNUDNs   & & 	/c           
        U R                   R                    U R                   H  u  pp4[        X5      n X   nU(       a   UR                  U5      nUc2  X0R                   R                  ;   a  U R                   R                  U	 Md  [        U5      n UR                  S5      U R                   R                  U'   M     g! [         a4    X0R                   R                  ;   a  U R                   R                  U	  M  f = f! [         a    [        SU S35        Sn N[         a  n[        SU SU SU 35      UeSnAff = f! [         a    X`R                   R                  U'    GMG  f = f)zUpdate the PDF's DocumentInfo dictionary to match XMP metadata.

The standard mapping is described here:
    https://www.pdfa.org/pdfa-metadata-xmp-rdf-dublin-core/
zThe DocumentInfo field z could not be updated from XMPNz4An error occurred while updating DocumentInfo field z
 from XMP z with value ascii)r   r   r   r   KeyErrorr   r   r   r  rr   encodeUnicodeEncodeError)r   r   elementr   r   r   valuer   s           rE   _update_docinfoPdfMetadata._update_docinfo  sl    			595I5I1C,#'E
 %66u=E }99#4#44		)),75ME827,,w2G		!!,/; 6J  99#4#44		)),7 " !1, @+ + !E  $N'.
5'eWN  & 827		!!,/8sA   C D(E :C>=C>E	E'D<<E"E+*E+c                   [        5       nU(       a  UR                  [        5        U R                  R                  USSS9  U(       a  UR                  [        5        UR                  S5        UR                  5       nU$ )Nutf-8T)encodingpretty_printr   )r   writeXPACKET_BEGINr   XPACKET_ENDseekread)r   xpacketr
  	xml_bytess       rE   _get_xml_bytesPdfMetadata._get_xml_bytes'  sY    yJJ}%		wTBJJ{#		!IIK	rD   c                   U R                   (       au  U R                  [        [        S5      [        R
                  " [        R                  5      R                  5       SS9  U R                  [        [        S5      S[        -   SS9  U R                  5       n[        U R                  U5      U R                  R                  l        [         R                  U R                  R                  R                  [         R"                  '   [         R$                  U R                  R                  R                  [         R&                  '   U R(                  (       a  U R+                  5         gg)zzSerialize our changes back to the PDF in memory.

Depending how we are initialized, leave our metadata mark and producer.
MetadataDateT)applying_markr   zpikepdf N)r   r   r   
XMP_NS_XMPr
   nowr   r   r   
XMP_NS_PDFpikepdf_versionr8  r   r   r  r  r   TypeXMLSubtyper   r+  )r   rX   s     rE   r  PdfMetadata._apply_changes2  s    
 99MMj.1X\\*446"  
 MMj*-_,"  
 !!#"(C"8		-1]]				*04		-  " rD   c                t   [        U[        5      (       a  [        U5      $ [        U[        5      (       d  [        U S35      eUS:X  a  U$ UR	                  S5      (       a  U$  UR                  SSS9u  p#U R                  R                  US5      n[        [        XC5      5      $ ! [         a    SUp2 N?f = f)z[Convert name to an XML QName.

e.g. pdf:Producer -> {http://ns.adobe.com/pdf/1.3/}Producer
z must be strri   {:rv   maxsplitN)	rj   r   r6   rn   r   splitr   r   r   )r   r   r   r  r   s        rE   _qnamePdfMetadata._qnameJ  s     dE""t9$$$tfL1222:K??3K	#**S1*5KF ffjj&5?##  
	# dC
	#s   %B' 'B76B7c                t    UR                  SSS9u  p#UR                  SS5      nU R                  U   S-   U-   $ )znGiven a fully qualified XML name, find a prefix.

e.g. {http://ns.adobe.com/pdf/1.3/}Producer -> pdf:Producer
}rv   rH  rF  ri   rG  )rJ  r   r   )r   urinameuripartr  r   s        rE   _prefix_from_uriPdfMetadata._prefix_from_urih  sA    
 }}S1}5ooc2&s#c)C//rD   c                2   UR                  SU R                  5      nUb   US   R                  $ [         HN  u  p4nUR                  SU 3U R                  5      nUc  M*  U" 5       nU H  nU" XgR                  5        M     Us  $    g! [         a     gf = f)zGather the sub-elements attached to a node.

Gather rdf:Bag and and rdf:Seq into set and list respectively. For
alternate languages values, take the first language only for
simplicity.
zrdf:Altr   ri   zrdf:)findr   text
IndexErrorXMP_CONTAINERS)r   nodeitemsxmlcontainer	containerinsertfnresultitems           rE   _get_subelementsPdfMetadata._get_subelementsq  s     		)TWW-Qx}}$ 2@-LXII\N3TWW=E}[F+ M 2@   s   B	 	
BBc                    U R                   c   eU R                   R                  SU R                  5      nUc5  U R                   R                  5       nUR                  S:X  d  [        S5      eU$ )Nz
.//rdf:RDFz0{http://www.w3.org/1999/02/22-rdf-syntax-ns#}RDFz$Metadata seems to be XML but not XMP)r   rT  r   getrootr  r   )r   r*   s     rE   r  PdfMetadata._get_rdf_root  s_    yy$$$iinn\4773;))##%C77PP !GHH
rD   c              #  f  #    U R                  U5      nU R                  5       nUR                  SU R                  5       H  nU(       a*  X$R	                  5       ;   a  XBUR                  U5      U4v   O/U(       d(  UR                  5        H  u  pVU(       d  M  XEXc4v   M     U(       a  UOSnUR                  XpR                  5       H_  nUR                  (       a3  UR                  R                  5       (       a  USUR                  U4v   MG  U R                  U5      n	USX4v   Ma     M     g7f)a  Get elements from XMP.

Core routine to find elements matching name within the XMP and yield
them.

For XMP spec 7.9.2.2, rdf:Description with property attributes,
we yield the node which will have the desired as one of its attributes.
qname is returned so that the node.attrib can be used to locate the
source.

For XMP spec 7.5, simple valued XMP properties, we yield the node,
None, and the value. For structure or array valued properties we gather
the elements. We ignore qualifiers.

Args:
    name: a prefixed name or QName to look for within the
        data section of the XMP; looks for all data keys if omitted

Yields:
    tuple: (node, qname_attrib, value, parent_node)

rdf:Description[@rdf:about=""]*N)
rK  r  findallr   r   r   rY  rU  r  r_  )
r   r   r   r*   rdfdescr   vr  rX  valuess
             rE   _get_elementsPdfMetadata._get_elements  s     2 D!  "{{#CTWWMG,,.0w{{5'93??#MMODAq&122 , "EsEww799!2!2tyy'::..t4T633 8 Ns   BD1BD1c              #  P   #    S U R                  U5       5        S h  vN   g  N7f)Nc              3  *   #    U  H	  oS    v   M     g7f)r   Nr;   )r   ri  s     rE   r   2PdfMetadata._get_element_values.<locals>.<genexpr>  s     ;":QaD":s   )rk  )r   r   s     rE   _get_element_valuesPdfMetadata._get_element_values  s     ;$"4"4T":;;;s   &$&c                6    [        U R                  U5      5      $ )zTest if XMP key is in metadata.)anyrp  r   r   s     rE   __contains__PdfMetadata.__contains__  s     4++C011rD   c                l     [        U R                  U5      5      $ ! [         a    [        U5      Sef = f)zRetrieve XMP metadata for key.N)nextrp  StopIterationr&  rt  s     rE   __getitem__PdfMetadata.__getitem__  s8    	*00566 	*3-T)	*s    3c              #  v   #    U R                  5        H!  u  pp4U(       a  Uv   M  UR                  v   M#     g7f)z2Iterate through XMP metadata attributes and nodes.N)rk  r  )r   rX  attrib_val_parentss        rE   __iter__PdfMetadata.__iter__  s1      -1,>,>,@(D$hh	 -As   79c                <    [        [        [        U 5      5      5      $ )z#Return number of items in metadata.)lenlistiterr  s    rE   __len__PdfMetadata.__len__  s     4T
#$$rD   c                    U R                   (       d  [        S5      eU R                  U5      nU R                  XX45         U R	                  XU5        g ! [
         a    U R                  X5         g f = f)N/Metadata not opened for editing, use with block)r   RuntimeErrorrK  _setitem_check_args_setitem_updatery  _setitem_insertr   r   r   r<  qkeys        rE   r   PdfMetadata._setitem  sg     ~~PQQ{{3  =?	+  40 	+  *	+s   A A21A2c                8   U R                   (       aF  U(       d?  UU R                  S5      U R                  S5      4;   a  [        R                  SU S35        [	        U[
        5      (       a.  X@R                  S5      ;   a  [        R                  U S35        g g g )Nzxmp:MetadataDatezpdf:Producerz
Update to zP will be overwritten because metadata was opened with set_pikepdf_as_editor=True
dc:creatorz# should be set to a list of strings)r   rK  rc   rd   rj   r6   errorr  s        rE   r  PdfMetadata._setitem_check_args  s    II!./N+ KKSE "2 2 c3D[[-F$GII@AB %HrD   c           
       ^ [        U4S j[         5       5      n[        R                  " U[	        [        [        U5      5      5      nS nUS:X  a  [	        [        [        S5      5      S0nT HN  n[        R                  " U[	        [        [        S5      5      US9nUc  M5  [        U5      nUS:X  a  S nXl	        MP     g )Nc              3  v   >#    U  H.  n[        TUR                  5      (       d  M   UR                  v   M0     g 7frU   )rj   r9   r7   )r   crY  s     rE   r   1PdfMetadata._setitem_add_array.<locals>.<genexpr>  s'      
 .1*UAII2NJAJJs   99rM   langz	x-defaultlir}  ri   )
rx  rW  r   
SubElementr6   r   
XMP_NS_RDF
XMP_NS_XMLrr   rU  )	r   rX  rY  r7   seq
tag_attribr^  el
inner_texts	     `      rE   _setitem_add_arrayPdfMetadata._setitem_add_array  s     
 .
 
 tSz8)D%EF,0
ueJ78+FJD!!#s5T+B'CJWB)/
#!%J$ rD   c           
     v   [        U R                  U5      5      u  pEpgU(       a  [        U[        5      (       dZ  X0R	                  S5      :X  a)  UR
                  U	 U R                  U[        U5      5        g [        SU SU S[        U5       35      eUR                  U[        U5      5        g [        U[        [        -  5      (       a;  UR                  S5       H  nUR                  U5        M     U R                  XB5        g [        U[        5      (       a  UR                  S5       H  nUR                  U5        M     [        U R	                  U5      5      [        ;   a&  U R                  U[        [        U5      /5      5        g [        U5      Ul        g [        SU SU S[        U5       35      e)Nr  Setting  to  with type rf  )rx  rk  rj   r6   rK  r}  r  rr   rn   r8   rk   r  rg  remove	LANG_ALTSrK   rU  )	r   r   r   r  rX  r}  _oldval_parentchilds	            rE   r  PdfMetadata._setitem_update  sY   )-d.@.@.E)F&gc3'';;|44 D)++D&+>#hse4uKS	{$STT-TCZ((c*E" +##D.S!!c*E" +4;;s#$	1''gvc{m.DE"3K	hse4uKS	{KLLrD   c           
     ^   U R                  5       n[        U R                  U5      5      [        ;   a  [	        [        U5      /5      n[        U[        [        -  5      (       a}  [        R                  " U[        [        [        S5      5      [        [        [        S5      5      S0S9n[        R                  " X@R                  U5      5      nU R                  XR5        g [        U[        5      (       a  UR                  SU R                  5      nUcF  [        R                  " U[        [        [        S5      5      [        [        [        S5      5      S0S9n[        R                  " X@R                  U5      5      n[        U5      Ul        g [#        SU SU S[%        U5       35      S e)	NDescriptionaboutri   r  re  r  r  r  )r  r6   rK  r  rK   rr   rj   r  rk   r   r  r   r  r  rT  r   rU  rn   r8   )r   r   r   r*   rh  rX  s         rE   r  PdfMetadata._setitem_insert-  sN     "t{{3 I-6#;-(Cc4#:&&&&E*m45E*g67<G
 ##G[[-=>D##D.S!!hh?IG**j-89j' :;R@
 ##G[[-=>DsDIhse4uKS	{KLRVVrD   c                &    U R                  XS5      $ )zSet XMP metadata key to value.F)r   )r   r   r   s      rE   __setitem__PdfMetadata.__setitem__F  s     }}Su--rD   c                   U R                   (       d  [        S5      e [        U R                  U5      5      u  p#pEU(       av  UR                  U	 [        UR                  5      S:X  aO  [        U5      S:X  a?  [        [        S5      UR                  R                  5       ;   a  UR                  U5        ggggUR                  U5        g! [         a    [        U5      Sef = f)zDelete item from XMP metadata.r  rv   r   r  N)r   r  rx  rk  r}  r  r   r  r   r  ry  r&  )r   r   rX  r}  r  parents         rE   __delitem__PdfMetadata.__delitem__K  s     ~~PQQ	*,01C1CC1H,I)D'KK'$)D	Qj'2dkk6F6F6HH MM$' I ' * d# 	*3-T)	*s   BC
 8C
 
C!c                    U R                   (       d  U R                  5         [        [        S5      n[        [        S5      n X   X   -   $ ! [         a     gf = f)a3  Return the PDF/A conformance level claimed by this PDF, or False.

A PDF may claim to PDF/A compliant without this being true. Use an
independent verifier such as veraPDF to test if a PDF is truly
conformant.

Returns:
    The conformance level of the PDF/A, or an empty string if the
    PDF does not claim PDF/A conformance. Possible valid values
    are: 1A, 1B, 2A, 2B, 2U, 3A, 3B, 3U. Note that ISO standard
    typically refers to PDF/A-1b for example, using lower case;
    this function returns the value as it appears in the PDF, which
    is uppercase.
partconformanceri   )r   r   r   XMP_NS_PDFA_IDr&  )r   key_partkey_conformances      rE   pdfa_statusPdfMetadata.pdfa_status`  sS    " yyJJL0>	>D$999 		s   A 
AAc                    U R                   (       d  U R                  5         [        [        S5      n X   $ ! [         a     gf = f)aG  Return the PDF/X conformance level claimed by this PDF, or False.

A PDF may claim to PDF/X compliant without this being true. Use an
independent verifier such as veraPDF to test if a PDF is truly
conformant.

Returns:
    The conformance level of the PDF/X, or an empty string if the
    PDF does not claim PDF/X conformance.
GTS_PDFXVersionri   )r   r   r   XMP_NS_PDFX_IDr&  )r   pdfx_versions     rE   pdfx_statusPdfMetadata.pdfx_status{  sA     yyJJL^->?	%% 		s   7 
AAc                >    U R                  SS9R                  S5      $ )z#Convert XMP metadata to XML string.F)r6  r.  )r8  decoder  s    rE   __str__PdfMetadata.__str__  s#     ""5"188AArD   )r   r   r   r   r   r   )TTT)r   r   r   boolr   r  r   r  )FF)r   r  r   r  r   None)r   r  )r
  bytesr   r  )T)r   zQName | strr   r6   )rX  r   r   r   )r   r   )ri   )r   str | QNamer   z<Iterator[tuple[_Element, str | bytes | None, Any, _Element]])r   r  r   zIterator[Any])r   r  )F)r   r  r   set[str] | list[str] | strr<  r  )r<  r  r  r6   r   r  )rY  r   r   r  )r   r  r   r  )r   r6   )Br=   r>   r?   r@   rA   r   	XMP_NS_DCr   Authorr   SubjectTitler?  r   r   r=  CreationDater   CreatorModDater   rB   r2   r   dictr   rY   r^   ra   rg   r   r   classmethodr   r   r  r   r	  r   r  r"  r+  r8  r  rK  rQ  r_  r  rk  rp  ru  rz  r  r  r   r  r  r  r  r  r  propertyr  r  r  rC   )r   r   r   s   000rE   r   r   ;  s   < 	y)T[[/Jy-tDy'4::t<z:t}}dCz:t}}dCz<1B1BMRz=$,,Ez<}M	-O) 	 :LL9K+#&+9KLBL!%&8!9J9 	#&	H"$D  <I/7I	0 	0 "!&*  	
  $  LQ2'+2DH2	2h'9R  
#(8T	#0 $ $:00 #%(4(4	E(4T< 2 2 * *   % % $	++ (+ 	+&C(% M8W2 . . * *(  4  * B B] Ms   7Gr   )rX   r  )rD   )rf   r  )r   )rp   zstr | Iterable[str]rq   r6   r   r6   )r|   r
   r   r6   )rp   r6   r   r
   )brA   
__future__r   loggingreabcr   r   collections.abcr   r   r   r	   r
   r   	functoolsr   ior   typingr   r   r   warningsr   lxmlr   
lxml.etreer   r   r   pikepdf._versionr   r@  pikepdf._xmlr   pikepdf.objectsr   r   r   pikepdfr   r  r?  r  XMP_NS_PDFA_EXTENSIONXMP_NS_PDFA_PROPERTYXMP_NS_PDFA_SCHEMAXMP_NS_PDFUA_IDr  XMP_NS_PHOTOSHOPXMP_NS_PRISMXMP_NS_PRISM2XMP_NS_PRISM3r  r=  XMP_NS_XMP_MMXMP_NS_XMP_RIGHTSr2   rB   r   r   r   r  r2  re   r3  r4   	getLoggerr=   rc   r  rG   r  rK   appendrk   addrW  	frozensetr6   r  compilero   r\   rY   r^   ra   rg   rr   r   r   r   r   r   r   r   r   r;   rD   rE   <module>r     s    "  	 # H H '   1 1   6 6 ; " 0 0 /	+
2@ > : 427 ?@@:
+
19  XO,>*&i X{#7HHG$73-3+- ) 0 (MD'	Wd+ ( 4
W	 -#: # !- -!d !
 0SWW%dkk* E)W%&E)]+,E)X&'E#\23		 zzS  zz"CD #B1$
+&@ XFH HMi M,(I (&&Z &Y	B. Y	BrD   