MCPcopy Index your code
hub / github.com/python-openxml/python-docx / _ZipPkgReader

Class _ZipPkgReader

src/docx/opc/phys_pkg.py:71–101  ·  view source on GitHub ↗

Implements |PhysPkgReader| interface for a zip file OPC package.

Source from the content-addressed store, hash-verified

69
70
71class _ZipPkgReader(PhysPkgReader):
72 """Implements |PhysPkgReader| interface for a zip file OPC package."""
73
74 def __init__(self, pkg_file):
75 super(_ZipPkgReader, self).__init__()
76 self._zipf = ZipFile(pkg_file, "r")
77
78 def blob_for(self, pack_uri):
79 """Return blob corresponding to `pack_uri`.
80
81 Raises |ValueError| if no matching member is present in zip archive.
82 """
83 return self._zipf.read(pack_uri.membername)
84
85 def close(self):
86 """Close the zip archive, releasing any resources it is using."""
87 self._zipf.close()
88
89 @property
90 def content_types_xml(self):
91 """Return the `[Content_Types].xml` blob from the zip package."""
92 return self.blob_for(CONTENT_TYPES_URI)
93
94 def rels_xml_for(self, source_uri):
95 """Return rels item XML for source with `source_uri` or None if no rels item is
96 present."""
97 try:
98 rels_xml = self.blob_for(source_uri.rels_uri)
99 except KeyError:
100 rels_xml = None
101 return rels_xml
102
103
104class _ZipPkgWriter(PhysPkgWriter):

Callers 3

it_can_be_closedMethod · 0.90
phys_readerMethod · 0.90

Calls

no outgoing calls

Tested by 3

it_can_be_closedMethod · 0.72
phys_readerMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…