diff options
author | Kurt B. Kaiser <kbk@shore.net> | 2002-09-17 03:55:13 (GMT) |
---|---|---|
committer | Kurt B. Kaiser <kbk@shore.net> | 2002-09-17 03:55:13 (GMT) |
commit | 254eb5380f281923ed26dcaa16f9eb7a654af5a0 (patch) | |
tree | b1a60df67d0ff69b2512dc841403f4f2f6633900 /Lib | |
parent | d8e20a0e6b597419b8bbec9cd7d76f3ea5067679 (diff) | |
download | cpython-254eb5380f281923ed26dcaa16f9eb7a654af5a0.zip cpython-254eb5380f281923ed26dcaa16f9eb7a654af5a0.tar.gz cpython-254eb5380f281923ed26dcaa16f9eb7a654af5a0.tar.bz2 |
Merge Py Idle changes:
Rev 1.10 doerwalter
(string methods)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/idlelib/PyParse.py | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/Lib/idlelib/PyParse.py b/Lib/idlelib/PyParse.py index c8212b2..422a86c 100644 --- a/Lib/idlelib/PyParse.py +++ b/Lib/idlelib/PyParse.py @@ -1,4 +1,3 @@ -import string import re import sys @@ -7,7 +6,7 @@ C_NONE, C_BACKSLASH, C_STRING, C_BRACKET = range(4) if 0: # for throwaway debugging output def dump(*stuff): - sys.__stdout__.write(string.join(map(str, stuff), " ") + "\n") + sys.__stdout__.write(" ".join(map(str, stuff)) + "\n") # Find what looks like the start of a popular stmt. @@ -103,7 +102,7 @@ for ch in ")}]": _tran[ord(ch)] = ')' for ch in "\"'\\\n#": _tran[ord(ch)] = ch -_tran = string.join(_tran, '') +_tran = ''.join(_tran) del ch try: @@ -153,13 +152,12 @@ class Parser: # Python 1.5.2 (#0, Apr 13 1999, ... def find_good_parse_start(self, use_ps1, is_char_in_string=None, - _rfind=string.rfind, _synchre=_synchre): str, pos = self.str, None if use_ps1: # shell window ps1 = '\n' + sys.ps1 - i = _rfind(str, ps1) + i = str.rfind(ps1) if i >= 0: pos = i + len(ps1) # make it look like there's a newline instead @@ -178,10 +176,10 @@ class Parser: # bumped to a legitimate synch point. limit = len(str) for tries in range(5): - i = _rfind(str, ":\n", 0, limit) + i = str.rfind(":\n", 0, limit) if i < 0: break - i = _rfind(str, '\n', 0, i) + 1 # start of colon line + i = str.rfind('\n', 0, i) + 1 # start of colon line m = _synchre(str, i, limit) if m and not is_char_in_string(m.start()): pos = m.start() @@ -226,7 +224,7 @@ class Parser: # based) of the non-continuation lines. # Creates self.{goodlines, continuation}. - def _study1(self, _replace=string.replace, _find=string.find): + def _study1(self): if self.study_level >= 1: return self.study_level = 1 @@ -236,12 +234,12 @@ class Parser: # uninteresting characters. This can cut the number of chars # by a factor of 10-40, and so greatly speed the following loop. str = self.str - str = string.translate(str, _tran) - str = _replace(str, 'xxxxxxxx', 'x') - str = _replace(str, 'xxxx', 'x') - str = _replace(str, 'xx', 'x') - str = _replace(str, 'xx', 'x') - str = _replace(str, '\nx', '\n') + str = str.translate(_tran) + str = str.replace('xxxxxxxx', 'x') + str = str.replace('xxxx', 'x') + str = str.replace('xx', 'x') + str = str.replace('xx', 'x') + str = str.replace('\nx', '\n') # note that replacing x\n with \n would be incorrect, because # x may be preceded by a backslash @@ -322,7 +320,7 @@ class Parser: if ch == '#': # consume the comment - i = _find(str, '\n', i) + i = str.find('\n', i) assert i >= 0 continue @@ -363,8 +361,7 @@ class Parser: # self.lastopenbracketpos # if continuation is C_BRACKET, index of last open bracket - def _study2(self, _rfind=string.rfind, _find=string.find, - _ws=string.whitespace): + def _study2(self): if self.study_level >= 2: return self._study1() @@ -381,7 +378,7 @@ class Parser: q = p for nothing in range(goodlines[i-1], goodlines[i]): # tricky: sets p to 0 if no preceding newline - p = _rfind(str, '\n', 0, p-1) + 1 + p = str.rfind('\n', 0, p-1) + 1 # The stmt str[p:q] isn't a continuation, but may be blank # or a non-indenting comment line. if _junkre(str, p): @@ -444,7 +441,7 @@ class Parser: if ch == '#': # consume comment and trailing newline - p = _find(str, '\n', p, q) + 1 + p = str.find('\n', p, q) + 1 assert p > 0 continue @@ -465,13 +462,13 @@ class Parser: # Assuming continuation is C_BRACKET, return the number # of spaces the next line should be indented. - def compute_bracket_indent(self, _find=string.find): + def compute_bracket_indent(self): self._study2() assert self.continuation == C_BRACKET j = self.lastopenbracketpos str = self.str n = len(str) - origi = i = string.rfind(str, '\n', 0, j) + 1 + origi = i = str.rfind('\n', 0, j) + 1 j = j+1 # one beyond open bracket # find first list item; set i to start of its line while j < n: @@ -482,7 +479,7 @@ class Parser: break else: # this line is junk; advance to next line - i = j = _find(str, '\n', j) + 1 + i = j = str.find('\n', j) + 1 else: # nothing interesting follows the bracket; # reproduce the bracket line's indentation + a level @@ -490,8 +487,7 @@ class Parser: while str[j] in " \t": j = j+1 extra = self.indentwidth - return len(string.expandtabs(str[i:j], - self.tabwidth)) + extra + return len(str[i:j].expandtabs(self.tabwidth)) + extra # Return number of physical lines in last stmt (whether or not # it's an interesting stmt! this is intended to be called when @@ -517,7 +513,7 @@ class Parser: # See whether the initial line starts an assignment stmt; i.e., # look for an = operator - endpos = string.find(str, '\n', startpos) + 1 + endpos = str.find('\n', startpos) + 1 found = level = 0 while i < endpos: ch = str[i] @@ -553,8 +549,7 @@ class Parser: while str[i] not in " \t\n": i = i+1 - return len(string.expandtabs(str[self.stmt_start : - i], + return len(str[self.stmt_start:i].expandtabs(\ self.tabwidth)) + 1 # Return the leading whitespace on the initial line of the last |