Merge the supplied properties into the _properties dictionary. The input properties must adhere to the class schema or a KeyError or TypeError exception will be raised. If adding an object of an XCObject subclass and the schema indicates a strong relationship, the object's
(self, properties, do_copy=False)
| 756 | self._XCPrint(file, end_tabs, "};\n") |
| 757 | |
| 758 | def UpdateProperties(self, properties, do_copy=False): |
| 759 | """Merge the supplied properties into the _properties dictionary. |
| 760 | |
| 761 | The input properties must adhere to the class schema or a KeyError or |
| 762 | TypeError exception will be raised. If adding an object of an XCObject |
| 763 | subclass and the schema indicates a strong relationship, the object's |
| 764 | parent will be set to this object. |
| 765 | |
| 766 | If do_copy is True, then lists, dicts, strong-owned XCObjects, and |
| 767 | strong-owned XCObjects in lists will be copied instead of having their |
| 768 | references added. |
| 769 | """ |
| 770 | |
| 771 | if properties is None: |
| 772 | return |
| 773 | |
| 774 | for property, value in properties.items(): |
| 775 | # Make sure the property is in the schema. |
| 776 | if property not in self._schema: |
| 777 | raise KeyError(property + " not in " + self.__class__.__name__) |
| 778 | |
| 779 | # Make sure the property conforms to the schema. |
| 780 | (is_list, property_type, is_strong) = self._schema[property][0:3] |
| 781 | if is_list: |
| 782 | if not isinstance(value, list): |
| 783 | raise TypeError( |
| 784 | property |
| 785 | + " of " |
| 786 | + self.__class__.__name__ |
| 787 | + " must be list, not " |
| 788 | + value.__class__.__name__ |
| 789 | ) |
| 790 | for item in value: |
| 791 | if not isinstance(item, property_type) and not ( |
| 792 | isinstance(item, str) and isinstance(property_type, str) |
| 793 | ): |
| 794 | # Accept unicode where str is specified. str is treated as |
| 795 | # UTF-8-encoded. |
| 796 | raise TypeError( |
| 797 | "item of " |
| 798 | + property |
| 799 | + " of " |
| 800 | + self.__class__.__name__ |
| 801 | + " must be " |
| 802 | + property_type.__name__ |
| 803 | + ", not " |
| 804 | + item.__class__.__name__ |
| 805 | ) |
| 806 | elif not isinstance(value, property_type) and not ( |
| 807 | isinstance(value, str) and isinstance(property_type, str) |
| 808 | ): |
| 809 | # Accept unicode where str is specified. str is treated as |
| 810 | # UTF-8-encoded. |
| 811 | raise TypeError( |
| 812 | property |
| 813 | + " of " |
| 814 | + self.__class__.__name__ |
| 815 | + " must be " |
no test coverage detected