
    j                        d 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 ddlmZ dd	lmZ  G d
 de          Z G d d          ZdS )z3WordprocessingML Package class and related objects.    )annotations)IO)Image)RELATIONSHIP_TYPE)
OpcPackagePackURI)	ImagePart)lazypropertyc                  >    e Zd ZdZd ZddZedd	            Zd
 ZdS )Packagez6Customizations specific to a WordprocessingML package.c                .    |                                   dS )zCalled 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selfs    V/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/docx/package.pyafter_unmarshalzPackage.after_unmarshal   s    
 	  """""    image_descriptorstr | IO[bytes]returnr
   c                6    | j                             |          S )zReturn |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)r   r   s     r   r   zPackage.get_or_add_image_part   s     556FGGGr   
ImagePartsc                    t                      S )z0|ImageParts| collection object for this package.)r   r   s    r   r   zPackage.image_parts!   s     ||r   c                    |                                  D ]N}|j        r
|j        t          j        k    r |j        | j        v r/| j                            |j                   OdS )zCLoad the image part collection with all the image parts in package.N)	iter_relsis_externalreltypeRTIMAGEtarget_partr   append)r   rels     r   r   zPackage._gather_image_parts&   ss    >>## 	5 	5C {bh&&$"222##CO4444	5 	5r   Nr   r   r   r
   )r   r   )	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r      sp        @@# # #H H H H    \	5 	5 	5 	5 	5r   r   c                  J    e Zd ZdZd Zd Zd Zd Zd ZddZ	d Z
d Zd ZdS )r   zICollection of |ImagePart| objects corresponding to images in the package.c                    g | _         d S N)_image_partsr   s    r   __init__zImageParts.__init__5   s    r   c                6    | j                             |          S r.   )r/   __contains__r   items     r   r2   zImageParts.__contains__8   s     --d333r   c                4    | j                                         S r.   )r/   __iter__r   s    r   r6   zImageParts.__iter__;   s     ))+++r   c                4    | j                                         S r.   )r/   __len__r   s    r   r8   zImageParts.__len__>   s     ((***r   c                :    | j                             |           d S r.   )r/   r$   r3   s     r   r$   zImageParts.appendA   s      &&&&&r   r   r   r   r
   c                    t          j        |          }|                     |j                  }||S |                     |          S )zReturn |ImagePart| object containing image identified by `image_descriptor`.

        The image-part is newly created if a matching one is not present in the
        collection.
        )r   	from_file_get_by_sha1sha1_add_image_part)r   r   imagematching_image_parts       r   r   z ImageParts.get_or_add_image_partD   sJ      011"//
;;*&&##E***r   c                    |                      |j                  }t          j        ||          }|                     |           |S )z_Return an |ImagePart| instance newly created from image and appended to the
        collection.)_next_image_partnameextr
   
from_imager$   )r   r?   partname
image_parts       r   r>   zImageParts._add_image_partP   sC     ,,UY77)%::
Jr   c                8    | j         D ]}|j        |k    r|c S dS )zlReturn the image part in this collection having a SHA1 hash matching `sha1`,
        or |None| if not found.N)r/   r=   )r   r=   rF   s      r   r<   zImageParts._get_by_sha1X   s9     + 	" 	"J$&&!!!! 'tr   c                    fd}d | D             }t          dt          |           dz             D ]}||vr ||          c S  |t          |           dz             S )zThe 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.
        c                ,    t          d| fz            S )Nz/word/media/image%d.%sr   )nrC   s    r   image_partnamez7ImageParts._next_image_partname.<locals>.image_partnameh   s    3q#h>???r   c                &    g | ]}|j         j        S r+   )rE   idx).0rF   s     r   
<listcomp>z3ImageParts._next_image_partname.<locals>.<listcomp>k   s    GGGJ
+/GGGr      )rangelen)r   rC   rK   used_numbersrJ   s    `   r   rB   zImageParts._next_image_partname`   s    	@ 	@ 	@ 	@ 	@ HG$GGGq#d))a-(( 	) 	)A$$%~a((((( %~c$ii!m,,,r   Nr&   )r'   r(   r)   r*   r0   r2   r6   r8   r$   r   r>   r<   rB   r+   r   r   r   r   2   s        SS  4 4 4, , ,+ + +' ' '
+ 
+ 
+ 
+    - - - - -r   r   N)r*   
__future__r   typingr   docx.image.imager   docx.opc.constantsr   r!   docx.opc.packager   docx.opc.packurir	   docx.parts.imager
   docx.sharedr   r   r   r+   r   r   <module>r\      s    9 9 " " " " " "       " " " " " " 6 6 6 6 6 6 ' ' ' ' ' ' $ $ $ $ $ $ & & & & & & $ $ $ $ $ $ 5  5  5  5  5j  5  5  5F=- =- =- =- =- =- =- =- =- =-r   