Loads the documents from the given zip file directory. Args: zip_path: The directory path inside the zip file. xml_handler: The xml parser/serializer to use. Returns: The documents handler.
(
cls,
zip_file: zipfile.ZipFile,
xml_handler: Optional[AbstractXmlParserSerializer] = None,
)
| 23 | |
| 24 | @classmethod |
| 25 | def load( |
| 26 | cls, |
| 27 | zip_file: zipfile.ZipFile, |
| 28 | xml_handler: Optional[AbstractXmlParserSerializer] = None, |
| 29 | ) -> Optional["DocumentsHandler"]: |
| 30 | """ |
| 31 | Loads the documents from the given zip file directory. |
| 32 | |
| 33 | Args: |
| 34 | zip_path: The directory path inside the zip file. |
| 35 | xml_handler: The xml parser/serializer to use. |
| 36 | |
| 37 | Returns: |
| 38 | The documents handler. |
| 39 | """ |
| 40 | xml_handler = xml_handler or XmlParserSerializer() |
| 41 | file_to_open = zipfile.Path(zip_file, "documents.xml") |
| 42 | if not file_to_open.exists(): |
| 43 | return None |
| 44 | definition = xml_handler.parse(file_to_open.read_bytes(), mdl.DocumentInfo) |
| 45 | documents = {} |
| 46 | if def_docs := definition.documents: |
| 47 | for document in def_docs.document: |
| 48 | document_path = zipfile.Path(zip_file, f"documents/{document.guid}") |
| 49 | if document_path.exists(): |
| 50 | documents[document.filename] = document_path.read_bytes() |
| 51 | return cls(definition, documents=documents) |
| 52 | |
| 53 | def save(self, bcf_zip: ZipFileInterface) -> None: |
| 54 | """Save the documents to the zip file.""" |
nothing calls this directly
no test coverage detected