]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
backport gvanrossum's patch:
authorAnthony Baxter <anthonybaxter@gmail.com>
Thu, 18 Apr 2002 05:08:28 +0000 (05:08 +0000)
committerAnthony Baxter <anthonybaxter@gmail.com>
Thu, 18 Apr 2002 05:08:28 +0000 (05:08 +0000)
commit1b2f63d2a74f5c6daef021000bc5a03ccb79d7e3
tree15a74e872010539e3d58cc7b94752acba95da386
parent0e654222e74eac29b8a6d0983d72bee841de161e
backport gvanrossum's patch:

Provisional fix for writefile() [SF bug # 541730].

The problem was that an exception can occur in the text.get() call or
in the write() call, when the text buffer contains non-ASCII
characters.  This causes the previous contents of the file to be lost.

The provisional fix is to call str(self.text.get(...)) *before*
opening the file, so that if the exception occurs, we never open the
file.

Two orthogonal better solutions have to wait for policy decisions:

1. We could try to encode the data as Latin-1 or as UTF-8; but that
   would require IDLE to grow a notion of file encoding which requires
   more thought.

2. We could make backups before overwriting a file.  This requires
   more thought because it needs to be fast and cross-platform and
   configurable.

Original patches were:
python/dist/src/Tools/idle/IOBinding.py:1.6
Tools/idle/IOBinding.py