Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f2fba87

Browse files
committed
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.
1 parent 0a84a33 commit f2fba87

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Tools/idle/PyParse.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ def __init__(self, indentwidth, tabwidth):
113113

114114
def set_str(self, str):
115115
assert len(str) == 0 or str[-1] == '\n'
116+
if type(str) == type(u""):
117+
# The parse functions have no idea what to do with Unicode, so
118+
# replace all Unicode characters with "x". This is "safe"
119+
# so long as the only characters germane to parsing the structure
120+
# of Python are 7-bit ASCII. It's *necessary* because Unicode
121+
# strings don't have a .translate() method that supports
122+
# deletechars.
123+
uniphooey = str
124+
str = []
125+
push = str.append
126+
for raw in map(ord, uniphooey):
127+
push(raw < 127 and chr(raw) or "x")
128+
str = "".join(str)
116129
self.str = str
117130
self.study_level = 0
118131

0 commit comments

Comments
 (0)