§
    £”jt%  ã                   óÌ   — d 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  G d„ d¦  «        Z G d	„ d
¦  «        Z G d„ d¦  «        Z G d„ d¦  «        Z G d„ d¦  «        ZdS )zQLow-level, read-only API to a serialized Open Packaging Convention (OPC) package.é    )ÚRELATIONSHIP_TARGET_MODE)Ú	parse_xml)ÚPACKAGE_URIÚPackURI)ÚPhysPkgReader)ÚCaseInsensitiveDictc                   óˆ   ‡ — e Zd ZdZˆ fd„Zed„ ¦   «         Zd„ Zd„ Zed„ ¦   «         Z	ed„ ¦   «         Z
ed
d	„¦   «         Zˆ xZS )ÚPackageReaderz‚Provides access to the contents of a zip-format OPC package via its
    :attr:`serialized_parts` and :attr:`pkg_srels` attributes.c                 ór   •— t          t          | ¦  «                             ¦   «          || _        || _        d S ©N)Úsuperr
   Ú__init__Ú
_pkg_srelsÚ_sparts)ÚselfÚcontent_typesÚ	pkg_srelsÚspartsÚ	__class__s       €úa/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/docx/opc/pkgreader.pyr   zPackageReader.__init__   s1   ø€ Ý�m˜TÑ"Ô"×+Ò+Ñ-Ô-Ð-Ø#ˆŒØˆŒˆˆó    c                 ó   — t          | ¦  «        }t                               |j        ¦  «        }t                               |t          ¦  «        }t                               |||¦  «        }|                     ¦   «          t	          |||¦  «        S )zEReturn a |PackageReader| instance loaded with contents of `pkg_file`.)	r   Ú_ContentTypeMapÚfrom_xmlÚcontent_types_xmlr
   Ú
_srels_forr   Ú_load_serialized_partsÚclose)Úpkg_fileÚphys_readerr   r   r   s        r   Ú	from_filezPackageReader.from_file   sw   € õ $ HÑ-Ô-ˆÝ'×0Ò0°Ô1NÑOÔOˆÝ!×,Ò,¨[½+ÑFÔFˆ	Ý×5Ò5°kÀ9ÈmÑ\Ô\ˆØ×ÒÑÔÐÝ˜]¨I°vÑ>Ô>Ð>r   c              #   óV   K  — | j         D ]}|j        |j        |j        |j        fV — ŒdS )zuGenerate a 4-tuple `(partname, content_type, reltype, blob)` for each of the
        serialized parts in the package.N)r   ÚpartnameÚcontent_typeÚreltypeÚblob)r   Úss     r   Úiter_spartszPackageReader.iter_sparts   sG   è è € ð ”ð 	Bð 	BˆAØ”:˜qœ~¨q¬y¸!¼&ÐAÐAÐAÐAÐAð	Bð 	Br   c              #   ór   K  — | j         D ]}t          |fV — Œ| j        D ]}|j        D ]}|j        |fV — ŒŒdS )z]Generate a 2-tuple `(source_uri, srel)` for each of the relationships in the
        package.N)r   r   r   Úsrelsr#   )r   ÚsrelÚsparts      r   Ú
iter_srelszPackageReader.iter_srels#   st   è è € ð ”Oð 	&ð 	&ˆDÝ Ð%Ð%Ð%Ð%Ð%Ø”\ð 	-ð 	-ˆEØœð -ð -�Ø”~ tÐ,Ð,Ð,Ð,Ð,ð-ð	-ð 	-r   c                 óÎ   — g }t                                | |¦  «        }|D ]7\  }}}}||         }	t          ||	|||¦  «        }
|                     |
¦  «         Œ8t	          |¦  «        S )z°Return a list of |_SerializedPart| instances corresponding to the parts in
        `phys_reader` accessible by walking the relationship graph starting with
        `pkg_srels`.)r
   Ú_walk_phys_partsÚ_SerializedPartÚappendÚtuple)r    r   r   r   Úpart_walkerr#   r&   r%   r*   r$   r,   s              r   r   z$PackageReader._load_serialized_parts,   sv   € ð
 ˆÝ#×4Ò4°[À)ÑLÔLˆØ.9ð 	!ð 	!Ñ*ˆH�d˜G UØ(¨Ô2ˆLÝ# H¨l¸GÀTÈ5ÑQÔQˆEØ�MŠM˜%Ñ Ô Ð Ð Ý�V‰}Œ}Ðr   c                 ól   — |                       |¦  «        }t                               |j        |¦  «        S )zvReturn |_SerializedRelationships| instance populated with relationships for
        source identified by `source_uri`.)Úrels_xml_forÚ_SerializedRelationshipsÚload_from_xmlÚbaseURI)r    Ú
source_uriÚrels_xmls      r   r   zPackageReader._srels_for9   s0   € ð ×+Ò+¨JÑ7Ô7ˆÝ'×5Ò5°jÔ6HÈ(ÑSÔSÐSr   Nc              #   óH  K  — |€g }|D ]˜}|j         rŒ
|j        }||v rŒ|                     |¦  «         |j        }t                               | |¦  «        }|                      |¦  «        }||||fV — t                               | ||¦  «        }|D ]\  }}}}||||fV — ŒŒ™dS )z—Generate a 4-tuple `(partname, blob, reltype, srels)` for each of the parts
        in `phys_reader` by walking the relationship graph rooted at srels.N)Úis_externalÚtarget_partnamer1   r%   r
   r   Úblob_forr/   )	r    r*   Úvisited_partnamesr+   r#   r%   Ú
part_srelsr&   Únext_walkers	            r   r/   zPackageReader._walk_phys_parts@   s÷   è è € ð Ð$Ø "ÐØð 	7ð 	7ˆDØÔð ØØÔ+ˆHØÐ,Ð,Ð,ØØ×$Ò$ XÑ.Ô.Ð.Ø”lˆGÝ&×1Ò1°+¸xÑHÔHˆJØ×'Ò'¨Ñ1Ô1ˆDØ˜T 7¨JÐ7Ð7Ð7Ð7Ý'×8Ò8¸ÀjÐRcÑdÔdˆKØ2=ð 7ð 7Ñ.�˜$ ¨Ø  w°Ð6Ð6Ð6Ð6Ð6ð7ð	7ð 	7r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústaticmethodr!   r(   r-   r   r   r/   Ú__classcell__©r   s   @r   r
   r
   
   sÙ   ø€ € € € € ðBð Bðð ð ð ð ð
 ð?ð ?ñ „\ð?ðBð Bð Bð-ð -ð -ð ð
ð 
ñ „\ð
ð ðTð Tñ „\ðTð ð7ð 7ð 7ñ „\ð7ð 7ð 7ð 7ð 7r   r
   c                   óJ   ‡ — e Zd ZdZˆ fd„Zd„ Zed„ ¦   «         Zd„ Zd„ Z	ˆ xZ
S )r   z�Value type providing dictionary semantics for looking up content type by part
    name, e.g. ``content_type = cti['/ppt/presentation.xml']``.c                 ó¢   •— t          t          | ¦  «                             ¦   «          t          ¦   «         | _        t          ¦   «         | _        d S r   )r   r   r   r   Ú
_overridesÚ	_defaults©r   r   s    €r   r   z_ContentTypeMap.__init__Z   s=   ø€ Ý�o˜tÑ$Ô$×-Ò-Ñ/Ô/Ð/Ý-Ñ/Ô/ˆŒÝ,Ñ.Ô.ˆŒˆˆr   c                 ó  — t          |t          ¦  «        s!d}t          |t          |¦  «        z  ¦  «        ‚|| j        v r| j        |         S |j        | j        v r| j        |j                 S d}t          ||z  ¦  «        ‚)z6Return content type for part identified by `partname`.z4_ContentTypeMap key must be <type 'PackURI'>, got %sz8no content type for partname '%s' in [Content_Types].xml)Ú
isinstancer   ÚKeyErrorÚtyperK   ÚextrL   )r   r#   Útmpls      r   Ú__getitem__z_ContentTypeMap.__getitem___   s�   € å˜(¥GÑ,Ô,ð 	2ØIˆDÝ˜4¥$ x¡.¤.Ñ0Ñ1Ô1Ð1Ø�t”Ð&Ð&Ø”? 8Ô,Ð,ØŒ<˜4œ>Ð)Ð)Ø”> (¤,Ô/Ð/ØIˆÝ�t˜h‘Ñ'Ô'Ð'r   c                 óè   — t          | ¦  «        }t          ¦   «         }|j        D ]"}|                     |j        |j        ¦  «         Œ#|j        D ]"}|                     |j        |j        ¦  «         Œ#|S )zcReturn a new |_ContentTypeMap| instance populated with the contents of
        `content_types_xml`.)	r   r   Ú	overridesÚ_add_overrider#   r$   ÚdefaultsÚ_add_defaultÚ	extension)r   Ú	types_elmÚct_mapÚoÚds        r   r   z_ContentTypeMap.from_xmlk   s€   € õ Ð/Ñ0Ô0ˆ	Ý Ñ"Ô"ˆØÔ$ð 	=ð 	=ˆAØ× Ò  ¤¨Q¬^Ñ<Ô<Ð<Ð<ØÔ#ð 	=ð 	=ˆAØ×Ò ¤¨Q¬^Ñ<Ô<Ð<Ð<Øˆr   c                 ó   — || j         |<   dS )z^Add the default mapping of `extension` to `content_type` to this content type
        mapping.N)rL   )r   rZ   r$   s      r   rY   z_ContentTypeMap._add_defaultw   s   € ð %1ˆŒ�yÑ!Ð!Ð!r   c                 ó   — || j         |<   dS )z]Add the default mapping of `partname` to `content_type` to this content type
        mapping.N)rK   )r   r#   r$   s      r   rW   z_ContentTypeMap._add_override|   s   € ð %1ˆŒ˜Ñ!Ð!Ð!r   )rB   rC   rD   rE   r   rT   rF   r   rY   rW   rG   rH   s   @r   r   r   V   sŒ   ø€ € € € € ðCð Cð/ð /ð /ð /ð /ð

(ð 
(ð 
(ð ð	ð 	ñ „\ð	ð1ð 1ð 1ð
1ð 1ð 1ð 1ð 1ð 1ð 1r   r   c                   ó�   ‡ — e Zd ZdZˆ fd„Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed„ ¦   «         Z
ˆ xZS )r0   z“Value object for an OPC package part.

    Provides access to the partname, content type, blob, and serialized relationships
    for the part.
    c                 óœ   •— t          t          | ¦  «                             ¦   «          || _        || _        || _        || _        || _        d S r   )r   r0   r   Ú	_partnameÚ_content_typeÚ_reltypeÚ_blobÚ_srels)r   r#   r$   r%   r&   r*   r   s         €r   r   z_SerializedPart.__init__‰   sG   ø€ Ý�o˜tÑ$Ô$×-Ò-Ñ/Ô/Ð/Ø!ˆŒØ)ˆÔØˆŒØˆŒ
ØˆŒˆˆr   c                 ó   — | j         S r   )rc   ©r   s    r   r#   z_SerializedPart.partname‘   s
   € àŒ~Ðr   c                 ó   — | j         S r   )rd   ri   s    r   r$   z_SerializedPart.content_type•   s   € àÔ!Ð!r   c                 ó   — | j         S r   )rf   ri   s    r   r&   z_SerializedPart.blob™   s
   € àŒzÐr   c                 ó   — | j         S )z-The referring relationship type of this part.©re   ri   s    r   r%   z_SerializedPart.reltype�   ó   € ð Œ}Ðr   c                 ó   — | j         S r   )rg   ri   s    r   r*   z_SerializedPart.srels¢   s
   € àŒ{Ðr   )rB   rC   rD   rE   r   Úpropertyr#   r$   r&   r%   r*   rG   rH   s   @r   r0   r0   ‚   sÉ   ø€ € € € € ðð ðð ð ð ð ð ðð ñ „Xðð ð"ð "ñ „Xð"ð ðð ñ „Xðð ðð ñ „Xðð ðð ñ „Xðð ð ð ð r   r0   c                   ó¦   ‡ — e Zd ZdZˆ fd„Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed„ ¦   «         Z
ed„ ¦   «         Zˆ xZS )	Ú_SerializedRelationshipzÝValue object representing a serialized relationship in an OPC package.

    Serialized, in this case, means any target part is referred to via its partname
    rather than a direct link to an in-memory |Part| object.
    c                 óÄ   •— t          t          | ¦  «                             ¦   «          || _        |j        | _        |j        | _        |j        | _	        |j
        | _        d S r   )r   rr   r   Ú_baseURIÚrIdÚ_rIdr%   re   Útarget_modeÚ_target_modeÚ
target_refÚ_target_ref)r   r8   Úrel_elmr   s      €r   r   z _SerializedRelationship.__init__®   sU   ø€ ÝÕ% tÑ,Ô,×5Ò5Ñ7Ô7Ð7ØˆŒØ”KˆŒ	ØœˆŒØ#Ô/ˆÔØ"Ô-ˆÔÐÐr   c                 ó,   — | j         t          j        k    S )z'True if target_mode is ``RTM.EXTERNAL``)rx   ÚRTMÚEXTERNALri   s    r   r<   z#_SerializedRelationship.is_external¶   s   € ð Ô ¥C¤LÒ0Ð0r   c                 ó   — | j         S )z.Relationship type, like ``RT.OFFICE_DOCUMENT``rm   ri   s    r   r%   z_SerializedRelationship.reltype»   rn   r   c                 ó   — | j         S )zmRelationship id, like 'rId9', corresponds to the ``Id`` attribute on the
        ``CT_Relationship`` element.)rv   ri   s    r   ru   z_SerializedRelationship.rIdÀ   s   € ð ŒyÐr   c                 ó   — | j         S )zwString in ``TargetMode`` attribute of ``CT_Relationship`` element, one of
        ``RTM.INTERNAL`` or ``RTM.EXTERNAL``.)rx   ri   s    r   rw   z#_SerializedRelationship.target_modeÆ   s   € ð Ô Ð r   c                 ó   — | j         S )zÂString in ``Target`` attribute of ``CT_Relationship`` element, a relative
        part reference for internal target mode or an arbitrary URI, e.g. an HTTP URL,
        for external target mode.)rz   ri   s    r   ry   z"_SerializedRelationship.target_refÌ   s   € ð
 ÔÐr   c                 ó¨   — | j         rd}t          |¦  «        ‚t          | d¦  «        s$t          j        | j        | j        ¦  «        | _        | j        S )zÙ|PackURI| instance containing partname targeted by this relationship.

        Raises ``ValueError`` on reference if target_mode is ``'External'``. Use
        :attr:`target_mode` to check before referencing.
        zUtarget_partname attribute on Relationship is undefined where TargetMode == "External"Ú_target_partname)r<   Ú
ValueErrorÚhasattrr   Úfrom_rel_refrt   ry   r„   )r   Úmsgs     r   r=   z'_SerializedRelationship.target_partnameÓ   s]   € ð Ôð 	"ð0ð õ ˜S‘/”/Ð!å�tÐ/Ñ0Ô0ð 	YÝ$+Ô$8¸¼ÈÌÑ$XÔ$XˆDÔ!ØÔ$Ð$r   )rB   rC   rD   rE   r   rp   r<   r%   ru   rw   ry   r=   rG   rH   s   @r   rr   rr   §   sä   ø€ € € € € ðð ð.ð .ð .ð .ð .ð ð1ð 1ñ „Xð1ð ðð ñ „Xðð ðð ñ „Xðð
 ð!ð !ñ „Xð!ð
 ð ð  ñ „Xð ð ð%ð %ñ „Xð%ð %ð %ð %ð %r   rr   c                   ó>   ‡ — e Zd ZdZˆ fd„Zd„ Zed„ ¦   «         Zˆ xZS )r6   z€Read-only sequence of |_SerializedRelationship| instances corresponding to the
    relationships item XML passed to constructor.c                 ód   •— t          t          | ¦  «                             ¦   «          g | _        d S r   )r   r6   r   rg   rM   s    €r   r   z!_SerializedRelationships.__init__ê   s+   ø€ ÝÕ&¨Ñ-Ô-×6Ò6Ñ8Ô8Ð8ØˆŒˆˆr   c                 ó4   — | j                              ¦   «         S )z*Support iteration, e.g. 'for x in srels:'.)rg   Ú__iter__ri   s    r   rŒ   z!_SerializedRelationships.__iter__î   s   € àŒ{×#Ò#Ñ%Ô%Ð%r   c                 ó¨   — t          ¦   «         }|�At          |¦  «        }|j        D ]*}|j                             t          | |¦  «        ¦  «         Œ+|S )zºReturn |_SerializedRelationships| instance loaded with the relationships
        contained in `rels_item_xml`.

        Returns an empty collection if `rels_item_xml` is |None|.
        )r6   r   ÚRelationship_lstrg   r1   rr   )r8   Úrels_item_xmlr*   Úrels_elmr{   s        r   r7   z&_SerializedRelationships.load_from_xmlò   s_   € õ )Ñ*Ô*ˆØÐ$Ý  Ñ/Ô/ˆHØ#Ô4ð Oð O�Ø”×#Ò#Õ$;¸GÀWÑ$MÔ$MÑNÔNÐNÐNØˆr   )	rB   rC   rD   rE   r   rŒ   rF   r7   rG   rH   s   @r   r6   r6   æ   sl   ø€ € € € € ð5ð 5ðð ð ð ð ð&ð &ð &ð ðð ñ „\ðð ð ð ð r   r6   N)rE   Údocx.opc.constantsr   r}   Údocx.opc.oxmlr   Údocx.opc.packurir   r   Údocx.opc.phys_pkgr   Údocx.opc.sharedr   r
   r   r0   rr   r6   © r   r   ú<module>r—      sI  ðØ WÐ Wà >Ð >Ð >Ð >Ð >Ð >Ø #Ð #Ð #Ð #Ð #Ð #Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø +Ð +Ð +Ð +Ð +Ð +Ø /Ð /Ð /Ð /Ð /Ð /ðI7ð I7ð I7ð I7ð I7ñ I7ô I7ð I7ðX)1ð )1ð )1ð )1ð )1ñ )1ô )1ð )1ðX"ð "ð "ð "ð "ñ "ô "ð "ðJ<%ð <%ð <%ð <%ð <%ñ <%ô <%ð <%ð~ð ð ð ð ñ ô ð ð ð r   