
    Ng                       U d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	m
Z
mZ ddlmZmZ ddlmZ ddlmZ dd	lmZmZmZmZ dd
lmZ ddlmZ ddlmZmZ ddlmZ  ddl!m"Z"m#Z# ddl$m%Z%m&Z&m'Z' erddl(m)Z) dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8d Z9d!e*d"fe+d#fe,d$fe-d%fe.d&fe/d'fe0d(fe1d)fe2d*fe3d+fe4d,fe5d-fe6d.fe7d/fe8d0fe9d1fd2d3d4d5gZ:d6e;d7<   e:D ]\  Z<Z= ej>        e=e<           d8Z?d9Z@d:ZAd;ZB G d< d=e          ZC ejD        eE          ZF G d> d?eG          ZH G d@ dAeI          ZJ eCdBeJeJjK                   eCdCeLeLjM                   eCdDeIeIjK                  gZN eO eP ee*dE                     eP ee*dF                     eP ee*dG                     eP ee9dH                    g          ZQ ejR        dI          ZS ejR        dJ          ZTdidMZUdidNZVdidOZWdjdkdRZXdldmdYZYdnd\ZZdod]Z[ G d^ d_e          Z\ G d` dae\          Z] G db dce\          Z^ G dd dee          Z_df Z` G dg dhe          ZadS )pzPDF metadata handling.    )annotationsN)ABCabstractmethod)IterableIteratorMutableMapping)datetimetimezonewraps)BytesIO)TYPE_CHECKINGAnyCallable
NamedTuple)warn)etree)QNameXMLSyntaxError)__version__)_Element	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                  2    e Zd ZU dZded<   ded<   ded<   dS )	XmpContainerz6Map XMP container object to suitable Python container.strrdf_typetypepy_typezCallable[..., None]	insert_fnN__name__
__module____qualname____doc____annotations__     S/var/www/html/ai-engine/env/lib/python3.11/site-packages/pikepdf/models/metadata.pyr4   r4   W   s6         @@MMMMMM""""""rA   r4   c                      e Zd ZdZdS )
NeverRaisez"An exception that is never raised.Nr;   r<   r=   r>   r@   rA   rB   rD   rD   b   s        ,,,,rA   rD   c                      e Zd ZdZdS )AltListzXMP AltList container.NrE   r@   rA   rB   rG   rG   f   s            rA   rG   AltBagSeqtitledescriptionrights
UsageTermszL(?u)[^\x09\x0A\x0D\x20-\U0000D7FF\U0000E000-\U0000FFFD\U00010000-\U0010FFFF]s   [^\x09\x0A\x0D\x20-\xFF]|&#0;xmlbytesc                :    t          t          |                     S Nr   r   rO   s    rB   _parser_basicrU      s    WS\\"""rA   c                l    t          t          t                              d|                               S NrA   )r   r   re_xml_illegal_bytessubrT   s    rB   _parser_strip_illegal_bytesrZ      s)    W155c3??@@AAArA   c                >    t          t          |           d          S )NT)recoverrS   rT   s    rB   _parser_recoveryr]      s    WS\\40000rA   rA   _xmlc                ^    t                               d           t          t                    S )Nz5Error occurred parsing XMP, replacing with empty XMP.)logwarningrU   	XMP_EMPTY)r^   s    rB   _parser_replace_with_empty_xmprc      s#    KKGHHH###rA   ; sstr | Iterable[str]joinerr5   returnc                j   t          | t                    st          | t                    r`t          d|             t          | t                    r#|                    t          |                     } n%|                    |           } nt          d          t          	                    d|           S )a  Ensure 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 )

isinstancer5   r   r   setjoinsorted	TypeErrorre_xml_illegal_charsrY   )re   rg   s     rB   _cleanrq      s     a Na"" 	N+++,,,!S!! #KKq		**KKNNLMMM##B***rA   dr	   c                    d| j         d}||                     d          z  }|                     d          }|r(|d         |dd         |dd         }}}|| | d	| z  }|S )
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)rr   re   tzsigntz_hourstz_minss         rB   encode_pdf_dater      s    . 	QVAM	"	""A	
D		B	 +"$Q%AaC"QqS'h	*h*****HrA   c                   t          | t                    rt          |           } | }|                    d          r
|dd         }g d}|D ]/}|                    |          r|                    |d          } n0|                    dd          }g d}|D ])}	 t          j        ||          c S # t          $ r Y &w xY wt          d	|  d
| d          )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   rj   )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 ))	rk   r   r5   
startswithendswithreplacer	   strptime
ValueError)re   tutcsutcdate_formatsdate_formats         rB   decode_pdf_dater      s0    !V FF	A||D abbE  D
   ::c?? 			#w''AE	 	
		#rA  L
 $  	$Q44444 	 	 	H	
VQVVRSVVV
W
WWs   B22
B?>B?c                  b    e Zd ZdZeed
d                        Zeedd                        Zd	S )	ConverterzXMP <-> DocumentInfo converter.docinfo_val
str | Nonerh   r   c                    dS )z/Derive XMP metadata from a DocumentInfo string.Nr@   r   s    rB   xmp_from_docinfozConverter.xmp_from_docinfo         rA   xmp_valc                    dS )z9Derive a DocumentInfo value from equivalent XMP metadata.Nr@   r   s    rB   docinfo_from_xmpzConverter.docinfo_from_xmp   r   rA   Nr   r   rh   r   )r   r   rh   r   )r;   r<   r=   r>   staticmethodr   r   r   r@   rA   rB   r   r      sr        ))> > > ^ \> H H H ^ \H H HrA   r   c                  @    e Zd ZdZed	d            Zed             ZdS )
AuthorConverterz-Convert XMP document authors to DocumentInfo.r   r   rh   r   c                    | gS )z*Derive XMP authors info from DocumentInfo.r@   r   s    rB   r   z AuthorConverter.xmp_from_docinfo   s     }rA   c                    t          | t                    r| S | | dgk    rdS d                    d | D                       S )zDerive DocumentInfo authors from XMP.

        XMP supports multiple author values, while DocumentInfo has a string,
        so we return the values separated by semi-colons.
        Nrd   c              3     K   | ]}||V  	d S rR   r@   ).0authors     rB   	<genexpr>z3AuthorConverter.docinfo_from_xmp.<locals>.<genexpr>  s'      LLF9K9K9K9K9KLLrA   )rk   r5   rm   r   s    rB   r   z AuthorConverter.docinfo_from_xmp  sR     gs## 	N?g$//4yyLLgLLLLLLrA   Nr   r;   r<   r=   r>   r   r   r   r@   rA   rB   r   r      sX        77   \ 
M 
M \
M 
M 
MrA   r   c                  >    e Zd ZdZed             Zed             ZdS )DateConverterz"Convert XMP dates to DocumentInfo.c                T    | dk    rdS t          |                                           S )z"Derive XMP date from DocumentInfo.rj   )r   	isoformatr   s    rB   r   zDateConverter.xmp_from_docinfo  s.     "2{++55777rA   c                    |                      d          r| dd         dz   } t          j        |           }t          |          S )zDerive DocumentInfo from XMP.r   Nz+00:00)r   r	   fromisoformatr   )r   dateobjs     rB   r   zDateConverter.docinfo_from_xmp  sJ     C   	.crclX-G(11w'''rA   Nr   r@   rA   rB   r   r     sN        ,,8 8 \8 ( ( \( ( (rA   r   c                  <    e Zd ZU dZded<   ded<   ded<   ded<   d	S )
DocinfoMappingzEMap DocumentInfo keys to their XMP equivalents, along with converter.r5   nskeyr   nameztype[Converter] | None	converterNr:   r@   rA   rB   r   r   #  s?         OOGGGHHHJJJ%%%%%%rA   r   c                <     t                      fd            }|S )z|Ensure the XMP has been loaded and parsed.

    TODO: Can this be removed? Why allow the uninit'ed state to even exist?
    c                R    | j         s|                                   | g|R i |S rR   )_xmp_load)selfargskwargsfns      rB   wrapperzensure_loaded.<locals>.wrapper2  s:    y 	JJLLLr$(((((((rA   r   )r   r   s   ` rB   ensure_loadedr   ,  s5     2YY) ) ) ) Y)
 NrA   c                  Z   e Zd ZU dZ eedej        e           eedej	        d           eedej
        d           eedej        d           eedej        d           eedej        e           eed	ej        d           eed
ej        e          gZded<   d eD             Zded<    ee          Zded<   eeeegZded<   egZded<   ed             Z 	 	 	 dQdRdZ!	 dSdTd"Z"dUd#Z#dVd&Z$e%d'             Z&d( Z'd) Z(dWd*Z)d+ Z*edXd/            Z+d0 Z,dYd4Z-dZd5Z.	 d[d\d9Z/d[d]d;Z0e%d^d=            Z1e%d^d>            Z2e%d?             Z3e%d@             Z4	 d_d`dDZ5dadFZ6dbdIZ7dJ Z8dK Z9e%dcdL            Z:e%d^dM            Z;e<dddN            Z=e<dddO            Z>e%dP             Z?dS )ePdfMetadataa=  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`
    creatorrL   NrK   KeywordsProducer
CreateDateCreatorTool
ModifyDatezlist[DocinfoMapping]DOCINFO_MAPPINGc                    i | ]\  }}||	S r@   r@   )r   uriprefixs      rB   
<dictcomp>zPdfMetadata.<dictcomp>d  s    LLL+#v&#LLLrA   zdict[str, str]NS
REVERSE_NSz Iterable[Callable[[bytes], Any]]_PARSERS_OVERWRITE_INVALID_XML_PARSERS_STANDARDc                l    || j         |<   || j        |<   t          j        t          t
                     dS )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)clsr   r   s      rB   register_xml_namespacez"PdfMetadata.register_xml_namespaceo  s4     v$s $/////rA   Tr   r   pikepdf_markboolsync_docinfooverwrite_invalid_xmlc                Z    || _         || _        || _        d| _        || _        d| _        dS )z7Construct PdfMetadata. Use Pdf.open_metadata() instead.FN)_pdfmarkr   	_updatingr   r   )r   r   r   r   r   s        rB   __init__zPdfMetadata.__init__{  s4     	 	(%:"			rA   Fdelete_missingraise_failurerh   Nonec                j   d
fd	}| j         D ]\  }}}}t          ||          }	|                    t          |                    }
|

|r|	| v r| |	= E	 t          |
          }
|r|                    |
          }
|
so|                     |	|
d           # t          t          t          f$ r} |d| d|           Y d}~d}~ww xY wd | j         D             }d |	                                D             |z
  }|D ]4} |d| dt          |                    |                     d	           5dS )a1  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                J    rt          |           |t          |            d S rR   )r   r   )msger   s     rB   warn_or_raisez4PdfMetadata.load_from_docinfo.<locals>.warn_or_raise  s(     - oo1,IIIIIrA   TzThe metadata field z could not be copied to XMPc                6    h | ]\  }}}}t          |          S r@   r5   )r   _docinfo_names      rB   	<setcomp>z0PdfMetadata.load_from_docinfo.<locals>.<setcomp>  s5     
 
 
"7!QaC
 
 
rA   c                ,    h | ]}t          |          S r@   r   )r   ks     rB   r   z0PdfMetadata.load_from_docinfo.<locals>.<setcomp>  s    >>>!s1vv>>>rA   z with value 'z,' has no XMP equivalent, so it was discardedrR   )r   r   getr5   r   _setitemr   AttributeErrorNotImplementedErrorkeysrepr)r   docinfor   r   r   r   shortkeyr   r   qnamevalr   valid_docinfo_namesextra_docinfo_namesextras      `           rB   load_from_docinfozPdfMetadata.load_from_docinfo  s   "	 	 	 	 	 	
 7;6J 	 	2C<#x((E ++c,//00C{! $etmmU
#hh :#44S99C eS$////0CD   S,SSSUV       
 
;?;O
 
 
 ?>w||~~>>>ATT( 	 	EM=e = =$w{{5?Q?Q:R:R = = =   	 	s   (B>BC-CCc                    	 | j         j        j                                        }n# t          $ r d}Y nw xY w|                     |           d S rW   )r   RootMetadata
read_bytesr   
_load_from)r   datas     rB   r   zPdfMetadata._load  s]    	9>*5577DD 	 	 	DDD	s   #& 55r  rP   c                \   |                                 dk    rt          }| j        r| j        n| j        }|D ]}	  ||          | _         n# | j        rt          nt          $ rg}t          |          	                    d          s"t          |          	                    d          rt                      | _        Y d }~ nY d }~d }~ww xY w| j        	 | j                            d          }|D ]!}t          j        | j        |j                   "|                                  d S # | j        rt           nt          $ r:}t"                              d|           t                      | _        Y d }~d S d }~ww xY wt"                              d           t                      | _        d S )NrA   z!Start tag expected, '<' not foundzDocument is emptyz/processing-instruction()zError occurred parsing XMP)exc_info)striprb   r   r   r   r   r   rD   r5   r   rc   xpathr   
strip_tagstag_get_rdf_root	Exceptionr`   ra   )r   r  parsersparserr   pispis          rB   r   zPdfMetadata._load_from  s   ::<<3D )(D//' 	  	 	F"F4LL	  #'"<L*   q66$$%HII SN N*011 !? @ @DIEEEEE	     9 =ioo&ABB 8 8B$TY7777""$$$$$ - 		= = =
 81EEE:<<							= KK4555688DIIIs1   AC$ACCAD* *E</E77E<c                    d| _         | S )zOpen metadata for editing.T)r   r   s    rB   	__enter__zPdfMetadata.__enter__  s     rA   c                n    	 |
	 d| _         dS |                                  d| _         dS # d| _         w xY w)z!Close metadata and apply changes.NF)r   _apply_changes)r   exc_typeexc_valexc_tbs       rB   __exit__zPdfMetadata.__exit__  sO    	## #DNNN !!!"DNNNUDN""""s   + + 	4c           
     r   | j         j         | j        D ]!\  }}}}t          ||          }	 | |         }n+# t          $ r || j         j        v r| j         j        |= Y Iw xY w|rb	 |                    |          }nK# t          $ r t          d| d           d}Y n*t          $ r}t          d| d| d|           |d}~ww xY w||| j         j        v r| j         j        |= t          |          }	 |
                    d          | j         j        |<   # t          $ r || j         j        |<   Y w xY wdS )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	  rq   encodeUnicodeEncodeError)r   r   elementr   r   r   valuer   s           rB   _update_docinfozPdfMetadata._update_docinfo  s    		595I  	8  	81C,	#w''EU   49#444	),7  %66u==EE! ! ! !+, + + +   !EEE    $N'N N38N NFKN N  
 }49#444	),75MME827,,w2G2G	!,//% 8 8 827	!,///8= 	8  	8s?   6%AA$A::C	C$B==C3"DD43D4c                   t                      }|r|                    t                     | j                            |dd           |r|                    t                     |                    d           |                                }|S )Nutf-8T)encodingpretty_printr   )r   writeXPACKET_BEGINr   XPACKET_ENDseekread)r   xpacketr  	xml_bytess       rB   _get_xml_byteszPdfMetadata._get_xml_bytes'  s{    yy 	&JJ}%%%	wTBBB 	$JJ{###		!IIKK	rA   c                v   | j         r|                     t          t          d          t	          j        t          j                                                  d           |                     t          t          d          dt          z   d           |                                 }t          | j        |          | j        j        _        t           j        | j        j        j        t           j        <   t           j        | j        j        j        t           j        <   | j        r|                                  dS dS )zSerialize 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_versionr*  r   r   r   r   r   TypeXMLSubtyper   r  )r   rO   s     rB   r  zPdfMetadata._apply_changes2  s   
 9 	MMj.11X\**4466"    
 MMj*--_,"    
 !!##"(C"8"8	-1]		*04	- 	#  """""	# 	#rA   r   QName | strr5   c                   t          |t                    rt          |          S t          |t                    st          | d          |dk    r|S |                    d          r|S 	 |                    dd          \  }}n# t          $ r d|}}Y nw xY w| j                            |d          }t          t          ||                    S )zkConvert name to an XML QName.

        e.g. pdf:Producer -> {http://ns.adobe.com/pdf/1.3/}Producer
        z must be strrj   {:rv   maxsplitN)	rk   r   r5   ro   r   splitr   r   r   )r   r   r   r  r   s        rB   _qnamezPdfMetadata._qnameJ  s     dE"" 	t99$$$ 	3t1112222::K??3 	K	#**S1*55KFCC 
	# 
	# 
	# dCFFF
	# fjj&&5c??###s   ,B BBc                    |                     dd          \  }}|                    dd          }| j        |         dz   |z   S )z~Given a fully qualified XML name, find a prefix.

        e.g. {http://ns.adobe.com/pdf/1.3/}Producer -> pdf:Producer
        }rv   r9  r7  rj   r8  )r;  r   r   )r   urinameuripartr  r   s        rB   _prefix_from_urizPdfMetadata._prefix_from_urih  sG    
 }}S1}55ooc2&&s#c)C//rA   noder   r   c                "   |                     d| j                  }|	 |d         j        S # t          $ r Y dS w xY wt          D ]J\  }}}|                     d| | j                  }|' |            }|D ]} |||j                   |c S dS )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:AltNr   rj   zrdf:)findr   text
IndexErrorXMP_CONTAINERS)r   rB  itemsxmlcontainer	containerinsertfnresultitems           rB   _get_subelementszPdfMetadata._get_subelementsq  s     		)TW--Qx}$   rr 2@ 	 	-L)XII3\33TW==E}Y[[F , ,++++MMMrs   , 
::c                    | j         J | j                             d| j                  }|3| j                                         }|j        dk    st          d          |S )Nz
.//rdf:RDFz0{http://www.w3.org/1999/02/22-rdf-syntax-ns#}RDFz$Metadata seems to be XML but not XMP)r   rD  r   getrootr  r   )r   r*   s     rB   r  zPdfMetadata._get_rdf_root  sa    y$$$inn\4733;)##%%C7PPP !GHHH
rA   rj   str | QName<Iterator[tuple[_Element, str | bytes | None, Any, _Element]]c              #  *  K   |                      |          }|                                 }|                    d| j                  D ]}|r2||                                v r|||                    |          |fV  n&|s$|                                D ]\  }}|r||||fV  |r|nd}|                    || j                  D ]M}|j        r'|j                                        r|d|j        |fV  0| 	                    |          }	|d|	|fV  NdS )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)

        zrdf:Description[@rdf:about=""]*N)
r<  r  findallr   r   r   rH  rE  r  rN  )
r   r   r   r*   rdfdescr   vr  rB  valuess
             rB   _get_elementszPdfMetadata._get_elements  sg     2 D!!  ""{{#CTWMM 	4 	4G 3',,..00w{{5'9'93????? 3#MMOO 3 3DAq 3&1c2222!*EEsEtw77 4 49 !2!2 ty'::::..t44T67333334	4 	4rA   Iterator[Any]c              #  T   K   d |                      |          D             E d {V  d S )Nc              3  &   K   | ]}|d          V  dS )r   Nr@   )r   rW  s     rB   r   z2PdfMetadata._get_element_values.<locals>.<genexpr>  s&      ;;QAaD;;;;;;rA   )rY  )r   r   s     rB   _get_element_valueszPdfMetadata._get_element_values  s@      ;;$"4"4T":":;;;;;;;;;;;;rA   r   c                F    t          |                     |                    S )zTest if XMP key is in metadata.)anyr]  r   r   s     rB   __contains__zPdfMetadata.__contains__  s      4++C00111rA   c                    	 t          |                     |                    S # t          $ r t          |          dw xY w)zRetrieve XMP metadata for key.N)nextr]  StopIterationr  r`  s     rB   __getitem__zPdfMetadata.__getitem__  sL    	*0055666 	* 	* 	*3--T)	*s   !$ ?c              #  b   K   |                                  D ]\  }}}}|r|V  |j        V  dS )z2Iterate through XMP metadata attributes and nodes.N)rY  r  )r   rB  attrib_val_parentss        rB   __iter__zPdfMetadata.__iter__  sV       -1,>,>,@,@ 	 	(D&$ h		 	rA   c                T    t          t          t          |                               S )z#Return number of items in metadata.)lenlistiterr  s    rB   __len__zPdfMetadata.__len__  s      4T

##$$$rA   r   set[str] | list[str] | strr-  c                
   | j         st          d          |                     |          }|                     ||||           	 |                     |||           d S # t
          $ r |                     ||           Y d S w xY w)N/Metadata not opened for editing, use with block)r   RuntimeErrorr<  _setitem_check_args_setitem_updaterd  _setitem_insertr   r   r   r-  qkeys        rB   r   zPdfMetadata._setitem  s     ~ 	RPQQQ{{3  c=$???	+  c400000 	+ 	+ 	+  c******	+s   A  BBrx  c                F   | j         rL|sJ||                     d          |                     d          fv rt                              d| d           t	          |t
                    r6||                     d          v r!t                              | d           d S d S d S )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   r<  r`   ra   rk   r5   errorrw  s        rB   rt  zPdfMetadata._setitem_check_args  s    I	!	 .//N++  KK2S 2 2 2   c3 	CDT[[-F-F$G$GIIAAABBBBB	C 	C$G$GrA   rH  r   c           
        t          fdt          D                       }t          j        |t	          t          t          |                              }d }|dk    r$t	          t          t          d                    di}D ]Y}t          j        |t	          t          t          d                    |          }|t          |          }|dk    rd }||_	        Zd S )Nc              3  P   K   | ] }t          |j                  |j        V  !d S rR   )rk   r8   r6   )r   crH  s     rB   r   z1PdfMetadata._setitem_add_array.<locals>.<genexpr>  sJ       
 
*UAI2N2N
J
 
 
 
 
 
rA   rH   langz	x-defaultlirg  rj   )
rc  rG  r   
SubElementr5   r   
XMP_NS_RDF
XMP_NS_XMLrq   rE  )	r   rB  rH  r6   seq
tag_attribrM  el
inner_texts	     `      rB   _setitem_add_arrayzPdfMetadata._setitem_add_array  s     
 
 
 
 .
 
 
 
 
 tSz8)D)D%E%EFF,0
ueJ7788+FJ 	% 	%D!#s5T+B+B'C'CJWWWB)/
##!%J$	% 	%rA   c           
        t          |                     |                    \  }}}}|rt          |t                    sk||                     d          k    r-|j        |= |                     |t          |                     d S t          d| d| dt          |                     |
                    |t          |                     d S t          |t          t          f          rE|                    d          D ]}|                    |           |                     ||           d S t          |t                    r|                    d          D ]}|                    |           t          |                     |                    t          v r3|                     |t          t          |          g                     d S t          |          |_        d S t          d| d| dt          |                     )Nrz  Setting  to  with type rT  )rc  rY  rk   r5   r<  rg  r  rq   ro   r7   rl   rm  rU  remove	LANG_ALTSrG   rE  )	r   r   r   rx  rB  rg  _oldval_parentchilds	            rB   ru  zPdfMetadata._setitem_update  s   )-d.@.@.E.E)F)F&fgw 	Mc3'' 	.4;;|4444 D)++D&++>>>>>#$Ss$S$S$S$SS		$S$STTT-----dC[)) 	Mc** # #E""""##D#.....S!! 	Mc** # #E""""4;;s##$$	11''gvc{{m.D.DEEEEE"3KK			KsKKKKS		KKLLLrA   c           
     v   |                                  }t          |                     |                    t          v rt	          t          |          g          }t          |t          t          f          rt          j
        |t          t          t          d                    t          t          t          d                    di          }t          j
        ||                     |                    }|                     ||           d S t          |t                    rpt          j
        |t          t          t          d                    t          t          d          d|                     |          t          |          i          }d S t          d| d| dt          |                     d )NDescriptionaboutrj   r  r  r  r  )r  r5   r<  r  rG   rq   rk   rm  rl   r   r  r   r  r  ro   r7   )r   r   r   r*   rV  rB  _rdfdescs          rB   rv  zPdfMetadata._setitem_insert-  s     ""t{{3  I--6#;;-((CcD#;'' 	W&E*m4455E*g6677<  G
 #GT[[-=-=>>D##D#.....S!! 
	W'E*m4455*g..KK$$fSkk  HHH KsKKKKS		KKLLRVVrA   c                0    |                      ||d          S )zSet XMP metadata key to value.F)r   )r   r   r   s      rB   __setitem__zPdfMetadata.__setitem__E  s     }}S#u---rA   c                   | j         st          d          	 t          |                     |                    \  }}}}|r~|j        |= t          |j                  dk    rXt          |          dk    rGt          t          d          |j                                        v r|	                    |           dS dS dS dS |	                    |           dS # t          $ r t          |          dw xY w)zDelete item from XMP metadata.rr  rv   r   r  N)r   rs  rc  rY  rg  rl  r   r  r   r  rd  r  )r   r   rB  rg  r  parents         rB   __delitem__zPdfMetadata.__delitem__J  s    ~ 	RPQQQ	*,01C1CC1H1H,I,I)D&'6 
$K'$$))D		Qj'22dk6F6F6H6HHH MM$''''' *)&HH
 d##### 	* 	* 	*3--T)	*s   BC ?C C1c                    | j         s|                                  t          t          d          }t          t          d          }	 | |         | |         z   S # t          $ r Y dS w xY w)a  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.
        partconformancerj   )r   r   r   XMP_NS_PDFA_IDr  )r   key_partkey_conformances      rB   pdfa_statuszPdfMetadata.pdfa_status_  st     y 	JJLLL00>>	>D$999 	 	 	22	s   A 
A&%A&c                    | j         s|                                  t          t          d          }	 | |         S # t          $ r Y dS w xY w)a  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_PDFXVersionrj   )r   r   r   XMP_NS_PDFX_IDr  )r   pdfx_versions     rB   pdfx_statuszPdfMetadata.pdfx_statusw  s]     y 	JJLLL^->??	%% 	 	 	22	s   : 
AAc                T    |                      d                              d          S )z#Convert XMP metadata to XML string.F)r(  r   )r*  decoder  s    rB   __str__zPdfMetadata.__str__  s)     ""5"1188AAArA   )TTT)r   r   r   r   r   r   r   r   )FF)r   r   r   r   rh   r   )rh   r   )r  rP   rh   r   )T)r   r5  rh   r5   )rB  r   rh   r   )rh   r   )rj   )r   rQ  rh   rR  )r   rQ  rh   rZ  )r   rQ  )F)r   rQ  r   rp  r-  r   )r-  r   rx  r5   rh   r   )rH  r   rh   r   )r   rQ  r   rp  )rh   r5   )@r;   r<   r=   r>   r   	XMP_NS_DCr   Authorr   SubjectTitler0  r   r   r.  CreationDater   CreatorModDater   r?   r2   r   dictr   rU   rZ   r]   rc   r   r   classmethodr   r   r   r   r   r   r  r  r  r*  r  r<  rA  rN  r  rY  r]  ra  re  rj  ro  r   rt  r  ru  rv  r  r  propertyr  r  r  r@   rA   rB   r   r   ;  s^         < 	y)T[/JJy-tDDy'4:t<<z:t}dCCz:t}dCCz<1BMRRz=$,EEz<}MM	-O 	 	 	 	 ML9KLLLBLLLL!%&8!9!9J9999 	#&	H"     <I/IIII	0 	0 [	0 "!&*      LQ2 2 2 2 2h   '9 '9 '9 '9R   ]
# # #(8 (8 (8T	 	 	 	# # #0 $ $ $ [$:0 0 0   0    #%(4 (4 (4 (4 (4T< < < < < 2 2 2 ]2 * * * ]*   ] % % ]% $	+ + + + +&C C C C(% % % % M M M8W W W0 . . . ]. * * * ]*(    X.    X* B B ]B B BrA   r   )rO   rP   )rA   )r^   rP   )rd   )re   rf   rg   r5   rh   r5   )rr   r	   rh   r5   )re   r5   rh   r	   )br>   
__future__r   loggingreabcr   r   collections.abcr   r   r   r	   r
   	functoolsr   ior   typingr   r   r   r   warningsr   lxmlr   
lxml.etreer   r   pikepdf._versionr   r1  pikepdf._xmlr   r   pikepdf.objectsr   r   r   pikepdfr   r  r0  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   r?   r   r   r   r  r$  rb   r%  r4   	getLoggerr;   r`   r	  rD   rm  rG   appendrl   addrG  	frozensetr5   r  compilerp   rX   rU   rZ   r]   rc   rq   r   r   r   r   r   r   r   r   r@   rA   rB   <module>r     s      " " " " " "  				 # # # # # # # # > > > > > > > > > > ' ' ' ' ' ' ' '             ; ; ; ; ; ; ; ; ; ; ; ;             , , , , , , , , ; ; ; ; ; ; , , , , , , , , 0 0 0 0 0 0 0 0 0 0  /	+
2@ > : 427 ?@@:
+
19  XO,>*&i X{#7HHG$73-3+-     0 ( , ,MD'EWd++++ 4
W	 -# # # # #: # # # g!!- - - - - - - -! ! ! ! !d ! ! !
 L00LSW%%Ldk** IEE)W%%&&EE)]++,,EE)X&&''EE#\2233	 	 "rzS   "rz"CDD # # # #B B B B1 1 1 1$ $ $ $ $
+ + + + +&   @ X  X  X  XFH H H H H H H HM M M M Mi M M M,( ( ( ( (I ( ( (&& & & & &Z & & &  U	B U	B U	B U	B U	B. U	B U	B U	B U	B U	BrA   