Fix text/newline handling with QSaveFile.

Fixes #309.

We use io.TextIOWrapper which already handles newline converting, so we
shouldn't open the QSaveFile with QIODevice.Text in the mode, as this lead to
double-converting newlines, which in turn produced this error message on
Windows.
This commit is contained in:
Florian Bruhin 2014-12-10 10:58:55 +01:00
parent 28fe84944c
commit 0b82fdb4d8

View File

@ -162,14 +162,13 @@ def savefile_open(filename, binary=False, encoding='utf-8'):
"""Context manager to easily use a QSaveFile."""
f = QSaveFile(filename)
try:
if binary:
ok = f.open(QIODevice.WriteOnly)
new_f = PyQIODevice(f)
else:
ok = f.open(QIODevice.WriteOnly | QIODevice.Text)
new_f = io.TextIOWrapper(PyQIODevice(f), encoding=encoding)
ok = f.open(QIODevice.WriteOnly)
if not ok: # pylint: disable=used-before-assignment
raise IOError(f.errorString())
if binary:
new_f = PyQIODevice(f)
else:
new_f = io.TextIOWrapper(PyQIODevice(f), encoding=encoding)
yield new_f
except:
f.cancelWriting()