@@ -691,6 +691,7 @@ def __init__(self, defaults=None, dict_type=_default_dict,
691691 self ._read_defaults (defaults )
692692 self ._allow_unnamed_section = allow_unnamed_section
693693
694+
694695 def defaults (self ):
695696 return self ._defaults
696697
@@ -758,7 +759,6 @@ def read(self, filenames, encoding=None):
758759 if isinstance (filename , os .PathLike ):
759760 filename = os .fspath (filename )
760761 read_ok .append (filename )
761- self ._loaded_sources .append (read_ok )
762762 return read_ok
763763
764764 def read_file (self , f , source = None ):
@@ -775,7 +775,6 @@ def read_file(self, f, source=None):
775775 except AttributeError :
776776 source = '<???>'
777777 self ._read (f , source )
778- self ._loaded_sources .append (source )
779778
780779 def read_string (self , string , source = '<string>' ):
781780 """Read configuration from a given string."""
@@ -812,7 +811,6 @@ def read_dict(self, dictionary, source='<dict>'):
812811 raise DuplicateOptionError (section , key , source )
813812 elements_added .add ((section , key ))
814813 self .set (section , key , value )
815- self ._loaded_sources .append (source )
816814
817815 def get (self , section , option , * , raw = False , vars = None , fallback = _UNSET ):
818816 """Get an option value for a given section.
@@ -1054,11 +1052,12 @@ def __iter__(self):
10541052
10551053 def __str__ (self ):
10561054 config_dict = {
1057- section : dict ( self .items (section , raw = True ))
1055+ section : { key : value for key , value in self .items (section , raw = True )}
10581056 for section in self .sections ()
10591057 }
10601058 return f"<ConfigParser: { config_dict } >"
10611059
1060+
10621061 def __repr__ (self ):
10631062 params = {
10641063 "defaults" : self ._defaults if self ._defaults else None ,
@@ -1073,8 +1072,8 @@ def __repr__(self):
10731072 sections_count = len (self ._sections )
10741073 state = {
10751074 "loaded_sources" : self ._loaded_sources ,
1076- "sections_count" : sections_count ,
1077- "sections" : list (self ._sections ) [:5 ], # limit to 5 section names for readability
1075+ "sections_count" : len ( self . _sections ) ,
1076+ "sections" : list (self ._sections . keys ()) [:5 ], # Limit to 5 section names for readability
10781077 }
10791078
10801079 if sections_count > 5 :
@@ -1084,6 +1083,7 @@ def __repr__(self):
10841083 f"params={ params } , "
10851084 f"state={ state } )>" )
10861085
1086+
10871087 def _read (self , fp , fpname ):
10881088 """Parse a sectioned configuration file.
10891089
@@ -1255,14 +1255,11 @@ def _convert_to_boolean(self, value):
12551255
12561256 def _validate_key_contents (self , key ):
12571257 """Raises an InvalidWriteError for any keys containing
1258- delimiters or that begins with the section header pattern"""
1258+ delimiters or that match the section header pattern"""
12591259 if re .match (self .SECTCRE , key ):
1260- raise InvalidWriteError (
1261- f"Cannot write key { key } ; begins with section pattern" )
1262- for delim in self ._delimiters :
1263- if delim in key :
1264- raise InvalidWriteError (
1265- f"Cannot write key { key } ; contains delimiter { delim } " )
1260+ raise InvalidWriteError ("Cannot write keys matching section pattern" )
1261+ if any (delim in key for delim in self ._delimiters ):
1262+ raise InvalidWriteError ("Cannot write key that contains delimiters" )
12661263
12671264 def _validate_value_types (self , * , section = "" , option = "" , value = "" ):
12681265 """Raises a TypeError for illegal non-string values.
0 commit comments