
    ,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
mZ ddlmZmZ ddlmZ ddlmZ dd	lmZ erdd
lmZ  G d d      Z G d d      Zy)zProvides low-level, write-only API to serialized (OPC) package.

OPC stands for Open Packaging Convention. This is e, essentially an implementation of
OpcPackage.save().
    )annotations)TYPE_CHECKINGIterable)CONTENT_TYPE)CT_Typesserialize_part_xml)CONTENT_TYPES_URIPACKAGE_URI)PhysPkgWriter)CaseInsensitiveDict)default_content_types)Partc                  R    e Zd ZdZed        Zed        Zedd       Zed        Zy)PackageWriterzWrites a zip-format OPC package to `pkg_file`, where `pkg_file` can be either a
    path to a zip file (a string) or a file-like object.

    Its single API method, :meth:`write`, is static, so this class is not intended to be
    instantiated.
    c                    t        |       }t        j                  ||       t        j                  ||       t        j	                  ||       |j                          y)zWrite a physical package (.pptx file) to `pkg_file` containing `pkg_rels` and
        `parts` and a content types stream based on the content types of the parts.N)r   r   _write_content_types_stream_write_pkg_rels_write_partsclose)pkg_filepkg_relspartsphys_writers       T/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/opc/pkgwriter.pywritezPackageWriter.write   sJ     $H-11+uE%%k8<"";6    c                n    t         j                  |      }| j                  t        |j                         y)zWrite ``[Content_Types].xml`` part to the physical package with an
        appropriate content type lookup target for each part in `parts`.N)_ContentTypesItem
from_partsr   r	   blob)r   r   ctis      r   r   z)PackageWriter._write_content_types_stream(   s)      **51+SXX6r   c                    |D ]x  }| j                  |j                  |j                         t        |j                        s?| j                  |j                  j
                  |j                  j                         z y)zWrite the blob of each part in `parts` to the package, along with a rels item
        for its relationships if and only if it has any.N)r   partnamer    lenrelsrels_urixml)r   r   parts      r   r   zPackageWriter._write_parts/   sZ      	IDdmmTYY7499~!!$--"8"8$))--H	Ir   c                X    | j                  t        j                  |j                         y)zGWrite the XML rels item for `pkg_rels` ('/_rels/.rels') to the package.N)r   r
   r&   r'   )r   r   s     r   r   zPackageWriter._write_pkg_rels8   s     	+..=r   N)r   r   r   zIterable[Part])	__name__
__module____qualname____doc__staticmethodr   r   r   r    r   r   r   r      sY       7 7 I I > >r   r   c                  L    e Zd ZdZd Zed        Zed        Zd Z	ed        Z
y)r   zService class that composes a content types item ([Content_Types].xml) based on a
    list of parts.

    Not meant to be instantiated directly, its single interface method is xml_for(),
    e.g. ``_ContentTypesItem.xml_for(parts)``.
    c                0    t               | _        i | _        y )N)r   	_defaults
_overridesselfs    r   __init__z_ContentTypesItem.__init__F   s    ,.r   c                ,    t        | j                        S )zvReturn XML form of this content types item, suitable for storage as
        ``[Content_Types].xml`` in an OPC package.)r   _elementr4   s    r   r    z_ContentTypesItem.blobJ   s     "$--00r   c                     |        }t         j                  |j                  d<   t         j                  |j                  d<   |D ](  }|j	                  |j
                  |j                         * |S )zReturn content types XML mapping each part in `parts` to the appropriate
        content type and suitable for storage as ``[Content_Types].xml`` in an OPC
        package.r%   r'   )CTOPC_RELATIONSHIPSr2   XML_add_content_typer#   content_type)clsr   r!   r(   s       r   r   z_ContentTypesItem.from_partsP   sa    
 e " 4 4f!vve 	DD!!$--1B1BC	D
r   c                    |j                   }|j                         |ft        v r|| j                  |<   y|| j                  |<   y)zwAdd a content type for the part with `partname` and `content_type`, using a
        default or override as appropriate.N)extlowerr   r2   r3   )r5   r#   r>   rA   s       r   r=   z#_ContentTypesItem._add_content_type\   s=     llIIK&*??".DNN3(4DOOH%r   c                J   t        j                         }t        | j                  j	                               D ]!  }|j                  || j                  |          # t        | j                  j	                               D ]!  }|j                  || j                  |          # |S )aS  Return XML form of this content types item, suitable for storage as
        ``[Content_Types].xml`` in an OPC package.

        Although the sequence of elements is not strictly significant, as an aid to
        testing and readability Default elements are sorted by extension and Override
        elements are sorted by partname.
        )r   newsortedr2   keysadd_defaultr3   add_override)r5   
_types_elmrA   r#   s       r   r8   z_ContentTypesItem._elemente   s     \\^
$..--/0 	=C""3s(;<	=t3356 	IH##Hdooh.GH	Ir   N)r*   r+   r,   r-   r6   propertyr    classmethodr   r=   r8   r/   r   r   r   r   >   sM     1 1
 	 	5  r   r   N)r-   
__future__r   typingr   r   docx.opc.constantsr   r:   docx.opc.oxmlr   r   docx.opc.packurir	   r
   docx.opc.phys_pkgr   docx.opc.sharedr   docx.opc.specr   docx.opc.partr   r   r   r/   r   r   <module>rU      s?    # * 1 6 ; + / /"%> %>P5 5r   