9898 insensitively defined as 0, false, no, off for False, and 1, true,
9999 yes, on for True). Returns False or True.
100100
101- items(section, raw=False, vars=None)
102- Return a list of tuples with (name, value) for each option
101+ items(section=_UNSET, raw=False, vars=None)
102+ If section is given, return a list of tuples with (section_name,
103+ section_proxy) for each section, including DEFAULTSECT. Otherwise,
104+ return a list of tuples with (name, value) for each option
103105 in the section.
104106
105107 remove_section(section)
@@ -495,9 +497,9 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
495497 raise InterpolationSyntaxError (
496498 option , section ,
497499 "More than one ':' found: %r" % (rest ,))
498- except KeyError :
500+ except ( KeyError , NoSectionError , NoOptionError ) :
499501 raise InterpolationMissingOptionError (
500- option , section , rest , var )
502+ option , section , rest , ":" . join ( path ) )
501503 if "$" in v :
502504 self ._interpolate_some (parser , opt , accum , v , sect ,
503505 dict (parser .items (sect , raw = True )),
@@ -730,7 +732,7 @@ def read_dict(self, dictionary, source='<dict>'):
730732 except (DuplicateSectionError , ValueError ):
731733 if self ._strict and section in elements_added :
732734 raise
733- elements_added .add (section )
735+ elements_added .add (section )
734736 for key , value in keys .items ():
735737 key = self .optionxform (str (key ))
736738 if value is not None :
@@ -820,7 +822,7 @@ def getboolean(self, section, option, *, raw=False, vars=None,
820822 else :
821823 return fallback
822824
823- def items (self , section , raw = False , vars = None ):
825+ def items (self , section = _UNSET , raw = False , vars = None ):
824826 """Return a list of (name, value) tuples for each option in a section.
825827
826828 All % interpolations are expanded in the return values, based on the
@@ -831,6 +833,8 @@ def items(self, section, raw=False, vars=None):
831833
832834 The section DEFAULT is special.
833835 """
836+ if section is _UNSET :
837+ return super ().items ()
834838 d = self ._defaults .copy ()
835839 try :
836840 d .update (self ._sections [section ])
@@ -851,7 +855,9 @@ def optionxform(self, optionstr):
851855 return optionstr .lower ()
852856
853857 def has_option (self , section , option ):
854- """Check for the existence of a given option in a given section."""
858+ """Check for the existence of a given option in a given section.
859+ If the specified `section' is None or an empty string, DEFAULT is
860+ assumed. If the specified `section' does not exist, returns False."""
855861 if not section or section == self .default_section :
856862 option = self .optionxform (option )
857863 return option in self ._defaults
@@ -1059,9 +1065,6 @@ def _read(self, fp, fpname):
10591065 # match if it would set optval to None
10601066 if optval is not None :
10611067 optval = optval .strip ()
1062- # allow empty values
1063- if optval == '""' :
1064- optval = ''
10651068 cursect [optname ] = [optval ]
10661069 else :
10671070 # valueless option handling
@@ -1196,21 +1199,24 @@ def __setitem__(self, key, value):
11961199 return self ._parser .set (self ._name , key , value )
11971200
11981201 def __delitem__ (self , key ):
1199- if not self ._parser .has_option (self ._name , key ):
1202+ if not (self ._parser .has_option (self ._name , key ) and
1203+ self ._parser .remove_option (self ._name , key )):
12001204 raise KeyError (key )
1201- return self ._parser .remove_option (self ._name , key )
12021205
12031206 def __contains__ (self , key ):
12041207 return self ._parser .has_option (self ._name , key )
12051208
12061209 def __len__ (self ):
1207- # XXX weak performance
1208- return len (self ._parser .options (self ._name ))
1210+ return len (self ._options ())
12091211
12101212 def __iter__ (self ):
1211- # XXX weak performance
1212- # XXX does not break when underlying container state changed
1213- return self ._parser .options (self ._name ).__iter__ ()
1213+ return self ._options ().__iter__ ()
1214+
1215+ def _options (self ):
1216+ if self ._name != self ._parser .default_section :
1217+ return self ._parser .options (self ._name )
1218+ else :
1219+ return self ._parser .defaults ()
12141220
12151221 def get (self , option , fallback = None , * , raw = False , vars = None ):
12161222 return self ._parser .get (self ._name , option , raw = raw , vars = vars ,
0 commit comments