
    ,h                        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y)z3WordprocessingML Package class and related objects.    )annotations)IOcast)Image)RELATIONSHIP_TYPE)
OpcPackagePackURI)	ImagePart)lazypropertyc                  6    e Zd ZdZd ZddZedd       Zd Zy)	Packagez6Customizations specific to a WordprocessingML package.c                $    | j                          y)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    N/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/package.pyafter_unmarshalzPackage.after_unmarshal   s    
 	  "    c                8    | j                   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   image_descriptors     r   r   zPackage.get_or_add_image_part   s     556FGGr   c                    t               S )z0|ImageParts| collection object for this package.)
ImagePartsr   s    r   r   zPackage.image_parts!   s     |r   c                   | j                         D ]u  }|j                  r|j                  t        j                  k7  r.|j
                  | j                  v rG| j                  j                  t        d|j
                               w y)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&   sk    >># 	HC{{bhh&$"2"22##Dcoo$FG	Hr   Nr   zstr | IO[bytes]returnr   )r&   r   )	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r      s*    @#H  	Hr   r   c                  R    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y)r   zICollection of |ImagePart| objects corresponding to images in the package.c                    g | _         y N)_image_partsr   s    r   __init__zImageParts.__init__5   s
    -/r   c                8    | j                   j                  |      S r.   )r/   __contains__r   items     r   r2   zImageParts.__contains__8   s      --d33r   c                6    | j                   j                         S r.   )r/   __iter__r   s    r   r6   zImageParts.__iter__;   s      ))++r   c                6    | j                   j                         S r.   )r/   __len__r   s    r   r8   zImageParts.__len__>   s      ((**r   c                :    | j                   j                  |       y r.   )r/   r#   r3   s     r   r#   zImageParts.appendA   s      &r   c                    t        j                  |      }| j                  |j                        }||S | j	                  |      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   sE      01"//

;*&&##E**r   c                    | j                  |j                        }t        j                  ||      }| j	                  |       |S )zVReturn |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   s:    ,,UYY7))%:
Jr   c                L    | j                   D ]  }|j                  |k(  s|c S  y)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_sha1W   s0     ++ 	"J$&!!	" r   c                    dfd}| D cg c]  }|j                   j                   }}t        dt        |       dz         D ]  }||vs ||      c S   |t        |       dz         S c c}w )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_partnameg   s    3q#h>??r      )rJ   intr&   r
   )rE   idxrangelen)r   rC   rK   rF   used_numbersrJ   s    `    r   rB   zImageParts._next_image_partname_   sx    	@ CGGJ
++//GGq#d)a-( 	)A$%a((	) c$i!m,,	 Hs   A*N)r4   object)r4   r   r%   )r?   r   )r=   strr&   zImagePart | None)rC   rS   r&   r
   )r'   r(   r)   r*   r0   r2   r6   r8   r#   r   r>   r<   rB   r+   r   r   r   r   2   s2    S0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>r\      s9    9 "  " 6 ' $ & $ Hj  HF<- <-r   