Implements |PhysPkgReader| interface for a zip file OPC package.
| 69 | |
| 70 | |
| 71 | class _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 | |
| 104 | class _ZipPkgWriter(PhysPkgWriter): |
no outgoing calls
searching dependent graphs…