@@ -997,8 +997,7 @@ def _read(self, fp, fpname):
997
997
sectname = mo .group ('header' )
998
998
if sectname in self ._sections :
999
999
if self ._strict and sectname in elements_added :
1000
- raise DuplicateSectionError (sectname , fpname ,
1001
- lineno )
1000
+ self ._handle_duplicate_section (sectname , fpname , lineno )
1002
1001
cursect = self ._sections [sectname ]
1003
1002
elements_added .add (sectname )
1004
1003
elif sectname == self .default_section :
@@ -1023,8 +1022,7 @@ def _read(self, fp, fpname):
1023
1022
optname = self .optionxform (optname .rstrip ())
1024
1023
if (self ._strict and
1025
1024
(sectname , optname ) in elements_added ):
1026
- raise DuplicateOptionError (sectname , optname ,
1027
- fpname , lineno )
1025
+ self ._handle_duplicate_option (sectname , optname , fpname , lineno )
1028
1026
elements_added .add ((sectname , optname ))
1029
1027
# This check is fine because the OPTCRE cannot
1030
1028
# match if it would set optval to None
@@ -1045,6 +1043,14 @@ def _read(self, fp, fpname):
1045
1043
if e :
1046
1044
raise e
1047
1045
1046
+ def _handle_duplicate_option (self , sectname , optname , fpname , lineno ):
1047
+ """Handle duplicate option definition. Override for custom behavior."""
1048
+ raise DuplicateOptionError (sectname , optname , fpname , lineno )
1049
+
1050
+ def _handle_duplicate_section (self , sectname , fpname , lineno ):
1051
+ """Handle duplicate section definition. Override for custom behavior."""
1052
+ raise DuplicateSectionError (sectname , fpname , lineno )
1053
+
1048
1054
def _join_multiline_values (self ):
1049
1055
defaults = self .default_section , self ._defaults
1050
1056
all_sections = itertools .chain ((defaults ,),
0 commit comments