[Idle-dev] CVS: idle PyParse.py,1.2,1.3

Kurt B. Kaiser kbk@users.sourceforge.net
Fri, 13 Jul 2001 13:33:48 -0700


Update of /cvsroot/idlefork/idle
In directory usw-pr-cvs1:/tmp/cvs-serv794

Modified Files:
	PyParse.py 
Log Message:
py-cvs-rel2_1 (Rev 1.6 - 1.8) merge
Fix autoindent bug and deflect Unicode from text.get()


Index: PyParse.py
===================================================================
RCS file: /cvsroot/idlefork/idle/PyParse.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** PyParse.py	2001/07/04 03:15:10	1.2
--- PyParse.py	2001/07/13 20:33:46	1.3
***************
*** 106,109 ****
--- 106,114 ----
  del ch
  
+ try:
+     UnicodeType = type(unicode(""))
+ except NameError:
+     UnicodeType = None
+ 
  class Parser:
  
***************
*** 114,117 ****
--- 119,135 ----
      def set_str(self, str):
          assert len(str) == 0 or str[-1] == '\n'
+         if type(str) is UnicodeType:
+             # 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
***************
*** 386,396 ****
              if m:
                  # we skipped at least one boring char
!                 p = m.end()
                  # back up over totally boring whitespace
!                 i = p-1    # index of last boring char
!                 while i >= 0 and str[i] in " \t\n":
                      i = i-1
!                 if i >= 0:
                      lastch = str[i]
                  if p >= q:
                      break
--- 404,415 ----
              if m:
                  # we skipped at least one boring char
!                 newp = m.end()
                  # back up over totally boring whitespace
!                 i = newp - 1    # index of last boring char
!                 while i >= p and str[i] in " \t\n":
                      i = i-1
!                 if i >= p:
                      lastch = str[i]
+                 p = newp
                  if p >= q:
                      break