| 86 | |
| 87 | |
| 88 | class Ids: |
| 89 | info: dict[str, Any] |
| 90 | |
| 91 | def __init__( |
| 92 | self, |
| 93 | title: Optional[str] = "Untitled", |
| 94 | copyright=None, |
| 95 | version=None, |
| 96 | description=None, |
| 97 | author=None, |
| 98 | date=None, |
| 99 | purpose=None, |
| 100 | milestone=None, |
| 101 | ): |
| 102 | # Not part of the IDS spec, but very useful in practice |
| 103 | self.filepath: Optional[str] = None |
| 104 | self.filename: Optional[str] = None |
| 105 | |
| 106 | self.specifications: list[Specification] = [] |
| 107 | self.info = {} |
| 108 | self.info["title"] = title or "Untitled" |
| 109 | if copyright: |
| 110 | self.info["copyright"] = copyright |
| 111 | if version: |
| 112 | self.info["version"] = version |
| 113 | if description: |
| 114 | self.info["description"] = description |
| 115 | if author and "@" in author: |
| 116 | self.info["author"] = author |
| 117 | if date: |
| 118 | try: |
| 119 | self.info["date"] = datetime.date.fromisoformat(date).isoformat() |
| 120 | except ValueError: |
| 121 | pass |
| 122 | if purpose: |
| 123 | self.info["purpose"] = purpose |
| 124 | if milestone: |
| 125 | self.info["milestone"] = milestone |
| 126 | |
| 127 | def asdict(self) -> dict[str, Any]: |
| 128 | info: dict[str, Any] = {} |
| 129 | for attr in ["title", "copyright", "version", "description", "author", "date", "purpose", "milestone"]: |
| 130 | if attr in self.info: |
| 131 | info[attr] = self.info[attr] |
| 132 | ids_dict: dict[str, Any] = { |
| 133 | "@xmlns": "http://standards.buildingsmart.org/IDS", |
| 134 | "@xmlns:xs": "http://www.w3.org/2001/XMLSchema", |
| 135 | "@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", |
| 136 | "@xsi:schemaLocation": "http://standards.buildingsmart.org/IDS http://standards.buildingsmart.org/IDS/1.0/ids.xsd", |
| 137 | "info": info, |
| 138 | "specifications": {"specification": []}, |
| 139 | } |
| 140 | for spec in self.specifications: |
| 141 | ids_dict["specifications"]["specification"].append(spec.asdict()) |
| 142 | return ids_dict |
| 143 | |
| 144 | def parse(self, data): |
| 145 | for attribute in ["title", "copyright", "version", "description", "author", "date", "purpose", "milestone"]: |
no outgoing calls
no test coverage detected