From 03c44a30a305f4506f03bf136065984464dd3af6 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Fri, 19 Feb 2010 06:08:41 +0000 Subject: Merged revisions 78232 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78232 | fred.drake | 2010-02-19 00:24:30 -0500 (Fri, 19 Feb 2010) | 3 lines - apply patch from issue 7005 - add corresponding documentation ........ --- Lib/configparser.py | 62 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 18 deletions(-) (limited to 'Lib/configparser.py') diff --git a/Lib/configparser.py b/Lib/configparser.py index bfbe4cbe4e..d0b03f9947 100644 --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -221,10 +221,15 @@ class MissingSectionHeaderError(ParsingError): class RawConfigParser: - def __init__(self, defaults=None, dict_type=_default_dict): + def __init__(self, defaults=None, dict_type=_default_dict, + allow_no_value=False): self._dict = dict_type self._sections = self._dict() self._defaults = self._dict() + if allow_no_value: + self._optcre = self.OPTCRE_NV + else: + self._optcre = self.OPTCRE if defaults: for key, value in defaults.items(): self._defaults[self.optionxform(key)] = value @@ -372,7 +377,7 @@ class RawConfigParser: return (option in self._sections[section] or option in self._defaults) - def set(self, section, option, value): + def set(self, section, option, value=None): """Set an option.""" if not section or section == DEFAULTSECT: sectdict = self._defaults @@ -394,8 +399,11 @@ class RawConfigParser: fp.write("[%s]\n" % section) for (key, value) in self._sections[section].items(): if key != "__name__": - fp.write("%s = %s\n" % - (key, str(value).replace('\n', '\n\t'))) + if value is None: + fp.write("%s\n" % (key)) + else: + fp.write("%s = %s\n" % + (key, str(value).replace('\n', '\n\t'))) fp.write("\n") def remove_option(self, section, option): @@ -436,6 +444,15 @@ class RawConfigParser: # by any # space/tab r'(?P.*)$' # everything up to eol ) + OPTCRE_NV = re.compile( + r'(?P