MCPcopy Index your code
hub / github.com/python/cpython / read_dict

Method read_dict

Lib/configparser.py:782–812  ·  view source on GitHub ↗

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>')

Source from the content-addressed store, hash-verified

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.

Callers 5

__setitem__Method · 0.95
_read_defaultsMethod · 0.80
test_basic_from_dictMethod · 0.80
test_weird_errorsMethod · 0.80
fromstringMethod · 0.80

Calls 8

add_sectionMethod · 0.95
optionxformMethod · 0.95
setMethod · 0.95
setFunction · 0.85
strFunction · 0.85
itemsMethod · 0.45
addMethod · 0.45

Tested by 3

test_basic_from_dictMethod · 0.64
test_weird_errorsMethod · 0.64
fromstringMethod · 0.64