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:
parent
28fe84944c
commit
0b82fdb4d8
@ -162,14 +162,13 @@ def savefile_open(filename, binary=False, encoding='utf-8'):
|
|||||||
"""Context manager to easily use a QSaveFile."""
|
"""Context manager to easily use a QSaveFile."""
|
||||||
f = QSaveFile(filename)
|
f = QSaveFile(filename)
|
||||||
try:
|
try:
|
||||||
if binary:
|
ok = f.open(QIODevice.WriteOnly)
|
||||||
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)
|
|
||||||
if not ok: # pylint: disable=used-before-assignment
|
if not ok: # pylint: disable=used-before-assignment
|
||||||
raise IOError(f.errorString())
|
raise IOError(f.errorString())
|
||||||
|
if binary:
|
||||||
|
new_f = PyQIODevice(f)
|
||||||
|
else:
|
||||||
|
new_f = io.TextIOWrapper(PyQIODevice(f), encoding=encoding)
|
||||||
yield new_f
|
yield new_f
|
||||||
except:
|
except:
|
||||||
f.cancelWriting()
|
f.cancelWriting()
|
||||||
|
Loading…
Reference in New Issue
Block a user