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/__pycache__/package.cpython-310.pyc
o

$we�@s�dZddlmZddlmZddlmZddlmZ	ddl
mZddlm
Z
ddlmZdd	lmZGd
d�de�ZGdd
�d
�ZdS)z3WordprocessingML Package class and related objects.�)�annotations)�IO)�Image)�RELATIONSHIP_TYPE)�
OpcPackage��PackURI)�	ImagePart)�lazypropertyc@s8eZdZdZdd�Zddd	�Zeddd��Zd
d�ZdS)�Packagez6Customizations specific to a WordprocessingML package.cCs|��dS)z�Called by loading code after all parts and relationships have been loaded.

        This method affords the opportunity for any required post-processing.
        N)�_gather_image_parts��self�r�E/home/arjun/projects/env/lib/python3.10/site-packages/docx/package.py�after_unmarshalszPackage.after_unmarshal�image_descriptor�str | IO[bytes]�returnr	cC�|j�|�S)z�Return |ImagePart| containing image specified by `image_descriptor`.

        The image-part is newly created if a matching one is not already present in the
        collection.
        )�image_parts�get_or_add_image_part)rrrrrrszPackage.get_or_add_image_part�
ImagePartscCst�S)z0|ImageParts| collection object for this package.)rr
rrrr!szPackage.image_partscCsD|��D]}|jr
q|jtjkrq|j|jvrq|j�|j�qdS)zCLoad the image part collection with all the image parts in package.N)�	iter_rels�is_external�reltype�RT�IMAGE�target_partr�append)r�relrrrr&s�zPackage._gather_image_partsN�rrrr	)rr)	�__name__�
__module__�__qualname__�__doc__rrr
rrrrrrrs
rc@sZeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zddd�Z	dd�Z
dd�Zdd�ZdS)rzICollection of |ImagePart| objects corresponding to images in the package.cCs
g|_dS�N)�_image_partsr
rrr�__init__5�
zImageParts.__init__cCrr&)r'�__contains__�r�itemrrrr*8szImageParts.__contains__cC�
|j��Sr&)r'�__iter__r
rrrr.;r)zImageParts.__iter__cCr-r&)r'�__len__r
rrrr/>r)zImageParts.__len__cCs|j�|�dSr&)r'rr+rrrrA�zImageParts.appendrrrr	cCs,t�|�}|�|j�}|dur|S|�|�S)z�Return |ImagePart| object containing image identified by `image_descriptor`.

        The image-part is newly created if a matching one is not present in the
        collection.
        N)r�	from_file�_get_by_sha1�sha1�_add_image_part)rr�image�matching_image_partrrrrDs


z ImageParts.get_or_add_image_partcCs&|�|j�}t�||�}|�|�|S)z_Return an |ImagePart| instance newly created from image and appended to the
        collection.)�_next_image_partname�extr	�
from_imager)rr5�partname�
image_partrrrr4Ps
zImageParts._add_image_partcCs"|jD]}|j|kr|SqdS)zlReturn the image part in this collection having a SHA1 hash matching `sha1`,
        or |None| if not found.N)r'r3)rr3r;rrrr2Xs


�zImageParts._get_by_sha1csV�fdd�}dd�|D�}tdt|�d�D]}||vr"||�Sq|t|�d�S)z�The next available image partname, starting from ``/word/media/image1.{ext}``
        where unused numbers are reused.

        The partname is unique by number, without regard to the extension. `ext` does
        not include the leading period.
        cstd|�f�S)Nz/word/media/image%d.%sr)�n�r8rr�image_partnamehr0z7ImageParts._next_image_partname.<locals>.image_partnamecSsg|]}|jj�qSr)r:�idx)�.0r;rrr�
<listcomp>ksz3ImageParts._next_image_partname.<locals>.<listcomp>�)�range�len)rr8r>�used_numbersr<rr=rr7`s�zImageParts._next_image_partnameNr!)
r"r#r$r%r(r*r.r/rrr4r2r7rrrrr2s
rN)r%�
__future__r�typingr�docx.image.imager�docx.opc.constantsrr�docx.opc.packager�docx.opc.packurir�docx.parts.imager	�docx.sharedr
rrrrrr�<module>s#