| 485 | super().update({key: value}) |
| 486 | |
| 487 | def update(self, update_dict): |
| 488 | changes = {} |
| 489 | for key, value in update_dict.items(): |
| 490 | # Ensure the value is either a _Section or a string |
| 491 | if isinstance(value, (dict, OrderedDict)): |
| 492 | sect = _Section( |
| 493 | name=key, |
| 494 | inicontents="", |
| 495 | separator=self.sep, |
| 496 | commenter=self.com, |
| 497 | no_spaces=self.no_spaces, |
| 498 | ) |
| 499 | sect.update(value) |
| 500 | value = sect |
| 501 | value_plain = value.as_dict() |
| 502 | else: |
| 503 | value = str(value) |
| 504 | value_plain = value |
| 505 | |
| 506 | if key not in self: |
| 507 | changes.update({key: {"before": None, "after": value_plain}}) |
| 508 | # If it's not a section, it may already exist as a |
| 509 | # commented-out key/value pair |
| 510 | if not isinstance(value, _Section): |
| 511 | self._uncomment_if_commented(key) |
| 512 | |
| 513 | super().update({key: value}) |
| 514 | else: |
| 515 | curr_value = self.get(key, None) |
| 516 | if isinstance(curr_value, _Section): |
| 517 | sub_changes = curr_value.update(value) |
| 518 | if sub_changes: |
| 519 | changes.update({key: sub_changes}) |
| 520 | else: |
| 521 | if curr_value != value: |
| 522 | changes.update( |
| 523 | {key: {"before": curr_value, "after": value_plain}} |
| 524 | ) |
| 525 | super().update({key: value}) |
| 526 | return changes |
| 527 | |
| 528 | def gen_ini(self): |
| 529 | yield f"{os.linesep}[{self.name}]{os.linesep}" |