Parses an "initialize" request or response and extracts the feature flags. For every "X" in self.PROPERTIES, sets self["X"] to the corresponding value from message.payload if it's present there, or to the default value otherwise.
(self, component, message)
| 144 | """ |
| 145 | |
| 146 | def __init__(self, component, message): |
| 147 | """Parses an "initialize" request or response and extracts the feature flags. |
| 148 | |
| 149 | For every "X" in self.PROPERTIES, sets self["X"] to the corresponding value |
| 150 | from message.payload if it's present there, or to the default value otherwise. |
| 151 | """ |
| 152 | |
| 153 | assert message.is_request("initialize") or message.is_response("initialize") |
| 154 | |
| 155 | self.component = component |
| 156 | |
| 157 | payload = message.payload |
| 158 | for name, validate in self.PROPERTIES.items(): |
| 159 | value = payload.get(name, ()) |
| 160 | if not callable(validate): |
| 161 | validate = json.default(validate) |
| 162 | |
| 163 | try: |
| 164 | value = validate(value) |
| 165 | except Exception as exc: |
| 166 | raise message.isnt_valid("{0} {1}", json.repr(name), exc) |
| 167 | |
| 168 | assert ( |
| 169 | value != () |
| 170 | ), f"{validate} must provide a default value for missing properties." |
| 171 | self[name] = value |
| 172 | |
| 173 | log.debug("{0}", self) |
| 174 | |
| 175 | def __repr__(self): |
| 176 | return f"{type(self).__name__}: {json.repr(dict(self))}" |
nothing calls this directly
no test coverage detected