XjdZddlZddlmZmZmZddlmZddlm Z GddZ Gdd Z Gd d e Z Gd d e Z Gdde Zy)zMProvides a general interface to a `physical` OPC package, such as a zip file.N) ZIP_DEFLATEDZipFile is_zipfile)PackageNotFoundError)CONTENT_TYPES_URIc"eZdZdZfdZxZS) PhysPkgReaderz,Factory for physical package reader objects.ct|trFtjj |rt }n&t |rt}ntd|zt}tt|/|S)NzPackage not found at '%s') isinstancestrospathisdir _DirPkgReaderr _ZipPkgReaderrsuperr __new__)clspkg_file reader_cls __class__s e/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/opc/phys_pkg.pyrzPhysPkgReader.__new__ sW h $ww}}X&* H%* *+F+QRR&J]C0<<__name__ __module__ __qualname____doc__r __classcell__rs@rr r s6 = =rr c"eZdZdZfdZxZS) PhysPkgWriterz,Factory for physical package writer objects.c2tt| tS)N)rr"r _ZipPkgWriter)rrrs rrzPhysPkgWriter.__new__s]C0??rrr s@rr"r"s6@@rr"cDeZdZdZfdZdZdZedZdZ xZ S)rzWImplements |PhysPkgReader| interface for an OPC package extracted into a directory.crtt| tjj ||_y)zA`path` is the path to a directory containing an expanded package.N)rr__init__r rabspath_path)selfrrs rr'z_DirPkgReader.__init__'s$ mT+-WW__T* rctjj|j|j}t |d5}|j }ddd|S#1swYSxYw)zIReturn contents of file corresponding to `pack_uri` in package directory.rbN)r rjoinr) membernameopenread)r*pack_urirfblobs rblob_forz_DirPkgReader.blob_for,sQww||DJJ(;(;< $  668D    s AA&cy)z|Provides interface consistency with |ZipFileSystem|, but does nothing, a directory file system doesn't need closing.Nr*s rclosez_DirPkgReader.close3s rc,|jtS)z7Return the `[Content_Types].xml` blob from the package.r4rr7s rcontent_types_xmlz_DirPkgReader.content_types_xml8}}.//rcb |j|j}|S#t$rd}Y|SwxYw)z`Return rels item XML for source with `source_uri`, or None if the item has no rels item.N)r4rels_uriIOErrorr* source_urirels_xmls r rels_xml_forz_DirPkgReader.rels_xml_for=s= }}Z%8%89H H   .. rrrrr'r4r8propertyr;rCrr s@rrr#s0+  00rrcDeZdZdZfdZdZdZedZdZ xZ S)rz@Implements |PhysPkgReader| interface for a zip file OPC package.cLtt| t|d|_y)Nr)rrr'r_zipfr*rrs rr'z_ZipPkgReader.__init__Js mT+-Xs+ rcL|jj|jS)zReturn blob corresponding to `pack_uri`. Raises |ValueError| if no matching member is present in zip archive. )rJr0r.)r*r1s rr4z_ZipPkgReader.blob_forNs zzx2233rc8|jjy)z;Close the zip archive, releasing any resources it is using.NrJr8r7s rr8z_ZipPkgReader.closeUs rc,|jtS)z;Return the `[Content_Types].xml` blob from the zip package.r:r7s rr;z_ZipPkgReader.content_types_xmlYr<rcb |j|j}|S#t$rd}Y|SwxYw)z]Return rels item XML for source with `source_uri` or None if no rels item is present.N)r4r>KeyErrorr@s rrCz_ZipPkgReader.rels_xml_for^s= }}Z%8%89H H rDrEr s@rrrGs.J,400rrc.eZdZdZfdZdZdZxZS)r$z@Implements |PhysPkgWriter| interface for a zip file OPC package.cXtt| t|dt|_y)Nw) compression)rr$r'rrrJrKs rr'z_ZipPkgWriter.__init__ks  mT+-Xs E rc8|jjy)zkClose the zip archive, flushing any pending physical writes and releasing any resources it's using.NrNr7s rr8z_ZipPkgWriter.closeos rcP|jj|j|y)zYWrite `blob` to this zip package with the membername corresponding to `pack_uri`.N)rJwritestrr.)r*r1r3s rwritez_ZipPkgWriter.writets H//6r)rrrrr'r8rYrr s@rr$r$hsJF 7rr$)rr zipfilerrrdocx.opc.exceptionsrdocx.opc.packurirr r"rrr$r6rrr]sSS 554.==$@@!M!HMB7M7r