Ë
    \Rðit%  ã                   ó¬   — 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y)zQLow-level, read-only API to a serialized Open Packaging Convention (OPC) package.é    )ÚRELATIONSHIP_TARGET_MODE)Ú	parse_xml)ÚPACKAGE_URIÚPackURI)ÚPhysPkgReader)ÚCaseInsensitiveDictc                   óp   ‡ — 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                 óF   •— t         t        | �  «        || _        || _        y ©N)Úsuperr
   Ú__init__Ú
_pkg_srelsÚ_sparts)ÚselfÚcontent_typesÚ	pkg_srelsÚspartsÚ	__class__s       €úM/var/www/html/Extract/venv/lib/python3.12/site-packages/docx/opc/pkgreader.pyr   zPackageReader.__init__   s   ø€ ÜŒm˜TÑ+Ô-Ø#ˆŒØˆ�ó    c                 óò   — t        | «      }t        j                  |j                  «      }t        j                  |t        «      }t        j                  |||«      }|j                  «        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   se   € ô $ HÓ-ˆÜ'×0Ñ0°×1NÑ1NÓOˆÜ!×,Ñ,¨[¼+ÓFˆ	Ü×5Ñ5°kÀ9ÈmÓ\ˆØ×ÑÔÜ˜]¨I°vÓ>Ð>r   c              #   óŽ   K  — | j                   D ]2  }|j                  |j                  |j                  |j                  f–— Œ4 y­w)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   s<   è ø€ ð —‘ò 	BˆAØ—:‘:˜qŸ~™~¨q¯y©y¸!¿&¹&ÐAÓAñ	Bùs   ‚AAc              #   ó¦   K  — | j                   D ]  }t        |f–— Œ | j                  D ]#  }|j                  D ]  }|j                  |f–— Œ Œ% y­w)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#   s[   è ø€ ð —O‘Oò 	&ˆDÜ Ð%Ó%ð	&à—\‘\ò 	-ˆEØŸ™ò -�Ø—~‘~ tÐ,Ó,ñ-ñ	-ùs   ‚AAc                 óª   — g }t         j                  | |«      }|D ],  \  }}}}||   }	t        ||	|||«      }
|j                  |
«       Œ. t	        |«      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,   sg   € ð
 ˆÜ#×4Ñ4°[À)ÓLˆØ.9ò 	!Ñ*ˆH�d˜G UØ(¨Ñ2ˆLÜ# H¨l¸GÀTÈ5ÓQˆEØ�M‰M˜%Õ ð	!ô �V‹}Ðr   c                 ód   — | j                  |«      }t        j                  |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   s-   € ð ×+Ñ+¨JÓ7ˆÜ'×5Ñ5°j×6HÑ6HÈ(ÓSÐSr   c              #   óL  K  — |€g }|D ]—  }|j                   rŒ|j                  }||v rŒ!|j                  |«       |j                  }t        j                  | |«      }| j                  |«      }||||f–— t        j                  | ||«      }|D ]  \  }}}}||||f–— Œ Œ™ y­w)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ˆDØ×ÒØØ×+Ñ+ˆHØÐ,Ñ,ØØ×$Ñ$ XÔ.Ø—l‘lˆGÜ&×1Ñ1°+¸xÓHˆJØ×'Ñ'¨Ó1ˆDØ˜T 7¨JÐ7Ò7Ü'×8Ñ8¸ÀjÐRcÓdˆKØ2=ò 7Ñ.�˜$ ¨Ø  w°Ð6Ó6ñ7ñ	7ùs   ‚B"B$r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústaticmethodr!   r(   r-   r   r   r/   Ú__classcell__©r   s   @r   r
   r
   
   sk   ø„ ñBôð
 ñ?ó ð?òBò-ð ñ
ó ð
ð ñTó ðTð ò7ó ô7r   r
   c                   óD   ‡ — 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                 óf   •— t         t        | �  «        t        «       | _        t        «       | _        y 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___   sw   € ä˜(¤GÔ,ØIˆDÜ˜4¤$ x£.Ñ0Ó1Ð1Ø�t—‘Ñ&Ø—?‘? 8Ñ,Ð,Ø�<‰<˜4Ÿ>™>Ñ)Ø—>‘> (§,¡,Ñ/Ð/ØIˆÜ�t˜h‘Ó'Ð'r   c                 ó  — t        | «      }t        «       }|j                  D ](  }|j                  |j                  |j
                  «       Œ* |j                  D ](  }|j                  |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   sv   € ô Ð/Ó0ˆ	Ü Ó"ˆØ×$Ñ$ò 	=ˆAØ× Ñ  §¡¨Q¯^©^Õ<ð	=à×#Ñ#ò 	=ˆAØ×Ñ §¡¨Q¯^©^Õ<ð	=àˆr   c                 ó"   — || j                   |<   y)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                   |<   y)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   s1   ø„ ñCô/ò

(ð ñ	ó ð	ò1ö
1r   r   c                   ór   ‡ — 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                 óp   •— t         t        | �  «        || _        || _        || _        || _        || _        y r   )r   r0   r   Ú	_partnameÚ_content_typeÚ_reltypeÚ_blobÚ_srels)r   r#   r$   r%   r&   r*   r   s         €r   r   z_SerializedPart.__init__‰   s4   ø€ ÜŒ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‰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   ‚   sq   ø„ ñôð ñó ðð ñ"ó ð"ð ñó ðð ñó ðð ñó ô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                  | _        y 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__®   sJ   ø€ ÜÔ% tÑ5Ô7ØˆŒØ—K‘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¡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‰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Ó   sW   € ð ×Òð0ð ô ˜S“/Ð!ä�tÐ/Ô0Ü$+×$8Ñ$8¸¿¹ÈÏÉÓ$XˆDÔ!Ø×$Ñ$Ð$r   )rB   rC   rD   rE   r   rp   r<   r%   ru   rw   ry   r=   rG   rH   s   @r   rr   rr   §   s…   ø„ ñô.ð ñ1ó ð1ð ñó ðð ñó ðð
 ñ!ó ð!ð
 ñ ó ð ð ñ%ó ô%r   rr   c                   ó8   ‡ — 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                 ó8   •— t         t        | �  «        g | _        y r   )r   r6   r   rg   rM   s    €r   r   z!_SerializedRelationships.__init__ê   s   ø€ ÜÔ&¨Ñ6Ô8Øˆ�r   c                 ó6   — | j                   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                  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ò   sR   € ô )Ó*ˆØÐ$Ü  Ó/ˆHØ#×4Ñ4ò O�Ø—‘×#Ñ#Ô$;¸GÀWÓ$MÕNðOàˆr   )	rB   rC   rD   rE   r   rŒ   rF   r7   rG   rH   s   @r   r6   r6   æ   s&   ø„ ñ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—      sO   ðÙ Wå >Ý #ß 1Ý +Ý /÷I7ñ I7÷X)1ñ )1÷X"ñ "÷J<%ñ <%÷~ò r   