Ë
    ^ãj9"  ã                  óà   — d 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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 ddlmZ erddlmZ ddlmZ ddlmZ  G d„ d«      Z G d„ d«      Zy)z8Objects that implement reading and writing OPC packages.é    )Úannotations)ÚIOÚTYPE_CHECKINGÚIteratorÚcast)ÚRELATIONSHIP_TYPE)ÚPACKAGE_URIÚPackURI)ÚPartFactory)ÚCorePropertiesPart)ÚPackageReader)ÚPackageWriter)ÚRelationships)Úlazyproperty)ÚCoreProperties)ÚPart)Ú_Relationshipc                  óÊ   ‡ — e Zd ZdZˆ fd„Zd„ Zedd„«       Zdd„Zdd„Z	ddd„Z
ed„ «       Zdd	„Zedd
„«       Zdd„Zedd„«       Zdd„Zed„ «       Zdd„Zedd„«       Zˆ xZS )Ú
OpcPackagez·Main API class for |python-opc|.

    A new instance is constructed by calling the :meth:`open` class method with a path
    to a package file or file-like object containing one.
    c                ó*   •— t         t        | �  «        y ©N)Úsuperr   Ú__init__)ÚselfÚ	__class__s    €úR/var/www/html/metafoliadorv2/venv/lib/python3.12/site-packages/docx/opc/package.pyr   zOpcPackage.__init__   s   ø€ ÜŒj˜$Ñ(Õ*ó    c                 ó   — y)z…Entry point for any post-unmarshaling processing.

        May be overridden by subclasses without forwarding call to super.
        N© ©r   s    r   Úafter_unmarshalzOpcPackage.after_unmarshal    s   € ð 	r   c                ó.   — | j                   j                  S )zl|CoreProperties| object providing read/write access to the Dublin Core
        properties for this document.)Ú_core_properties_partÚcore_propertiesr    s    r   r$   zOpcPackage.core_properties)   s   € ð ×)Ñ)×9Ñ9Ð9r   c              #  óJ   ‡K  — 	 d	 	 	 	 	 dˆfd„Š ‰| «      D ]  }|–— Œ y­w)zƒGenerate exactly one reference to each relationship in the package by
        performing a depth-first traversal of the rels graph.Nc              3  óæ   •K  — |€g n|}| j                   j                  «       D ]I  }|–— |j                  rŒ|j                  }||v rŒ%|j	                  |«       |} ‰||«      D ]  }|–— Œ ŒK y ­wr   ©ÚrelsÚvaluesÚis_externalÚtarget_partÚappend)ÚsourceÚvisitedÚrelÚpartÚ
new_sourceÚ	walk_relss        €r   r2   z'OpcPackage.iter_rels.<locals>.walk_rels3   s~   øè ø€ ð $˜O‘b°ˆGØ—{‘{×)Ñ)Ó+ò 
�Ø’	Ø—?’?ØØ—‘�Ø˜7‘?ØØ—‘˜tÔ$Ø!�
Ù$ Z°Ó9ò �CØ“Iññ
ùs   ƒA.A1r   )r-   zOpcPackage | Partr.   zlist[Part] | NoneÚreturnúIterator[_Relationship]r   )r   r/   r2   s     @r   Ú	iter_relszOpcPackage.iter_rels/   sE   øè ø€ ð
 EIð	Ø%ð	Ø0Að	à$õ	ñ  ˜T“?ò 	ˆCØ‹Iñ	ùs   ƒ #c              #  ó>   ‡K  — g fˆfd„	Š ‰| «      D ]  }|–— Œ y­w)zƒGenerate exactly one reference to each of the parts in the package by
        performing a depth-first traversal of the rels graph.c              3  óÚ   •K  — | j                   j                  «       D ]I  }|j                  rŒ|j                  }||v rŒ!|j	                  |«       |–— |} ‰||«      D ]  }|–— Œ ŒK y ­wr   r'   )r-   r.   r/   r0   r1   Ú
walk_partss        €r   r8   z)OpcPackage.iter_parts.<locals>.walk_partsJ   sq   øè ø€ Ø—{‘{×)Ñ)Ó+ò 
�Ø—?’?ØØ—‘�Ø˜7‘?ØØ—‘˜tÔ$Ø’
Ø!�
Ù& z°7Ó;ò �DØ“Jññ
ùs   ƒA(A+Nr   )r   r0   r8   s     @r   Ú
iter_partszOpcPackage.iter_partsF   s,   øè ø€ ð (*õ 	ñ ˜tÓ$ò 	ˆDØ‹Jñ	ùs   ƒc                ó>   — | j                   j                  ||||«      S )a}  Return newly added |_Relationship| instance of `reltype` between this part
        and `target` with key `rId`.

        Target mode is set to ``RTM.EXTERNAL`` if `is_external` is |True|. Intended for
        use during load from a serialized package, where the rId is well known. Other
        methods exist for adding a new relationship to the package during processing.
        )r(   Úadd_relationship)r   ÚreltypeÚtargetÚrIdr*   s        r   Úload_relzOpcPackage.load_relZ   s   € ð �y‰y×)Ñ)¨'°6¸3ÀÓLÐLr   c                ó@   — | j                  t        j                  «      S )a  Return a reference to the main document part for this package.

        Examples include a document part for a WordprocessingML package, a presentation
        part for a PresentationML package, or a workbook part for a SpreadsheetML
        package.
        )Úpart_related_byÚRTÚOFFICE_DOCUMENTr    s    r   Úmain_document_partzOpcPackage.main_document_partd   s   € ð ×#Ñ#¤B×$6Ñ$6Ó7Ð7r   c                óÂ   — | j                  «       D �ch c]  }|j                  ’Œ }}t        dt        |«      dz   «      D ]  }||z  }||vsŒt	        |«      c S  yc c}w )a“  Return a |PackURI| instance representing partname matching `template`.

        The returned part-name has the next available numeric suffix to distinguish it
        from other parts of its type. `template` is a printf (%)-style template string
        containing a single replacement item, a '%d' to be used to insert the integer
        portion of the partname. Example: "/word/header%d.xml"
        é   é   N)r9   ÚpartnameÚrangeÚlenr
   )r   Útemplater0   Ú	partnamesÚnÚcandidate_partnames         r   Únext_partnamezOpcPackage.next_partnamen   se   € ð 04¯©Ó/@ÖA t�T—]“]ÐAˆ	ÐAÜ�qœ#˜i›.¨1Ñ,Ó-ò 	3ˆAØ!)¨A¡ÐØ!¨Ò2ÜÐ1Ó2Ò2ñ	3ùò Bs   “Ac                ót   — t        j                  |«      } | «       }t        j                  ||t        «       |S )zGReturn an |OpcPackage| instance loaded with the contents of `pkg_file`.)r   Ú	from_fileÚUnmarshallerÚ	unmarshalr   )ÚclsÚpkg_fileÚ
pkg_readerÚpackages       r   ÚopenzOpcPackage.open|   s2   € ô #×,Ñ,¨XÓ6ˆ
Ù“%ˆÜ×Ñ˜z¨7´KÔ@Øˆr   c                ó8   — | j                   j                  |«      S )zÍReturn part to which this package has a relationship of `reltype`.

        Raises |KeyError| if no such relationship is found and |ValueError| if more than
        one such relationship is found.
        )r(   Úpart_with_reltype)r   r<   s     r   rA   zOpcPackage.part_related_by„   s   € ð �y‰y×*Ñ*¨7Ó3Ð3r   c                ó4   — t        | j                  «       «      S )zJReturn a list containing a reference to each of the parts in this package.)Úlistr9   r    s    r   ÚpartszOpcPackage.partsŒ   s   € ô �D—O‘OÓ%Ó&Ð&r   c                óR   — | j                   j                  ||«      }|j                  S )zãReturn rId key of new or existing relationship to `part`.

        If a relationship of `reltype` to `part` already exists, its rId is returned. Otherwise a
        new relationship is created and that rId is returned.
        )r(   Ú
get_or_addr>   )r   r0   r<   r/   s       r   Ú	relate_tozOpcPackage.relate_to‘   s#   € ð �i‰i×"Ñ" 7¨DÓ1ˆØ�w‰wˆr   c                ó4   — t        t        j                  «      S )ztReturn a reference to the |Relationships| instance holding the collection of
        relationships for this package.)r   r	   ÚbaseURIr    s    r   r(   zOpcPackage.relsš   s   € ô œ[×0Ñ0Ó1Ð1r   c                óœ   — | j                   D ]  }|j                  «        Œ t        j                  || j                  | j                   «       y)znSave this package to `pkg_file`.

        `pkg_file` can be either a file-path or a file-like object.
        N)r]   Úbefore_marshalr   Úwriter(   )r   rU   r0   s      r   ÚsavezOpcPackage.save    s=   € ð
 —J‘Jò 	"ˆDØ×ÑÕ!ð	"ä×Ñ˜H d§i¡i°·±Õ<r   c                óê   — 	 t        t        | j                  t        j                  «      «      S # t
        $ r: t        j                  | «      }| j                  |t        j                  «       |cY S w xY w)z‘|CorePropertiesPart| object related to this package.

        Creates a default core properties part if one is not present (not common).
        )r   r   rA   rB   ÚCORE_PROPERTIESÚKeyErrorÚdefaultr`   )r   Úcore_properties_parts     r   r#   z OpcPackage._core_properties_part©   sa   € ð	(ÜÔ*¨D×,@Ñ,@Ä×ASÑASÓ,TÓUÐUøÜò 	(Ü#5×#=Ñ#=¸dÓ#CÐ Ø�N‰NÐ/´×1CÑ1CÔDØ'Ò'ð	(ús   ‚,/ ¯A A2Á1A2)r3   r   )r3   r4   )r3   zIterator[Part])F)r<   Ústrr=   z
Part | strr>   rl   r*   Úbool)rK   rl   r3   r
   )rU   ústr | IO[bytes]r3   r   )r<   rl   r3   r   )r3   z
list[Part])r0   r   r<   rl   )rU   rn   )r3   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r!   Úpropertyr$   r5   r9   r?   rD   rO   ÚclassmethodrX   rA   r]   r`   r   r(   rf   r#   Ú__classcell__)r   s   @r   r   r      s®   ø„ ñô+òð ò:ó ð:ó
ó.ô(Mð ñ8ó ð8ó3ð òó ðó4ð ò'ó ð'óð ñ2ó ð2ó
=ð ò
(ó ô
(r   r   c                  ó@   — e Zd ZdZed„ «       Zed„ «       Zed„ «       Zy)rR   zHHosts static methods for unmarshalling a package from a |PackageReader|.c                óÊ   — t         j                  | ||«      }t         j                  | ||«       |j                  «       D ]  }|j	                  «        Œ |j	                  «        y)zÖConstruct graph of parts and realized relationships based on the contents of
        `pkg_reader`, delegating construction of each part to `part_factory`.

        Package relationships are added to `pkg`.
        N)rR   Ú_unmarshal_partsÚ_unmarshal_relationshipsr)   r!   )rV   rW   Úpart_factoryr]   r0   s        r   rS   zUnmarshaller.unmarshalº   sW   € ô ×-Ñ-¨j¸'À<ÓPˆÜ×-Ñ-¨j¸'À5ÔIØ—L‘L“Nò 	#ˆDØ× Ñ Õ"ð	#à×ÑÕ!r   c                ó\   — i }| j                  «       D ]  \  }}}} ||||||«      ||<   Œ |S )zÏReturn a dictionary of |Part| instances unmarshalled from `pkg_reader`, keyed
        by partname.

        Side-effect is that each part in `pkg_reader` is constructed using
        `part_factory`.
        )Úiter_sparts)rV   rW   rz   r]   rH   Úcontent_typer<   Úblobs           r   rx   zUnmarshaller._unmarshal_partsÇ   sH   € ð ˆØ5?×5KÑ5KÓ5Mò 	[Ñ1ˆH�l G¨TÙ*¨8°\À7ÈDÐRYÓZˆE�(ŠOð	[àˆr   c                óþ   — | j                  «       D ]j  \  }}|dk(  r|n||   }|j                  r|j                  n||j                     }|j	                  |j
                  ||j                  |j                  «       Œl y)z±Add a relationship to the source object corresponding to each of the
        relationships in `pkg_reader` with its target_part set to the actual target part
        in `parts`.ú/N)Ú
iter_srelsr*   Ú
target_refÚtarget_partnamer?   r<   r>   )rV   rW   r]   Ú
source_uriÚsrelr-   r=   s          r   ry   z%Unmarshaller._unmarshal_relationshipsÔ   st   € ð
 !+× 5Ñ 5Ó 7ò 	NÑˆJ˜Ø *¨cÒ 1‘W°u¸ZÑ7HˆFØ(,×(8Ò(8�T—_’_¸eÀD×DXÑDXÑ>YˆFØ�O‰O˜DŸL™L¨&°$·(±(¸D×<LÑ<LÕMñ	Nr   N)ro   rp   rq   rr   ÚstaticmethodrS   rx   ry   r   r   r   rR   rR   ·   sA   „ ÙRàñ
"ó ð
"ð ñ
ó ð
ð ñNó ñNr   rR   N) rr   Ú
__future__r   Útypingr   r   r   r   Údocx.opc.constantsr   rB   Údocx.opc.packurir	   r
   Údocx.opc.partr   Údocx.opc.parts.corepropsr   Údocx.opc.pkgreaderr   Údocx.opc.pkgwriterr   Údocx.opc.relr   Údocx.sharedr   Údocx.opc.corepropsr   r   r   r   rR   r   r   r   ú<module>r’      sN   ðÙ >å "ç 4Ó 4å 6ß 1Ý %Ý 7Ý ,Ý ,Ý &Ý $áÝ1Ý"Ý*÷^(ñ ^(÷B%Nò %Nr   