XjdZddlmZddlmZmZddlmZddl m Z m Z ddl m Z mZddlmZddlmZdd lmZerdd lmZGd d ZGd dZy)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_CHECKINGIterable) CONTENT_TYPE)CT_Typesserialize_part_xml)CONTENT_TYPES_URI PACKAGE_URI) PhysPkgWriter)CaseInsensitiveDict)default_content_types)PartcReZdZdZedZedZeddZedZy) 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. ct|}tj||tj||tj |||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_partsclose)pkg_filepkg_relsparts phys_writers f/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/opc/pkgwriter.pywritezPackageWriter.writesJ$H- 11+uE%%k8<"";6cntj|}|jt|jy)zWrite ``[Content_Types].xml`` part to the physical package with an appropriate content type lookup target for each part in `parts`.N)_ContentTypesItem from_partsrr blob)rrctis rrz)PackageWriter._write_content_types_stream(s) **51+SXX6rc|D]x}|j|j|jt|js?|j|jj |jj zy)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)rpartnamer lenrelsrels_urixml)rrparts rrzPackageWriter._write_parts/sZ ID   dmmTYY 7499~!!$--"8"8$))--H IrcX|jtj|jy)zGWrite the XML rels item for `pkg_rels` ('/_rels/.rels') to the package.N)rr r&r')rrs rrzPackageWriter._write_pkg_rels8s +.. =rN)rr rzIterable[Part]) __name__ __module__ __qualname____doc__ staticmethodrrrrrrrrsY77 II>>rrcLeZdZdZdZedZedZdZ edZ y)rzService 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)``. c0t|_i|_y)N)r _defaults _overridesselfs r__init__z_ContentTypesItem.__init__Fs,.rc,t|jS)zvReturn XML form of this content types item, suitable for storage as ``[Content_Types].xml`` in an OPC package.)r_elementr4s rr z_ContentTypesItem.blobJs"$--00rc|}tj|jd<tj|jd<|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')CTOPC_RELATIONSHIPSr2XML_add_content_typer# content_type)clsrr!r(s rrz_ContentTypesItem.from_partsPsa e " 4 4 f!vv e DD  ! !$--1B1B C D rc|j}|j|ftvr||j|<y||j|<y)zwAdd a content type for the part with `partname` and `content_type`, using a default or override as appropriate.N)extlowerr r2r3)r5r#r>rAs rr=z#_ContentTypesItem._add_content_type\s=ll IIK &*? ?".DNN3 (4DOOH %rcJtj}t|jj D]!}|j ||j|#t|j j D]!}|j||j |#|S)aSReturn 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. )rnewsortedr2keys add_defaultr3 add_override)r5 _types_elmrAr#s rr8z_ContentTypesItem._elementes\\^ $..--/0 =C  " "3s(; < =t3356 IH  # #Hdooh.G H IrN) r*r+r,r-r6propertyr classmethodrr=r8r/rrrr>sM11   5  rrN)r- __future__rtypingrrdocx.opc.constantsrr: docx.opc.oxmlrrdocx.opc.packurir r docx.opc.phys_pkgr docx.opc.sharedr docx.opc.specr docx.opc.partrrrr/rrrUs? #*16;+//"%>%>P55r