aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/idlelib/PyParse.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/idlelib/PyParse.py')
-rw-r--r--Lib/idlelib/PyParse.py28
1 files changed, 12 insertions, 16 deletions
diff --git a/Lib/idlelib/PyParse.py b/Lib/idlelib/PyParse.py
index 1a9db6743ce..61a0003ce5a 100644
--- a/Lib/idlelib/PyParse.py
+++ b/Lib/idlelib/PyParse.py
@@ -94,20 +94,16 @@ _chew_ordinaryre = re.compile(r"""
# Build translation table to map uninteresting chars to "x", open
# brackets to "(", and close brackets to ")".
-_tran = ['x'] * 256
+_tran = {}
+for i in range(256):
+ _tran[i] = 'x'
for ch in "({[":
_tran[ord(ch)] = '('
for ch in ")}]":
_tran[ord(ch)] = ')'
for ch in "\"'\\\n#":
_tran[ord(ch)] = ch
-_tran = ''.join(_tran)
-del ch
-
-try:
- UnicodeType = type(unicode(""))
-except NameError:
- UnicodeType = None
+del i, ch
class Parser:
@@ -115,22 +111,22 @@ class Parser:
self.indentwidth = indentwidth
self.tabwidth = tabwidth
- def set_str(self, str):
- assert len(str) == 0 or str[-1] == '\n'
- if type(str) is UnicodeType:
+ def set_str(self, s):
+ assert len(s) == 0 or s[-1] == '\n'
+ if isinstance(s, str):
# 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
+ uniphooey = s
+ s = []
+ push = s.append
for raw in map(ord, uniphooey):
push(raw < 127 and chr(raw) or "x")
- str = "".join(str)
- self.str = str
+ s = "".join(s)
+ self.str = s
self.study_level = 0
# Return index of a good place to begin parsing, as close to the