[Python-checkins] python/dist/src/Tools/idle IOBinding.py,1.5,1.6

Guido van Rossum guido@python.org
Sun, 14 Apr 2002 21:25:21 -0400


I forgot to mark this one as a bugfix candidate.

> Subject: [Python-checkins] python/dist/src/Tools/idle IOBinding.py,1.5,1.6
> From: gvanrossum@sourceforge.net
> To: python-checkins@python.org
> Date: Sun, 14 Apr 2002 17:19:14 -0700
> X-Spam-Status: No, hits=-1.4 required=5.0 tests=NO_REAL_NAME,SUBJ_PYTHON_ZOPE,BODY_PYTHON_ZOPE version=2.11
> X-MailScanner: Found to be clean
> 
> Update of /cvsroot/python/python/dist/src/Tools/idle
> In directory usw-pr-cvs1:/tmp/cvs-serv24274
> 
> Modified Files:
> 	IOBinding.py 
> Log Message:
> 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.
> 
> 
> Index: IOBinding.py
> ===================================================================
> RCS file: /cvsroot/python/python/dist/src/Tools/idle/IOBinding.py,v
> retrieving revision 1.5
> retrieving revision 1.6
> diff -C2 -d -r1.5 -r1.6
> *** IOBinding.py	4 Apr 2002 22:55:58 -0000	1.5
> --- IOBinding.py	15 Apr 2002 00:19:12 -0000	1.6
> ***************
> *** 149,155 ****
>       def writefile(self, filename):
>           self.fixlastline()
>           try:
>               f = open(filename, "w")
> -             chars = self.text.get("1.0", "end-1c")
>               f.write(chars)
>               f.close()
> --- 149,155 ----
>       def writefile(self, filename):
>           self.fixlastline()
> +         chars = str(self.text.get("1.0", "end-1c"))
>           try:
>               f = open(filename, "w")
>               f.write(chars)
>               f.close()
> 
> 
> 
> 
> _______________________________________________
> Python-checkins mailing list
> Python-checkins@python.org
> http://mail.python.org/mailman/listinfo/python-checkins