[Python-checkins] CVS: python/dist/src/Tools/idle PyParse.py,1.6,1.7

Tim Peters python-dev@python.org
Fri, 6 Oct 2000 16:09:03 -0700


Update of /cvsroot/python/python/dist/src/Tools/idle
In directory slayer.i.sourceforge.net:/tmp/cvs-serv26651/python/dist/src/tools/idle

Modified Files:
	PyParse.py 
Log Message:
Fix for next iteration of SF bug 115690 (Unicode headaches in IDLE).  The
parsing functions in support of auto-indent weren't expecting Unicode
strings, but text.get() can now return them (although it remains muddy as
to exactly when or why that can happen).  Fixed that with a Big Hammer.


Index: PyParse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/idle/PyParse.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** PyParse.py	2000/03/13 14:50:24	1.6
--- PyParse.py	2000/10/06 23:09:00	1.7
***************
*** 114,117 ****
--- 114,130 ----
      def set_str(self, str):
          assert len(str) == 0 or str[-1] == '\n'
+         if type(str) == type(u""):
+             # The parse functions have no idea what to do with Unicode, so
+             # replace all Unicode characters with "x".  This is "safe"
+             # so long as the only characters germane to parsing the structure
+             # of Python are 7-bit ASCII.  It's *necessary* because Unicode
+             # strings don't have a .translate() method that supports
+             # deletechars.
+             uniphooey = str
+             str = []
+             push = str.append
+             for raw in map(ord, uniphooey):
+                 push(raw < 127 and chr(raw) or "x")
+             str = "".join(str)
          self.str = str
          self.study_level = 0