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

        Creates a default core properties part if one is not present (not common).
        )Zpart_related_byRTCORE_PROPERTIESKeyErrorr	   defaultZ	relate_to)selfZ
core_props r   T/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/pptx/package.pycore_properties   s   
zPackage.core_properties
image_filestr | IO[bytes]c                 C     | 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   r   r   r   r          zPackage.get_or_add_image_partc                 C  r   )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   mediar   r   r   r   (   r   zPackage.get_or_add_media_partextstrr   c                   "    fdd}| }t d||f 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                    L   t dd   D } t| D ]\}}|d }||k r|  S qt| d S )Nc                 S  s,   g | ]}|j d r|j jdur|j jqS )z/ppt/media/imageNZpartname
startswithidx.0partr   r   r   
<listcomp>9   s    
zRPackage.next_image_partname.<locals>.first_available_image_idx.<locals>.<listcomp>   sorted
iter_parts	enumeratelen)Z
image_idxsiZ	image_idxr'   r   r   r   first_available_image_idx7   s   
z>Package.next_image_partname.<locals>.first_available_image_idxz/ppt/media/image%d.%sr   )r   r!   r4   r'   r   r3   r   next_image_partname0   s   zPackage.next_image_partnamec                   r#   )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                    r$   )Nc                 S  s    g | ]}|j d r|j jqS )z/ppt/media/mediar%   r(   r   r   r   r+   U   s    
zRPackage.next_media_partname.<locals>.first_available_media_idx.<locals>.<listcomp>r,   r-   )Z
media_idxsr2   Z	media_idxr'   r3   r   r   first_available_media_idxS   s   z>Package.next_media_partname.<locals>.first_available_media_idxz/ppt/media/media%d.%sr   )r   r!   r6   r'   r   r3   r   next_media_partnameK   s   zPackage.next_media_partnamec                 C  s   | j S )zU
        Reference to the |Presentation| instance contained in this package.
        )main_document_partr3   r   r   r   presentation_partd   s   zPackage.presentation_partc                 C     t | S )zc
        |_ImageParts| object providing access to the image parts in this
        package.
        )_ImagePartsr3   r   r   r   r   k   s   zPackage._image_partsc                 C  r:   )zReturn |_MediaParts| object for this package.

        The media parts object provides access to all the media parts in this
        package.
        )_MediaPartsr3   r   r   r   r   s   s   zPackage._media_partsN)r   r	   )r   r   )r!   r"   r   r   )__name__
__module____qualname____doc__r   r   r   r   r5   r7   propertyr9   r   r   r   r   r   r   r      s    



r   c                      s>   e Zd ZdZ fddZdddZdddZdddZ  ZS )r;   z0Provides access to the image parts in a package.c                      t t|   || _d S N)superr;   __init___packager   package	__class__r   r   rE         
z_ImageParts.__init__r   Iterator[ImagePart]c                 c  sP    g }| j  D ]}|jrq|jtjkrq|j}||v rq|| |V  qdS )z?Generate a reference to each |ImagePart| object in the package.N)rF   	iter_relsis_externalreltyper   IMAGEtarget_partappend)r   Zimage_partsrel
image_partr   r   r   __iter__   s   
z_ImageParts.__iter__r   r   r   c                 C  s,   t |}| |j}|r|S t| 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   newrF   )r   r   imagerT   r   r   r   r      s   
z!_ImageParts.get_or_add_image_partrX   r"   ImagePart | Nonec                 C  s,   | D ]}t |ds
q|j|kr|  S q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.
        rX   N)hasattrrX   )r   rX   rT   r   r   r   rW      s   

z_ImageParts._find_by_sha1)r   rL   )r   r   r   r   )rX   r"   r   r[   )	r=   r>   r?   r@   rE   rU   r   rW   __classcell__r   r   rI   r   r;   }   s    

r;   c                      s8   e Zd ZdZ fddZdd Zdd Zdd	 Z  ZS )
r<   zProvides access to the media parts in a package.

    Supports iteration and :meth:`get()` using the media object SHA1 hash as
    its key.
    c                   rB   rC   )rD   r<   rE   rF   rG   rI   r   r   rE      rK   z_MediaParts.__init__c                 c  sV    g }| j  D ] }|jrq|jtjtjfvrq|j}||v r q|| |V  qdS )z?Generate a reference to each |MediaPart| object in the package.N)	rF   rM   rN   rO   r   MEDIAVIDEOrQ   rR   )r   Zmedia_partsrS   
media_partr   r   r   rU      s   
z_MediaParts.__iter__c                 C  s&   |  |j}|du rt| 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.
        N)rW   rX   r   rY   rF   )r   r    r`   r   r   r   r      s   z!_MediaParts.get_or_add_media_partc                 C  s    | D ]}|j |kr|  S q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)rX   )r   rX   r`   r   r   r   rW      s
   
z_MediaParts._find_by_sha1)	r=   r>   r?   r@   rE   rU   r   rW   r]   r   r   rI   r   r<      s    r<   N)r@   
__future__r   typingr   r   pptx.opc.constantsr   r   pptx.opc.packager   Zpptx.opc.packurir   pptx.parts.corepropsr	   pptx.parts.imager
   r   pptx.parts.mediar   	pptx.utilr   r   objectr;   r<   r   r   r   r   <module>   s    m/