MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / load

Method load

src/bcf/bcf/v3/document.py:25–51  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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."""

Callers

nothing calls this directly

Calls 2

XmlParserSerializerClass · 0.90
parseMethod · 0.45

Tested by

no test coverage detected