Ë
    \Rði"  ã                  óì   — 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 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)ÚSelf)ÚCoreProperties)ÚPart)Ú_Relationshipc                  ó¸   — e Zd Z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y)Ú
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                 ó   — y)z…Entry point for any post-unmarshaling processing.

        May be overridden by subclasses without forwarding call to super.
        N© ©Úselfs    úK/var/www/html/Extract/venv/lib/python3.12/site-packages/docx/opc/package.pyÚafter_unmarshalzOpcPackage.after_unmarshal   s   € ð 	ó    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©N©ÚrelsÚvaluesÚis_externalÚtarget_partÚappend)ÚsourceÚvisitedÚrelÚpartÚ
new_sourceÚ	walk_relss        €r   r/   z'OpcPackage.iter_rels.<locals>.walk_rels2   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,   r/   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,   r-   r.   Ú
walk_partss        €r   r5   z)OpcPackage.iter_parts.<locals>.walk_partsI   sq   øè ø€ Ø—{‘{×)Ñ)Ó+ò 
�Ø—?’?ØØ—‘�Ø˜7‘?ØØ—‘˜tÔ$Ø’
Ø!�
Ù& z°7Ó;ò �DØ“Jññ
ùs   ƒA(A+Nr   )r   r-   r5   s     @r   Ú
iter_partszOpcPackage.iter_partsE   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_relY   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_partc   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)r6   ÚpartnameÚrangeÚlenr
   )r   Útemplater-   Ú	partnamesÚnÚcandidate_partnames         r   Únext_partnamezOpcPackage.next_partnamem   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   r9   s     r   r>   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.)Úlistr6   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   r-   r9   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)rZ   Úbefore_marshalr   Úwriter%   )r   rR   r-   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   r>   r?   Ú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N)r0   r   )r0   r1   )r0   zIterator[Part])F)r9   Ústrr:   z
Part | strr;   ri   r'   Úbool)rH   ri   r0   r
   )rR   ústr | IO[bytes]r0   r   )r9   ri   r0   r   )r0   z
list[Part])r-   r   r9   ri   )rR   rk   )r0   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr    r2   r6   r<   rA   rL   ÚclassmethodrU   r>   rZ   r]   r   r%   rc   r   r   r   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)rO   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)rO   Ú_unmarshal_partsÚ_unmarshal_relationshipsr&   r   )rS   rT   Úpart_factoryrZ   r-   s        r   rP   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)rS   rT   rv   rZ   rE   Úcontent_typer9   Úblobs           r   rt   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<   r9   r;   )rS   rT   rZ   Ú
source_uriÚsrelr*   r:   s          r   ru   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)rl   rm   rn   ro   ÚstaticmethodrP   rt   ru   r   r   r   rO   rO   ¶   sA   „ ÙRàñ
"ó ð
"ð ñ
ó ð
ð ñNó ñNr   rO   N)"ro   Ú
__future__r   Útypingr   r   r   r   Údocx.opc.constantsr   r?   Údocx.opc.packurir	   r
   Údocx.opc.partr   Údocx.opc.parts.corepropsr   Údocx.opc.pkgreaderr   Údocx.opc.pkgwriterr   Údocx.opc.relr   Údocx.sharedr   Útyping_extensionsr   Údocx.opc.corepropsr   r   r   r   rO   r   r   r   ú<module>r�      sQ   ðÙ >å "ç 4Ó 4å 6ß 1Ý %Ý 7Ý ,Ý ,Ý &Ý $áÝ&å1Ý"Ý*÷[(ñ [(÷|%Nò %Nr   