HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/docx/opc/__pycache__/package.cpython-310.pyc
o

$we��@s�dZddlmZddlmZmZddlmZddl	m
Z
ddlmZddl
mZddlmZdd	lmZGd
d�d�ZGdd
�d
�ZdS)z8Objects that implement reading and writing OPC packages.�)�RELATIONSHIP_TYPE)�PACKAGE_URI�PackURI)�PartFactory)�CorePropertiesPart)�
PackageReader)�
PackageWriter)�
Relationships)�lazypropertycs�eZdZdZ�fdd�Zdd�Zedd��Zdd	�Zd
d�Z	d!d
d�Z
edd��Zdd�Ze
dd��Zdd�Zedd��Zdd�Zedd��Zdd�Zedd ��Z�ZS)"�
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.
    cstt|���dS�N)�superr�__init__��self��	__class__��I/home/arjun/projects/env/lib/python3.10/site-packages/docx/opc/package.pyrszOpcPackage.__init__cCsdS)z�Entry point for any post-unmarshaling processing.

        May be overridden by subclasses without forwarding call to super.
        Nrrrrr�after_unmarshalszOpcPackage.after_unmarshalcCs|jjS)zl|CoreProperties| object providing read/write access to the Dublin Core
        properties for this document.)�_core_properties_part�core_propertiesrrrrr szOpcPackage.core_propertiesc#s(�d�fdd�	��|�D]}|VqdS)z�Generate exactly one reference to each relationship in the package by
        performing a depth-first traversal of the rels graph.Nc3sh�|durgn|}|j��D]#}|V|jrq|j}||vrq|�|�|}�||�D]}|Vq+qdSr��rels�values�is_external�target_part�append��source�visited�rel�part�
new_source��	walk_relsrrr%*s�
��z'OpcPackage.iter_rels.<locals>.walk_relsrr)rr!rr$r�	iter_rels&s
��zOpcPackage.iter_relsc#s*�gf�fdd�	��|�D]}|Vq
dS)z�Generate exactly one reference to each of the parts in the package by
        performing a depth-first traversal of the rels graph.c3sX�|j��D]#}|jrq|j}||vrq|�|�|V|}�||�D]}|Vq#qdSrrr��
walk_partsrrr(?s�
��z)OpcPackage.iter_parts.<locals>.walk_partsNr)rr"rr'r�
iter_parts;s
�
�zOpcPackage.iter_partsFcCs|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�rIdrrrr�load_relOszOpcPackage.load_relcCs|�tj�S)aReturn 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_DOCUMENTrrrr�main_document_partYszOpcPackage.main_document_partcCsJdd�|��D�}tdt|�d�D]}||}||vr"t|�SqdS)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"
        cSsh|]}|j�qSr)�partname)�.0r"rrr�	<setcomp>ksz+OpcPackage.next_partname.<locals>.<setcomp>��N)r)�range�lenr)r�template�	partnames�n�candidate_partnamerrr�
next_partnamecs��zOpcPackage.next_partnamecCs"t�|�}|�}t�||t�|S)zGReturn an |OpcPackage| instance loaded with the contents of `pkg_file`.)r�	from_file�Unmarshaller�	unmarshalr)�cls�pkg_file�
pkg_reader�packagerrr�openqs
zOpcPackage.opencCs|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)rr+rrrr/yszOpcPackage.part_related_bycCst|���S)zJReturn a list containing a reference to each of the parts in this package.)�listr)rrrr�parts�szOpcPackage.partscCs|j�||�}|jS)z�Return rId key of relationship to `part`, from the existing relationship if
        there is one, otherwise a newly created one.)r�
get_or_addr-)rr"r+r!rrr�	relate_to�szOpcPackage.relate_tocCs
ttj�S)ztReturn a reference to the |Relationships| instance holding the collection of
        relationships for this package.)r	r�baseURIrrrrr�s
zOpcPackage.relscCs*|jD]}|��qt�||j|j�dS)zvSave this package to `pkg_file`, where `file` can be either a path to a file
        (a string) or a file-like object.N)rI�before_marshalr�writer)rrCr"rrr�save�s

zOpcPackage.savecCs>z|�tj�WStyt�|�}|�|tj�|YSw)z�|CorePropertiesPart| object related to this package.

        Creates a default core properties part if one is not present (not common).
        )r/r0�CORE_PROPERTIES�KeyErrorr�defaultrK)r�core_properties_partrrrr�s
�z OpcPackage._core_properties_part)F)�__name__�
__module__�__qualname__�__doc__rr�propertyrr&r)r.r2r>�classmethodrFr/rIrKr
rrOr�
__classcell__rrrrr
s.	



	


rc@s4eZdZdZedd��Zedd��Zedd��ZdS)	r@zHHosts static methods for unmarshalling a package from a |PackageReader|.cCs>t�|||�}t�|||�|��D]}|��q|��dS)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)r@�_unmarshal_parts�_unmarshal_relationshipsrr)rDrE�part_factoryrIr"rrrrA�s

zUnmarshaller.unmarshalcCs2i}|��D]\}}}}||||||�||<q|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)rDrEr]rIr3�content_typer+�blobrrrr[�s

�zUnmarshaller._unmarshal_partscCsV|��D]$\}}|dkr|n||}|jr|jn||j}|�|j||j|j�qdS)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-)rDrErI�
source_uri�srelrr,rrrr\�s��z%Unmarshaller._unmarshal_relationshipsN)rTrUrVrW�staticmethodrAr[r\rrrrr@�s

r@N)rW�docx.opc.constantsrr0�docx.opc.packurirr�
docx.opc.partr�docx.opc.parts.corepropsr�docx.opc.pkgreaderr�docx.opc.pkgwriterr�docx.opc.relr	�docx.opc.sharedr
rr@rrrr�<module>s