Read configuration from a dictionary. Keys are section names, values are dictionaries with keys and values that should be present in the section. If the used dictionary type preserves order, sections and their keys will be added in order. All types held in the dicti
(self, dictionary, source='<dict>')
| 780 | self.read_file(sfile, source) |
| 781 | |
| 782 | def read_dict(self, dictionary, source='<dict>'): |
| 783 | """Read configuration from a dictionary. |
| 784 | |
| 785 | Keys are section names, values are dictionaries with keys and values |
| 786 | that should be present in the section. If the used dictionary type |
| 787 | preserves order, sections and their keys will be added in order. |
| 788 | |
| 789 | All types held in the dictionary are converted to strings during |
| 790 | reading, including section names, option names and keys. |
| 791 | |
| 792 | Optional second argument is the `source` specifying the name of the |
| 793 | dictionary being read. |
| 794 | """ |
| 795 | elements_added = set() |
| 796 | for section, keys in dictionary.items(): |
| 797 | if section is not UNNAMED_SECTION: |
| 798 | section = str(section) |
| 799 | try: |
| 800 | self.add_section(section) |
| 801 | except (DuplicateSectionError, ValueError): |
| 802 | if self._strict and section in elements_added: |
| 803 | raise |
| 804 | elements_added.add(section) |
| 805 | for key, value in keys.items(): |
| 806 | key = self.optionxform(str(key)) |
| 807 | if value is not None: |
| 808 | value = str(value) |
| 809 | if self._strict and (section, key) in elements_added: |
| 810 | raise DuplicateOptionError(section, key, source) |
| 811 | elements_added.add((section, key)) |
| 812 | self.set(section, key, value) |
| 813 | |
| 814 | def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET): |
| 815 | """Get an option value for a given section. |