
    hi                        d Z ddlmZ ddlmZ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cast)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    d/var/www/development/aibuddy-work/election-extract/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 ]\}|j        r
|j        t          j        k    r |j        | j        v r/| j                            t          d|j                             ]dS )zCLoad the image part collection with all the image parts in package.r   N)		iter_relsis_externalreltypeRTIMAGEtarget_partr   appendr   )r   rels     r   r   zPackage._gather_image_parts&   s    >>## 	H 	HC {bh&&$"222##Dco$F$FGGGG	H 	Hr   Nr   r   r   r   )r   r   )	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r      su        @@# # #H H H H    \	H 	H 	H 	H 	Hr   r   c                  T    e Zd ZdZd ZddZd Zd Zdd	ZddZ	ddZ
ddZd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   itemobjectc                6    | j                             |          S r/   )r0   __contains__r   r2   s     r   r5   zImageParts.__contains__8   s     --d333r   c                4    | j                                         S r/   )r0   __iter__r   s    r   r8   zImageParts.__iter__;   s     ))+++r   c                4    | j                                         S r/   )r0   __len__r   s    r   r:   zImageParts.__len__>   s     ((***r   r   c                :    | j                             |           d S r/   )r0   r%   r6   s     r   r%   zImageParts.appendA   s      &&&&&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   rA   r   c                    |                      |j                  }t          j        ||          }|                     |           |S )zVReturn |ImagePart| instance newly created from `image` and appended to the collection.)_next_image_partnameextr   
from_imager%   )r   rA   partname
image_parts       r   r@   zImageParts._add_image_partP   sA    ,,UY77)%::
Jr   r?   strImagePart | Nonec                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)r0   r?   )r   r?   rH   s      r   r>   zImageParts._get_by_sha1W   s9     + 	" 	"J$&&!!!! 'tr   rE   r
   c                    d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.
        nintr   r
   c                ,    t          d| fz            S )Nz/word/media/image%d.%sr	   )rM   rE   s    r   image_partnamez7ImageParts._next_image_partname.<locals>.image_partnameg   s    3q#h>???r   c                &    g | ]}|j         j        S r,   )rG   idx).0rH   s     r   
<listcomp>z3ImageParts._next_image_partname.<locals>.<listcomp>j   s    GGGJ
+/GGGr      )rM   rN   r   r
   )rangelen)r   rE   rP   used_numbersrM   s    `   r   rD   zImageParts._next_image_partname_   s    	@ 	@ 	@ 	@ 	@ 	@ HG$GGGq#d))a-(( 	) 	)A$$%~a((((( %~c$ii!m,,,r   N)r2   r3   )r2   r   r'   )rA   r   )r?   rI   r   rJ   )rE   rI   r   r
   )r(   r)   r*   r+   r1   r5   r8   r:   r%   r   r@   r>   rD   r,   r   r   r   r   2   s        SS0 0 04 4 4 4, , ,+ + +' ' ' '
+ 
+ 
+ 
+      - - - - - -r   r   N)r+   
__future__r   typingr   r   docx.image.imager   docx.opc.constantsr   r"   docx.opc.packager   docx.opc.packurir
   docx.parts.imager   docx.sharedr   r   r   r,   r   r   <module>ra      s   9 9 " " " " " "         " " " " " " 6 6 6 6 6 6 ' ' ' ' ' ' $ $ $ $ $ $ & & & & & & $ $ $ $ $ $ H  H  H  H  Hj  H  H  HF<- <- <- <- <- <- <- <- <- <-r   