summaryrefslogtreecommitdiff
path: root/configobj.py
diff options
context:
space:
mode:
authorfuzzyman <devnull@localhost>2010-02-27 21:38:07 +0000
committerfuzzyman <devnull@localhost>2010-02-27 21:38:07 +0000
commit20c75063e4e0d3e3441b5b65d4c14ab63016b672 (patch)
treedab8b1fcc9eb71a558d5d713b4145d5203a0ee4a /configobj.py
parent3ae5465a3129213d97b53a5eca5bf79c07033b57 (diff)
downloadconfigobj-git-20c75063e4e0d3e3441b5b65d4c14ab63016b672.tar.gz
Fix to avoid writing invalid newlines on Windows.
Diffstat (limited to 'configobj.py')
-rw-r--r--configobj.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/configobj.py b/configobj.py
index 7e3adee..c1f6e6d 100644
--- a/configobj.py
+++ b/configobj.py
@@ -2015,6 +2015,8 @@ class ConfigObj(Section):
>>> a.filename = filename
>>> a == ConfigObj('test.ini', raise_errors=True)
1
+ >>> import os
+ >>> os.remove('test.ini')
"""
if self.indent_type is None:
# this can be true if initialised from a dictionary
@@ -2090,6 +2092,10 @@ class ConfigObj(Section):
# Turn the list to a string, joined with correct newlines
newline = self.newlines or os.linesep
+ if (getattr(outfile, 'mode', None) is not None and outfile.mode == 'w'
+ and sys.platform == 'win32' and newline == '\r\n'):
+ # Windows specific hack to avoid writing '\r\r\n'
+ newline = '\n'
output = self._a_to_u(newline).join(out)
if self.encoding:
output = output.encode(self.encoding)