When configuration files are read, all option settings are merged together in a master dictionary that is heirarchically organized using the section keys as keys in the dictionary. The "Sections" (section 5.3) and "Section keys" (section 5.4) examples may help visualize this concept. When duplicate options exist at the same level, either in the same file or different files, the last one in wins.
When the parse()
method is called or when an option get()
method
is called a list of keys is constructed to walk through the dictionary
of settings. The key list is constructed in the following order with the
keys with top priority listed first
get()
keys argument
(see section 2.5 "Parsing")
add_option()
keys argument
(see section 2.3 "Adding options")
'DEFAULT'
key
The algorithm for obtaining a setting from the dictionary of heirarchically organized settings is:
start at top of option dictionary start at top of key list <----------------------- get next key <------------------------------- | no keys left) DONE - no setting found | | is key in dictionary? | | no) ------------------------------------ | yes) is setting a dictionary? | yes) proceed to next level -------------- no) DONE - setting found
This implementation allows the user to store multiple settings in the configuration file and provides great flexibility for controlling which settings get used.