§
    £”j"  ã                  óú   — 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!dS )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d0d"„Zed1d$„¦   «         Zd%S )2Ú
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                ó   — dS )z…Entry point for any post-unmarshaling processing.

        May be overridden by subclasses without forwarding call to super.
        N© ©Úselfs    ú_/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/docx/opc/package.pyÚafter_unmarshalzOpcPackage.after_unmarshal   s	   € ð 	ˆó    Úreturnr   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Ð9r   úIterator[_Relationship]c              #  ó@   ‡K  — 	 d	d
ˆfd„Š ‰| ¦  «        D ]}|V — ŒdS )zƒGenerate exactly one reference to each relationship in the package by
        performing a depth-first traversal of the rels graph.NÚsourceúOpcPackage | PartÚvisitedúlist[Part] | Noner   r"   c              3  óÔ   •K  — |€g n|}| j                              ¦   «         D ]D}|V — |j        rŒ|j        }||v rŒ|                     |¦  «         |} ‰||¦  «        D ]}|V — ŒŒEd S ©N©ÚrelsÚvaluesÚis_externalÚtarget_partÚappend)r$   r&   ÚrelÚpartÚ
new_sourceÚ	walk_relss        €r   r3   z'OpcPackage.iter_rels.<locals>.walk_rels2   s¨   øè è € ð $˜O�b�b°ˆGØ”{×)Ò)Ñ+Ô+ð 
ð 
�Ø�	�	�	Ø”?ð ØØ”�Ø˜7�?�?ØØ—’˜tÑ$Ô$Ð$Ø!�
Ø$˜9 Z°Ñ9Ô9ð ð �CØ�I�I�I�Iðð
ð 
r   r)   )r$   r%   r&   r'   r   r"   r   )r   r0   r3   s     @r   Ú	iter_relszOpcPackage.iter_rels.   s_   øè è € ð
 EIð	ð 	ð 	ð 	ð 	ð 	ð 	ð  �9˜T‘?”?ð 	ð 	ˆCØˆIˆIˆIˆIð	ð 	r   úIterator[Part]c              #  ó>   ‡K  — g fˆfd„	Š ‰| ¦  «        D ]}|V — ŒdS )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                              ¦   «         D ]D}|j        rŒ
|j        }||v rŒ|                     |¦  «         |V — |} ‰||¦  «        D ]}|V — ŒŒEd S r)   r*   )r$   r&   r0   r1   r2   Ú
walk_partss        €r   r8   z)OpcPackage.iter_parts.<locals>.walk_partsI   s™   øè è € Ø”{×)Ò)Ñ+Ô+ð 
ð 
�Ø”?ð ØØ”�Ø˜7�?�?ØØ—’˜tÑ$Ô$Ð$Ø�
�
�
Ø!�
Ø&˜J z°7Ñ;Ô;ð ð �DØ�J�J�J�Jðð
ð 
r   Nr   )r   r1   r8   s     @r   Ú
iter_partszOpcPackage.iter_partsE   sZ   øè è € ð (*ð 	ð 	ð 	ð 	ð 	ð 	ð �J˜tÑ$Ô$ð 	ð 	ˆDØˆJˆJˆJˆJð	ð 	r   FÚreltypeÚstrÚtargetú
Part | strÚrIdr-   Úboolc                ó<   — | 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   r:   r<   r>   r-   s        r   Úload_relzOpcPackage.load_relY   s    € ð Œy×)Ò)¨'°6¸3ÀÑLÔLÐLr   c                ó@   — |                       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Ñ7Ô7Ð7r   Útemplater
   c                ó¼   — d„ |                       ¦   «         D ¦   «         }t          dt          |¦  «        dz   ¦  «        D ]}||z  }||vrt          |¦  «        c S ŒdS )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"
        c                ó   — h | ]	}|j         ’Œ
S r   )Úpartname)Ú.0r1   s     r   ú	<setcomp>z+OpcPackage.next_partname.<locals>.<setcomp>u   s   € ÐAÐAÐA t�T”]ÐAÐAÐAr   é   é   N)r9   ÚrangeÚlenr
   )r   rH   Ú	partnamesÚnÚcandidate_partnames        r   Únext_partnamezOpcPackage.next_partnamem   s   € ð BÐA¨t¯ªÑ/@Ô/@ÐAÑAÔAˆ	Ý�q�#˜i™.œ.¨1Ñ,Ñ-Ô-ð 	3ð 	3ˆAØ!)¨A¡ÐØ!¨Ð2Ð2ÝÐ1Ñ2Ô2Ð2Ð2Ð2ð 3ð	3ð 	3r   Úpkg_fileústr | IO[bytes]r   c                ó„   — t          j        |¦  «        } | ¦   «         }t                               ||t          ¦  «         |S )zGReturn an |OpcPackage| instance loaded with the contents of `pkg_file`.)r   Ú	from_fileÚUnmarshallerÚ	unmarshalr   )ÚclsrV   Ú
pkg_readerÚpackages       r   ÚopenzOpcPackage.open{   s<   € õ #Ô,¨XÑ6Ô6ˆ
Ø�#‘%”%ˆÝ×Ò˜z¨7µKÑ@Ô@Ð@Øˆr   r   c                ó6   — | 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   rD   zOpcPackage.part_related_byƒ   s   € ð Œy×*Ò*¨7Ñ3Ô3Ð3r   ú
list[Part]c                óD   — t          |                      ¦   «         ¦  «        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   r1   c                óF   — | 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   r1   r:   r0   s       r   Ú	relate_tozOpcPackage.relate_to�   s"   € ð Œi×"Ò" 7¨DÑ1Ô1ˆØŒ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Ñ1Ô1Ð1r   c                ó‚   — | j         D ]}|                     ¦   «          Œt          j        || j        | j         ¦  «         dS )znSave this package to `pkg_file`.

        `pkg_file` can be either a file-path or a file-like object.
        N)re   Úbefore_marshalr   Úwriter+   )r   rV   r1   s      r   ÚsavezOpcPackage.saveŸ   sI   € ð
 ”Jð 	"ð 	"ˆDØ×ÒÑ!Ô!Ð!Ð!ÝÔ˜H d¤i°´Ñ<Ô<Ð<Ð<Ð<r   r   c                óô   — 	 t          t          |                      t          j        ¦  «        ¦  «        S # t
          $ r9 t          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   rD   rE   ÚCORE_PROPERTIESÚKeyErrorÚdefaultrh   )r   Úcore_properties_parts     r   r    z OpcPackage._core_properties_part¨   sy   € ð	(ÝÕ*¨D×,@Ò,@ÅÔASÑ,TÔ,TÑUÔUÐUøÝð 	(ð 	(ð 	(Ý#5Ô#=¸dÑ#CÔ#CÐ Ø�NŠNÐ/µÔ1CÑDÔDÐDØ'Ð'Ð'Ð'ð	(øøøs   ‚14 ´A A7Á6A7N)r   r   )r   r"   )r   r5   )F)r:   r;   r<   r=   r>   r;   r-   r?   )rH   r;   r   r
   )rV   rW   r   r   )r:   r;   r   r   )r   rb   )r1   r   r:   r;   )rV   rW   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr!   r4   r9   rB   rG   rU   Úclassmethodr_   rD   re   rh   r   r+   rn   r    r   r   r   r   r      sy  € € € € € ðð ðð ð ð ð:ð :ð :ñ „Xð:ð
ð ð ð ð.ð ð ð ð(Mð Mð Mð Mð Mð ð8ð 8ñ „Xð8ð3ð 3ð 3ð 3ð ðð ð ñ „[ðð4ð 4ð 4ð 4ð ð'ð 'ð 'ñ „Xð'ðð ð ð ð ð2ð 2ñ „\ð2ð
=ð =ð =ð =ð ð
(ð 
(ð 
(ñ „Xð
(ð 
(ð 
(r   r   c                  óT   — e Zd ZdZed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         ZdS )rZ   zHHosts static methods for unmarshalling a package from a |PackageReader|.c                óô   — t                                | ||¦  «        }t                                | ||¦  «         |                     ¦   «         D ]}|                     ¦   «          Œ|                     ¦   «          dS )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)rZ   Ú_unmarshal_partsÚ_unmarshal_relationshipsr,   r   )r]   r^   Úpart_factoryre   r1   s        r   r[   zUnmarshaller.unmarshal¹   sw   € õ ×-Ò-¨j¸'À<ÑPÔPˆÝ×-Ò-¨j¸'À5ÑIÔIÐIØ—L’L‘N”Nð 	#ð 	#ˆDØ× Ò Ñ"Ô"Ð"Ð"Ø×ÒÑ!Ô!Ð!Ð!Ð!r   c                óf   — i }|                       ¦   «         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)r]   r^   r~   re   rK   Úcontent_typer:   Úblobs           r   r|   zUnmarshaller._unmarshal_partsÆ   sR   € ð ˆØ5?×5KÒ5KÑ5MÔ5Mð 	[ð 	[Ñ1ˆH�l G¨TØ*˜l¨8°\À7ÈDÐRYÑZÔZˆE�(‰OˆOØˆr   c                óÞ   — |                       ¦   «         D ]W\  }}|dk    r|n||         }|j        r|j        n||j                 }|                     |j        ||j        |j        ¦  «         ŒXdS )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_partnamerB   r:   r>   )r]   r^   re   Ú
source_uriÚsrelr$   r<   s          r   r}   z%Unmarshaller._unmarshal_relationshipsÓ   s‡   € ð
 !+× 5Ò 5Ñ 7Ô 7ð 	Nð 	NÑˆJ˜Ø *¨cÒ 1Ð 1�W�W°u¸ZÔ7HˆFØ(,Ô(8ÐY�T”_�_¸eÀDÔDXÔ>YˆFØ�OŠO˜DœL¨&°$´(¸DÔ<LÑMÔMÐMÐMð	Nð 	Nr   N)rt   ru   rv   rw   Ústaticmethodr[   r|   r}   r   r   r   rZ   rZ   ¶   sn   € € € € € ØRÐRàð
"ð 
"ñ „\ð
"ð ð
ð 
ñ „\ð
ð ðNð Nñ „\ðNð Nð Nr   rZ   N)"rw   Ú
__future__r   Útypingr   r   r   r   Údocx.opc.constantsr   rE   Ú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   rZ   r   r   r   ú<module>r—      s”  ðØ >Ð >à "Ð "Ð "Ð "Ð "Ð "à 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4à 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø %Ð %Ð %Ð %Ð %Ð %Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø &Ð &Ð &Ð &Ð &Ð &Ø $Ð $Ð $Ð $Ð $Ð $àð +Ø&Ð&Ð&Ð&Ð&Ð&à1Ð1Ð1Ð1Ð1Ð1Ø"Ð"Ð"Ð"Ð"Ð"Ø*Ð*Ð*Ð*Ð*Ð*ð[(ð [(ð [(ð [(ð [(ñ [(ô [(ð [(ð|%Nð %Nð %Nð %Nð %Nñ %Nô %Nð %Nð %Nð %Nr   