Skip to content

Commit 94002b4

Browse files
committed
Reindent
1 parent 762b8b0 commit 94002b4

File tree

1 file changed

+49
-49
lines changed

1 file changed

+49
-49
lines changed

Lib/configparser.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,29 @@ def _handle_rest(self, st, line, fpname):
10961096
self._handle_header(st, mo, fpname) if mo else self._handle_option(st, line, fpname)
10971097

10981098
def _handle_header(self, st, mo, fpname):
1099+
st.sectname = mo.group('header')
1100+
if st.sectname in self._sections:
1101+
if self._strict and st.sectname in st.elements_added:
1102+
raise DuplicateSectionError(st.sectname, fpname,
1103+
st.lineno)
1104+
st.cursect = self._sections[st.sectname]
1105+
st.elements_added.add(st.sectname)
1106+
elif st.sectname == self.default_section:
1107+
st.cursect = self._defaults
1108+
else:
1109+
st.cursect = self._dict()
1110+
self._sections[st.sectname] = st.cursect
1111+
self._proxies[st.sectname] = SectionProxy(self, st.sectname)
1112+
st.elements_added.add(st.sectname)
1113+
# So sections can't start with a continuation line
1114+
st.optname = None
1115+
1116+
def _handle_option(self, st, line, fpname):
1117+
# an option line?
1118+
st.indent_level = st.cur_indent_level
1119+
# is it a section header?
1120+
mo = self.SECTCRE.match(line.clean)
1121+
if mo:
10991122
st.sectname = mo.group('header')
11001123
if st.sectname in self._sections:
11011124
if self._strict and st.sectname in st.elements_added:
@@ -1112,59 +1135,36 @@ def _handle_header(self, st, mo, fpname):
11121135
st.elements_added.add(st.sectname)
11131136
# So sections can't start with a continuation line
11141137
st.optname = None
1115-
1116-
def _handle_option(self, st, line, fpname):
1138+
# no section header in the file?
1139+
elif st.cursect is None:
1140+
raise MissingSectionHeaderError(fpname, st.lineno, line)
11171141
# an option line?
1118-
st.indent_level = st.cur_indent_level
1119-
# is it a section header?
1120-
mo = self.SECTCRE.match(line.clean)
1142+
else:
1143+
mo = self._optcre.match(line.clean)
11211144
if mo:
1122-
st.sectname = mo.group('header')
1123-
if st.sectname in self._sections:
1124-
if self._strict and st.sectname in st.elements_added:
1125-
raise DuplicateSectionError(st.sectname, fpname,
1126-
st.lineno)
1127-
st.cursect = self._sections[st.sectname]
1128-
st.elements_added.add(st.sectname)
1129-
elif st.sectname == self.default_section:
1130-
st.cursect = self._defaults
1145+
st.optname, vi, optval = mo.group('option', 'vi', 'value')
1146+
if not st.optname:
1147+
st.errors.append(ParsingError(fpname, st.lineno, line))
1148+
st.optname = self.optionxform(st.optname.rstrip())
1149+
if (self._strict and
1150+
(st.sectname, st.optname) in st.elements_added):
1151+
raise DuplicateOptionError(st.sectname, st.optname,
1152+
fpname, st.lineno)
1153+
st.elements_added.add((st.sectname, st.optname))
1154+
# This check is fine because the OPTCRE cannot
1155+
# match if it would set optval to None
1156+
if optval is not None:
1157+
optval = optval.strip()
1158+
st.cursect[st.optname] = [optval]
11311159
else:
1132-
st.cursect = self._dict()
1133-
self._sections[st.sectname] = st.cursect
1134-
self._proxies[st.sectname] = SectionProxy(self, st.sectname)
1135-
st.elements_added.add(st.sectname)
1136-
# So sections can't start with a continuation line
1137-
st.optname = None
1138-
# no section header in the file?
1139-
elif st.cursect is None:
1140-
raise MissingSectionHeaderError(fpname, st.lineno, line)
1141-
# an option line?
1160+
# valueless option handling
1161+
st.cursect[st.optname] = None
11421162
else:
1143-
mo = self._optcre.match(line.clean)
1144-
if mo:
1145-
st.optname, vi, optval = mo.group('option', 'vi', 'value')
1146-
if not st.optname:
1147-
st.errors.append(ParsingError(fpname, st.lineno, line))
1148-
st.optname = self.optionxform(st.optname.rstrip())
1149-
if (self._strict and
1150-
(st.sectname, st.optname) in st.elements_added):
1151-
raise DuplicateOptionError(st.sectname, st.optname,
1152-
fpname, st.lineno)
1153-
st.elements_added.add((st.sectname, st.optname))
1154-
# This check is fine because the OPTCRE cannot
1155-
# match if it would set optval to None
1156-
if optval is not None:
1157-
optval = optval.strip()
1158-
st.cursect[st.optname] = [optval]
1159-
else:
1160-
# valueless option handling
1161-
st.cursect[st.optname] = None
1162-
else:
1163-
# a non-fatal parsing error occurred. set up the
1164-
# exception but keep going. the exception will be
1165-
# raised at the end of the file and will contain a
1166-
# list of all bogus lines
1167-
st.errors.append(ParsingError(fpname, st.lineno, line))
1163+
# a non-fatal parsing error occurred. set up the
1164+
# exception but keep going. the exception will be
1165+
# raised at the end of the file and will contain a
1166+
# list of all bogus lines
1167+
st.errors.append(ParsingError(fpname, st.lineno, line))
11681168

11691169
def _join_multiline_values(self):
11701170
defaults = self.default_section, self._defaults

0 commit comments

Comments
 (0)