o
    j                     @  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).
        )part_related_byRTCORE_PROPERTIESKeyErrorr	   default	relate_to)self
core_props r   L/home/air/Certificate/back/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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)
image_idxsi	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$   r:   r+   r   r9   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>r0   r1   )
media_idxsr7   	media_idxr+   r9   r   r   first_available_media_idxS   s   z>Package.next_media_partname.<locals>.first_available_media_idxz/ppt/media/media%d.%sr   )r   r$   r>   r+   r   r9   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_partr9   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.
        )_ImagePartsr9   r   r   r   r   k   s   zPackage._image_partsc                 C  rB   )zReturn |_MediaParts| object for this package.

        The media parts object provides access to all the media parts in this
        package.
        )_MediaPartsr9   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"   r;   r?   propertyrA   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 )rC   z0Provides access to the image parts in a package.c                      t t|   || _d S N)superrC   __init___packager   package	__class__r   r   rM         
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)rN   	iter_relsis_externalreltyper   IMAGEtarget_partappend)r   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   newrN   )r   r   imager]   r   r   r   r      s   
z!_ImageParts.get_or_add_image_partra   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.
        ra   N)hasattrra   )r   ra   r]   r   r   r   r`      s   

z_ImageParts._find_by_sha1)r   rT   )r   r   r   r   )ra   r%   r   rd   )	rE   rF   rG   rH   rM   r^   r   r`   __classcell__r   r   rQ   r   rC   }   s    

rC   c                      s8   e Zd ZdZ fddZdd Zdd Zdd	 Z  ZS )
rD   zProvides access to the media parts in a package.

    Supports iteration and :meth:`get()` using the media object SHA1 hash as
    its key.
    c                   rJ   rK   )rL   rD   rM   rN   rO   rQ   r   r   rM      rS   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)	rN   rU   rV   rW   r   MEDIAVIDEOrY   rZ   )r   media_partsr\   
media_partr   r   r   r^      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)r`   ra   r   rb   rN   )r   r#   rj   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)ra   )r   ra   rj   r   r   r   r`      s
   
z_MediaParts._find_by_sha1)	rE   rF   rG   rH   rM   r^   r"   r`   rf   r   r   rQ   r   rD      s    rD   N)rH   
__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   objectrC   rD   r   r   r   r   <module>   s    m/