
    l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y)zOverall .pptx package.    )annotations)IOIterator)RELATIONSHIP_TYPE)
OpcPackagePackURI)CorePropertiesPart)Image	ImagePart)	MediaPart)lazypropertyc                  n    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y
)PackagezAn overall .pptx package.c                    	 | j                  t        j                        S # t        $ r: t	        j
                  |       }| 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     J/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/pptx/package.pycore_propertieszPackage.core_properties   sW    	''(:(:;; 	+33D9JNN:r'9'9:	s   ! A A$#A$c                8    | j                   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   
image_files     r   r   zPackage.get_or_add_image_part    s       66zBB    c                8    | j                   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    c                <      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                 D   t        j                         D  cg c]I  } | j                  j                  d      r,| j                  j                  | j                  j                  K c}       }t        |      D ]  \  }}|dz   }||k  s|c S  t        |      dz   S c c} w )Nz/ppt/media/image   sorted
iter_partspartname
startswithidx	enumeratelen)part
image_idxsi	image_idxr-   r   s        r   first_available_image_idxz>Package.next_image_partname.<locals>.first_available_image_idx7   s     !% 1001CD MM--9	 MM%%	J !** 5 9!e?J z?Q&&s   ABz/ppt/media/image%d.%sr   )r   extr4   r-   s   `   r   next_image_partnamezPackage.next_image_partname0   s'    	'" ().#s;<<r    c                <      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        j                         D  cg c]3  } | j                  j                  d      r| j                  j                  5 c}       }t        |      D ]  \  }}|dz   }||k  s|c S  t        |      dz   S c c} w )Nz/ppt/media/mediar'   r(   )r0   
media_idxsr2   	media_idxr-   r   s        r   first_available_media_idxz>Package.next_media_partname.<locals>.first_available_media_idxS   s     !% 1}}//0BC MM%%J !** 5 9!e?J z?Q&&s   8Bz/ppt/media/media%d.%sr   )r   r5   r;   r-   s   `   r   next_media_partnamezPackage.next_media_partnameK   s'    	' ().#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.
        )_ImagePartsr?   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.
        )_MediaPartsr?   s    r   r"   zPackage._media_partss   s     4  r    N)returnr
   )r   str | IO[bytes])r5   strrE   r	   )__name__
__module____qualname____doc__r   r   r   r#   r6   r<   propertyr@   r   r"    r    r   r   r      sh    #
 
C>=6=2 ' ' ! ! ! !r    r   c                  :     e Zd ZdZ fdZddZddZddZ xZS )	rB   z0Provides access to the image parts in a package.c                8    t         t        |           || _        y N)superrB   __init___packager   package	__class__s     r   rR   z_ImageParts.__init__       k4)+r    c              #     K   g }| j                   j                         D ]S  }|j                  r|j                  t        j
                  k7  r.|j                  }||v r?|j                  |       | U yw)z?Generate a reference to each |ImagePart| object in the package.N)rS   	iter_relsis_externalreltyper   IMAGEtarget_partappend)r   image_partsrel
image_parts       r   __iter__z_ImageParts.__iter__   sl     ==**, 		C{{bhh&J[(z*		s   A4A6c                    t        j                  |      }| j                  |j                        }|r|S 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   newrS   )r   r   imagera   s       r   r   z!_ImageParts.get_or_add_image_part   sB     
+''

3
'zPY]]4==%-PPr    c                R    | D ]"  }t        |d      s|j                  |k(  s |c S  y)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.
        rf   N)hasattrrf   )r   rf   ra   s      r   re   z_ImageParts._find_by_sha1   s7      	"J:v.$&!!	" r    )rE   zIterator[ImagePart])r   rF   rE   r   )rf   rG   rE   zImagePart | None)	rH   rI   rJ   rK   rR   rb   r   re   __classcell__rV   s   @r   rB   rB   }   s    : 	Qr    rB   c                  4     e Zd ZdZ fdZd Zd Zd Z x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                8    t         t        |           || _        y rP   )rQ   rD   rR   rS   rT   s     r   rR   z_MediaParts.__init__   rW   r    c              #    K   g }| j                   j                         D ]b  }|j                  r|j                  t        j
                  t        j                  fvr=|j                  }||v rN|j                  |       | d yw)z?Generate a reference to each |MediaPart| object in the package.N)	rS   rY   rZ   r[   r   MEDIAVIDEOr]   r^   )r   media_partsr`   
media_parts       r   rb   z_MediaParts.__iter__   sw     
 ==**, 		C{{288RXX"66J[(z*		s   BBc                    | j                  |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.
        )re   rf   r   rg   rS   )r   r$   rs   s      r   r#   z!_MediaParts.get_or_add_media_part   s8     ''

3
"t}}e<Jr    c                8    | D ]  }|j                   |k(  s|c S  y)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)rf   )r   rf   rs   s      r   re   z_MediaParts._find_by_sha1   s*      	"J$&!!	" r    )	rH   rI   rJ   rK   rR   rb   r#   re   rk   rl   s   @r   rD   rD      s     "

r    rD   N)rK   
__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   objectrB   rD   rM   r    r   <module>r      sK     "  6 ' $ 3 - & "j!j j!Z,& ,^2& 2r    