Author jiangjinhu666
Recipients jiangjinhu666, r.david.murray
Date 2018-01-17.14:27:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1516199262.4.0.467229070634.issue32581@psf.upfronthosting.co.za>
In-reply-to
Content
The configure file "test.ini":

[section_a]
addr = "127.0.0.1"
password = ""

Change the value of addr by the "test.py":

import ConfigParser

tmpfile = "test.ini"
conf = ConfigParser.ConfigParser()
conf.read(tmpfile)
conf.set("section_a", "addr", "\"127.0.0.2\"")
cfgfile = open(tmpfile, 'w')
conf.write(cfgfile) 

After change the value of addr to 127.0.0.2,the test.ini will be:

[section_a]
addr = "127.0.0.2"
password = 

The "" of the password lost!

And one method which will fix this bug of the write function of the ConfigParder.py:

    def write(self, fp):
        """Write an .ini-format representation of the configuration state."""
        if self._defaults:
            fp.write("[%s]\n" % DEFAULTSECT)
            for (key, value) in self._defaults.items():
                fp.write("%s = %s\n" % (key, str(value).replace('\n', '\n\t')))
            fp.write("\n")
        for section in self._sections:
            fp.write("[%s]\n" % section)
            for (key, value) in self._sections[section].items():
                if key == "__name__":
                    continue
                if (value is not None) or (self._optcre == self.OPTCRE):
                    if value == "":    #
                        value = "\"\""  #
                        key = " = ".join((key, str(value).replace('\n', '\n\t')))#
                    else:                                         #
                        key = " = ".join((key, str(value).replace('\n', '\n\t')))

    
                fp.write("%s\n" % (key))
            fp.write("\n") 


Please check it.
Thanks!
History
Date User Action Args
2018-01-17 14:27:42jiangjinhu666setrecipients: + jiangjinhu666, r.david.murray
2018-01-17 14:27:42jiangjinhu666setmessageid: <1516199262.4.0.467229070634.issue32581@psf.upfronthosting.co.za>
2018-01-17 14:27:42jiangjinhu666linkissue32581 messages
2018-01-17 14:27:42jiangjinhu666create