MCPcopy Create free account
hub / github.com/scanny/python-pptx / _ZipPkgWriter

Class _ZipPkgWriter

src/pptx/opc/serialized.py:217–243  ·  view source on GitHub ↗

Implements |PhysPkgWriter| interface for a zip-file (.pptx file) OPC package.

Source from the content-addressed store, hash-verified

215
216
217class _ZipPkgWriter(_PhysPkgWriter):
218 """Implements |PhysPkgWriter| interface for a zip-file (.pptx file) OPC package."""
219
220 def __init__(self, pkg_file: str | IO[bytes]):
221 self._pkg_file = pkg_file
222
223 def __enter__(self) -> _ZipPkgWriter:
224 """Enable use as a context-manager. Opening zip for writing happens here."""
225 return self
226
227 def __exit__(self, *exc: list[Any]) -> None:
228 """Close the zip archive on exit from context.
229
230 Closing flushes any pending physical writes and releasing any resources it's using.
231 """
232 self._zipf.close()
233
234 def write(self, pack_uri: PackURI, blob: bytes) -> None:
235 """Write `blob` to zip package with membername corresponding to `pack_uri`."""
236 self._zipf.writestr(pack_uri.membername, blob)
237
238 @lazyproperty
239 def _zipf(self) -> zipfile.ZipFile:
240 """`ZipFile` instance open for writing."""
241 return zipfile.ZipFile(
242 self._pkg_file, "w", compression=zipfile.ZIP_DEFLATED, strict_timestamps=False
243 )
244
245
246class _ContentTypesItem:

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…