[issue32581] A bug of the write funtion of ConfigParser.py

2018-01-17 Thread jiangjinhu

New submission from jiangjinhu :

By the write funtion of ConfigParser.py,the partial content of the configue 
will change.

--
components: Library (Lib)
messages: 310168
nosy: jiangjinhu666
priority: normal
severity: normal
status: open
title: A bug of the write funtion of ConfigParser.py
type: behavior
versions: Python 2.7

___
Python tracker 
<https://bugs.python.org/issue32581>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32581] A bug of the write funtion of ConfigParser.py

2018-01-17 Thread jiangjinhu

jiangjinhu  added the comment:

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')))

  #  key = " = ".join((key, str(value).replace('\n', '\n\t')))

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

--

___
Python tracker 
<https://bugs.python.org/issue32581>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32581] A bug of the write funtion of ConfigParser.py

2018-01-17 Thread jiangjinhu

jiangjinhu  added the comment:

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!

--

___
Python tracker 
<https://bugs.python.org/issue32581>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32581] A bug of the write funtion of ConfigParser.py

2018-01-17 Thread jiangjinhu

jiangjinhu  added the comment:

But accidentally,with the "password = "" " in the configure files ,which are 
called by my services, the service will start successfully,and with "password = 
  ",the services can not.On the other hand ,I just set the option "addr = 
"127.0.0.1"",why the option "password = "" " will change.
Just add this.

--

___
Python tracker 
<https://bugs.python.org/issue32581>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com