
    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mZ dd	lmZ dd
lmZ  G d de
          Z G d de          Z G d de          ZdS )zOverall .pptx package.    )annotations)IOIterator)RELATIONSHIP_TYPE)
OpcPackagePackURI)CorePropertiesPart)Image	ImagePart)	MediaPart)lazypropertyc                      e Zd ZdZedd            ZddZd ZddZd Z	e
d             Zed             Zed             ZdS )PackagezAn overall .pptx package.returnr
   c                    	 |                      t          j                  S # t          $ r9 t	          j        |           }|                     |t          j                   |cY S w xY w)zInstance of |CoreProperties| holding read/write Dublin Core doc properties.

        Creates a default core properties part if one is not present (not common).
        )part_related_byRTCORE_PROPERTIESKeyErrorr
   default	relate_to)self
core_propss     d/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/pptx/package.pycore_propertieszPackage.core_properties   sl    	''(:;;; 	 	 	+3D99JNN:r'9:::	s   ! A A$#A$
image_filestr | IO[bytes]c                6    | j                             |          S )z
        Return an |ImagePart| object containing the image in *image_file*. If
        the image part already exists in this package, it is reused,
        otherwise a new one is created.
        )_image_partsget_or_add_image_part)r   r   s     r   r!   zPackage.get_or_add_image_part    s      66zBBB    c                6    | j                             |          S )zReturn a |MediaPart| object containing the media in *media*.

        If a media part for this media bytestream ("file") is already present
        in this package, it is reused, otherwise a new one is created.
        )_media_partsget_or_add_media_part)r   medias     r   r%   zPackage.get_or_add_media_part(   s      66u===r"   extstrr	   c                J      fd} |            }t          d||fz            S )zReturn a |PackURI| instance representing the next available image partname.

        Partname uses the next available sequence number. *ext* is used as the extention on the
        returned partname.
        c                     t          d                                 D                       } t          |           D ]\  }}|dz   }||k     r|c S t          |           dz   S )Nc                r    g | ]4}|j                             d           r|j         j        (|j         j        5S )z/ppt/media/imagepartname
startswithidx.0parts     r   
<listcomp>zRPackage.next_image_partname.<locals>.first_available_image_idx.<locals>.<listcomp>9   sO       001CDD	
 !M-9	 M% :99r"      sorted
iter_parts	enumeratelen)
image_idxsi	image_idxr/   r   s       r   first_available_image_idxz>Package.next_image_partname.<locals>.first_available_image_idx7   s      $ 1 1  	 	J !** 5 5  9!e??JJJ #z??Q&&r"   z/ppt/media/image%d.%sr   )r   r'   r=   r/   s   `   r   next_image_partnamezPackage.next_image_partname0   sD    	' 	' 	' 	' 	'" (')).#s;<<<r"   c                J      fd} |            }t          d||fz            S )zReturn |PackURI| instance for next available media partname.

        Partname is first available, starting at sequence number 1. Empty
        sequence numbers are reused. *ext* is used as the extension on the
        returned partname.
        c                     t          d                                 D                       } t          |           D ]\  }}|dz   }||k     r|c S t          |           dz   S )Nc                Z    g | ](}|j                             d           |j         j        )S )z/ppt/media/mediar,   r0   s     r   r3   zRPackage.next_media_partname.<locals>.first_available_media_idx.<locals>.<listcomp>U   sD       }//0BCCM%  r"   r4   r5   )
media_idxsr;   	media_idxr/   r   s       r   first_available_media_idxz>Package.next_media_partname.<locals>.first_available_media_idxS   s      $ 1 1   J !** 5 5  9!e??JJJ #z??Q&&r"   z/ppt/media/media%d.%sr   )r   r'   rD   r/   s   `   r   next_media_partnamezPackage.next_media_partnameK   sD    	' 	' 	' 	' 	' (')).#s;<<<r"   c                    | j         S )zU
        Reference to the |Presentation| instance contained in this package.
        )main_document_partr   s    r   presentation_partzPackage.presentation_partd   s    
 &&r"   c                     t          |           S )zc
        |_ImageParts| object providing access to the image parts in this
        package.
        )_ImagePartsrH   s    r   r    zPackage._image_partsk   s     4   r"   c                     t          |           S )zReturn |_MediaParts| object for this package.

        The media parts object provides access to all the media parts in this
        package.
        )_MediaPartsrH   s    r   r$   zPackage._media_partss   s     4   r"   N)r   r
   )r   r   )r'   r(   r   r	   )__name__
__module____qualname____doc__r   r   r!   r%   r>   rE   propertyrI   r    r$    r"   r   r   r      s        ##
 
 
 \
C C C C> > >= = = =6= = =2 ' ' X' ! ! \! ! ! \! ! !r"   r   c                  :     e Zd ZdZ fdZddZdd	ZddZ xZS )rK   z0Provides access to the image parts in a package.c                d    t          t          |                                            || _        d S N)superrK   __init___packager   package	__class__s     r   rX   z_ImageParts.__init__   *    k4  ))+++r"   r   Iterator[ImagePart]c              #     K   g }| j                                         D ]E}|j        r
|j        t          j        k    r |j        }||v r,|                    |           |V  FdS )z?Generate a reference to each |ImagePart| object in the package.N)rY   	iter_relsis_externalreltyper   IMAGEtarget_partappend)r   image_partsrel
image_parts       r   __iter__z_ImageParts.__iter__   s      =**,, 		 		C {bh&&J[((z***		 		r"   r   r   r   c                    t          j        |          }|                     |j                  }|r|nt	          j        | j        |          S )a=  Return |ImagePart| object containing the image in `image_file`.

        `image_file` can be either a path to an image file or a file-like object
        containing an image. If an image part containing this same image already exists,
        that instance is returned, otherwise a new image part is created.
        )r   	from_file_find_by_sha1sha1r   newrY   )r   r   imagerh   s       r   r!   z!_ImageParts.get_or_add_image_part   sE     
++''
33
'PzzY]4=%-P-PPr"   rm   r(   ImagePart | Nonec                P    | D ]"}t          |d          s|j        |k    r|c S #dS )z
        Return an |ImagePart| object belonging to this package or |None| if
        no matching image part is found. The image part is identified by the
        SHA1 hash digest of the image binary it contains.
        rm   N)hasattrrm   )r   rm   rh   s      r   rl   z_ImageParts._find_by_sha1   sK      	" 	"J:v.. $&&!!!! 'tr"   )r   r^   )r   r   r   r   )rm   r(   r   rp   )	rN   rO   rP   rQ   rX   ri   r!   rl   __classcell__r\   s   @r   rK   rK   }   s~        ::            	Q 	Q 	Q 	Q       r"   rK   c                  4     e Zd ZdZ fdZd Zd Zd Z xZS )rM   zProvides access to the media parts in a package.

    Supports iteration and :meth:`get()` using the media object SHA1 hash as
    its key.
    c                d    t          t          |                                            || _        d S rV   )rW   rM   rX   rY   rZ   s     r   rX   z_MediaParts.__init__   r]   r"   c              #     K   g }| j                                         D ]O}|j        r
|j        t          j        t          j        fvr*|j        }||v r6|                    |           |V  PdS )z?Generate a reference to each |MediaPart| object in the package.N)	rY   r`   ra   rb   r   MEDIAVIDEOrd   re   )r   media_partsrg   
media_parts       r   ri   z_MediaParts.__iter__   s      
 =**,, 		 		C {28RX"666J[((z***		 		r"   c                r    |                      |j                  }|t          j        | j        |          }|S )zReturn a |MediaPart| object containing the media in *media*.

        If this package already contains a media part for the same
        bytestream, that instance is returned, otherwise a new media part is
        created.
        )rl   rm   r   rn   rY   )r   r&   r{   s      r   r%   z!_MediaParts.get_or_add_media_part   s8     ''
33
"t}e<<Jr"   c                .    | D ]}|j         |k    r|c S dS )zReturn |MediaPart| object having *sha1* hash or None if not found.

        All media parts belonging to this package are considered. A media
        part is identified by the SHA1 hash digest of its bytestream
        ("file").
        N)rm   )r   rm   r{   s      r   rl   z_MediaParts._find_by_sha1   s6      	" 	"J$&&!!!! 'tr"   )	rN   rO   rP   rQ   rX   ri   r%   rl   rs   rt   s   @r   rM   rM      so                    "
 
 

 
 
 
 
 
 
r"   rM   N)rQ   
__future__r   typingr   r   pptx.opc.constantsr   r   pptx.opc.packager   pptx.opc.packurir	   pptx.parts.corepropsr
   pptx.parts.imager   r   pptx.parts.mediar   	pptx.utilr   r   objectrK   rM   rS   r"   r   <module>r      sK     " " " " " "         6 6 6 6 6 6 ' ' ' ' ' ' $ $ $ $ $ $ 3 3 3 3 3 3 - - - - - - - - & & & & & & " " " " " "j! j! j! j! j!j j! j! j!Z, , , , ,& , , ,^2 2 2 2 2& 2 2 2 2 2r"   