Update of /cvsroot/pywin32/pywin32/Pythonwin/pywin/idle
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8819/idle
Modified Files:
AutoExpand.py AutoIndent.py CallTips.py FormatParagraph.py
IdleHistory.py PyParse.py
Log Message:
Replace use of string module with string methods
Index: FormatParagraph.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/idle/FormatParagraph.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FormatParagraph.py 13 Aug 2000 13:20:20 -0000 1.1
--- FormatParagraph.py 9 Aug 2008 16:47:07 -0000 1.2
***************
*** 51,62 ****
if comment_header:
# Reformat the comment lines - convert to text sans header.
! lines = string.split(data, "\n")
lines = map(lambda st, l=len(comment_header): st[l:], lines)
! data = string.join(lines, "\n")
# Reformat to 70 chars or a 20 char width, whichever is greater.
format_width = max(70-len(comment_header), 20)
newdata = reformat_paragraph(data, format_width)
# re-split and re-insert the comment header.
! newdata = string.split(newdata, "\n")
# If the block ends in a \n, we dont want the comment
# prefix inserted after it. (Im not sure it makes sense to
--- 51,62 ----
if comment_header:
# Reformat the comment lines - convert to text sans header.
! lines = data.split("\n")
lines = map(lambda st, l=len(comment_header): st[l:], lines)
! data = "\n".join(lines)
# Reformat to 70 chars or a 20 char width, whichever is greater.
format_width = max(70-len(comment_header), 20)
newdata = reformat_paragraph(data, format_width)
# re-split and re-insert the comment header.
! newdata = newdata.split("\n")
# If the block ends in a \n, we dont want the comment
# prefix inserted after it. (Im not sure it makes sense to
***************
*** 69,73 ****
newdata = newdata[:-1]
builder = lambda item, prefix=comment_header: prefix+item
! newdata = string.join(map(builder, newdata), '\n') + block_suffix
else:
# Just a normal text format
--- 69,73 ----
newdata = newdata[:-1]
builder = lambda item, prefix=comment_header: prefix+item
! newdata = '\n'.join([builder(d) for d in newdata]) + block_suffix
else:
# Just a normal text format
***************
*** 85,89 ****
def find_paragraph(text, mark):
! lineno, col = map(int, string.split(mark, "."))
line = text.get("%d.0" % lineno, "%d.0 lineend" % lineno)
while text.compare("%d.0" % lineno, "<", "end") and is_all_white(line):
--- 85,89 ----
def find_paragraph(text, mark):
! lineno, col = list(map(int, mark.split(".")))
line = text.get("%d.0" % lineno, "%d.0 lineend" % lineno)
while text.compare("%d.0" % lineno, "<", "end") and is_all_white(line):
***************
*** 110,114 ****
def reformat_paragraph(data, limit=70):
! lines = string.split(data, "\n")
i = 0
n = len(lines)
--- 110,114 ----
def reformat_paragraph(data, limit=70):
! lines = data.split("\n")
i = 0
n = len(lines)
***************
*** 131,137 ****
if not word:
continue # Can happen when line ends in whitespace
! if len(string.expandtabs(partial + word)) > limit and \
partial != indent1:
! new.append(string.rstrip(partial))
partial = indent2
partial = partial + word + " "
--- 131,137 ----
if not word:
continue # Can happen when line ends in whitespace
! if len((partial + word).expandtabs()) > limit and \
partial != indent1:
! new.append(partial.rstrip())
partial = indent2
partial = partial + word + " "
***************
*** 139,146 ****
partial = partial + " "
i = i+1
! new.append(string.rstrip(partial))
# XXX Should reformat remaining paragraphs as well
new.extend(lines[i:])
! return string.join(new, "\n")
def is_all_white(line):
--- 139,146 ----
partial = partial + " "
i = i+1
! new.append(partial.rstrip())
# XXX Should reformat remaining paragraphs as well
new.extend(lines[i:])
! return "\n".join(new)
def is_all_white(line):
Index: AutoExpand.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/idle/AutoExpand.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AutoExpand.py 1 Sep 1999 23:33:51 -0000 1.1
--- AutoExpand.py 9 Aug 2008 16:47:07 -0000 1.2
***************
*** 22,26 ****
]
! wordchars = string.letters + string.digits + "_"
def __init__(self, editwin):
--- 22,26 ----
]
! wordchars = string.ascii_letters + string.digits + "_"
def __init__(self, editwin):
Index: CallTips.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/idle/CallTips.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CallTips.py 22 Feb 2008 04:05:26 -0000 1.2
--- CallTips.py 9 Aug 2008 16:47:07 -0000 1.3
***************
*** 77,81 ****
def get_object_at_cursor(self,
! wordchars="._" + string.uppercase + string.lowercase + string.digits):
# XXX - This needs to be moved to a better place
# so the "." attribute lookup code can also use it.
--- 77,81 ----
def get_object_at_cursor(self,
! wordchars="._" + string.ascii_uppercase + string.ascii_lowercase + string.digits):
# XXX - This needs to be moved to a better place
# so the "." attribute lookup code can also use it.
***************
*** 139,143 ****
if fob.func_code.co_flags & 0x8:
items.append("***")
! argText = string.join(items , ", ")
argText = "(%s)" % argText
except:
--- 139,143 ----
if fob.func_code.co_flags & 0x8:
items.append("***")
! argText = ", ".join(items)
argText = "(%s)" % argText
except:
Index: AutoIndent.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/idle/AutoIndent.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** AutoIndent.py 27 Feb 2006 11:07:09 -0000 1.2
--- AutoIndent.py 9 Aug 2008 16:47:07 -0000 1.3
***************
*** 1,3 ****
- import string
#from Tkinter import TclError
#import tkMessageBox
--- 1,2 ----
***************
*** 169,174 ****
# Ick. It may require *inserting* spaces if we back up over a
# tab character! This is written to be clear, not fast.
! expand, tabwidth = string.expandtabs, self.tabwidth
! have = len(expand(chars, tabwidth))
assert have > 0
want = int((have - 1) / self.indentwidth) * self.indentwidth
--- 168,172 ----
# Ick. It may require *inserting* spaces if we back up over a
# tab character! This is written to be clear, not fast.
! have = len(chars.expandtabs(self.tabwidth))
assert have > 0
want = int((have - 1) / self.indentwidth) * self.indentwidth
***************
*** 177,181 ****
chars = chars[:-1]
ncharsdeleted = ncharsdeleted + 1
! have = len(expand(chars, tabwidth))
if have <= want or chars[-1] not in " \t":
break
--- 175,179 ----
chars = chars[:-1]
ncharsdeleted = ncharsdeleted + 1
! have = len(chars.expandtabs(self.tabwidth))
if have <= want or chars[-1] not in " \t":
break
***************
*** 211,216 ****
pad = '\t'
else:
! effective = len(string.expandtabs(prefix,
! self.tabwidth))
n = self.indentwidth
pad = ' ' * (n - effective % n)
--- 209,213 ----
pad = '\t'
else:
! effective = len(prefix.expandtabs(self.tabwidth))
n = self.indentwidth
pad = ' ' * (n - effective % n)
***************
*** 377,381 ****
tabwidth = self._asktabwidth()
for pos in range(len(lines)):
! lines[pos] = string.expandtabs(lines[pos], tabwidth)
self.set_region(head, tail, chars, lines)
--- 374,378 ----
tabwidth = self._asktabwidth()
for pos in range(len(lines)):
! lines[pos] = lines[pos].expandtabs(tabwidth)
self.set_region(head, tail, chars, lines)
***************
*** 418,427 ****
tail = text.index("insert lineend +1c")
chars = text.get(head, tail)
! lines = string.split(chars, "\n")
return head, tail, chars, lines
def set_region(self, head, tail, chars, lines):
text = self.text
! newchars = string.join(lines, "\n")
if newchars == chars:
text.bell()
--- 415,424 ----
tail = text.index("insert lineend +1c")
chars = text.get(head, tail)
! lines = chars.split("\n")
return head, tail, chars, lines
def set_region(self, head, tail, chars, lines):
text = self.text
! newchars = "\n".join(lines)
if newchars == chars:
text.bell()
Index: PyParse.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/idle/PyParse.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** PyParse.py 2 Jun 2002 00:28:00 -0000 1.4
--- PyParse.py 9 Aug 2008 16:47:07 -0000 1.5
***************
*** 13,17 ****
if 0: # for throwaway debugging output
def dump(*stuff):
! sys.__stdout__.write(string.join(map(str, stuff), " ") + "\n")
# Find what looks like the start of a popular stmt.
--- 13,17 ----
if 0: # for throwaway debugging output
def dump(*stuff):
! sys.__stdout__.write(" ".join(map(str, stuff)) + "\n")
# Find what looks like the start of a popular stmt.
***************
*** 108,112 ****
for ch in "\"'\\\n#":
_tran[ord(ch)] = ch
! _tran = string.join(_tran, '')
del ch
--- 108,112 ----
for ch in "\"'\\\n#":
_tran[ord(ch)] = ch
! _tran = ''.join(_tran)
del ch
***************
*** 152,163 ****
# 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)
if i >= 0:
pos = i + len(ps1)
--- 152,161 ----
# Python 1.5.2 (#0, Apr 13 1999, ...
! def find_good_parse_start(self, use_ps1, is_char_in_string=None):
str, pos = self.str, None
if use_ps1:
# shell window
ps1 = '\n' + sys.ps1
! i = str.rfind(ps1)
if i >= 0:
pos = i + len(ps1)
***************
*** 178,185 ****
limit = len(str)
for tries in range(5):
! i = _rfind(str, ":\n", 0, limit)
if i < 0:
break
! i = _rfind(str, '\n', 0, i) + 1 # start of colon line
m = _synchre(str, i, limit)
if m and not is_char_in_string(m.start()):
--- 176,183 ----
limit = len(str)
for tries in range(5):
! i = str.rfind(":\n", 0, limit)
if i < 0:
break
! 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()):
***************
*** 226,230 ****
# Creates self.{goodlines, continuation}.
! def _study1(self, _replace=string.replace, _find=string.find):
if self.study_level >= 1:
return
--- 224,228 ----
# Creates self.{goodlines, continuation}.
! def _study1(self):
if self.study_level >= 1:
return
***************
*** 236,245 ****
# 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')
# note that replacing x\n with \n would be incorrect, because
# x may be preceded by a backslash
--- 234,243 ----
# by a factor of 10-40, and so greatly speed the following loop.
str = self.str
! 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,326 ****
if ch == '#':
# consume the comment
! i = _find(str, '\n', i)
assert i >= 0
continue
--- 320,324 ----
if ch == '#':
# consume the comment
! i = str.find('\n', i)
assert i >= 0
continue
***************
*** 363,368 ****
# if continuation is C_BRACKET, index of last open bracket
! def _study2(self, _rfind=string.rfind, _find=string.find,
! _ws=string.whitespace):
if self.study_level >= 2:
return
--- 361,366 ----
# if continuation is C_BRACKET, index of last open bracket
! def _study2(self):
! _ws=string.whitespace
if self.study_level >= 2:
return
***************
*** 381,385 ****
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
# The stmt str[p:q] isn't a continuation, but may be blank
# or a non-indenting comment line.
--- 379,383 ----
for nothing in range(goodlines[i-1], goodlines[i]):
# tricky: sets p to 0 if no preceding newline
! 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.
***************
*** 444,448 ****
if ch == '#':
# consume comment and trailing newline
! p = _find(str, '\n', p, q) + 1
assert p > 0
continue
--- 442,446 ----
if ch == '#':
# consume comment and trailing newline
! p = str.find('\n', p, q) + 1
assert p > 0
continue
***************
*** 465,469 ****
# of spaces the next line should be indented.
! def compute_bracket_indent(self, _find=string.find):
self._study2()
assert self.continuation == C_BRACKET
--- 463,467 ----
# of spaces the next line should be indented.
! def compute_bracket_indent(self):
self._study2()
assert self.continuation == C_BRACKET
***************
*** 471,475 ****
str = self.str
n = len(str)
! origi = i = string.rfind(str, '\n', 0, j) + 1
j = j+1 # one beyond open bracket
# find first list item; set i to start of its line
--- 469,473 ----
str = self.str
n = len(str)
! 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
***************
*** 482,486 ****
else:
# this line is junk; advance to next line
! i = j = _find(str, '\n', j) + 1
else:
# nothing interesting follows the bracket;
--- 480,484 ----
else:
# this line is junk; advance to next line
! i = j = str.find('\n', j) + 1
else:
# nothing interesting follows the bracket;
***************
*** 490,495 ****
j = j+1
extra = self.indentwidth
! return len(string.expandtabs(str[i:j],
! self.tabwidth)) + extra
# Return number of physical lines in last stmt (whether or not
--- 488,492 ----
j = j+1
extra = self.indentwidth
! return len(str[i:j].expandtabs(self.tabwidth)) + extra
# Return number of physical lines in last stmt (whether or not
***************
*** 517,521 ****
# See whether the initial line starts an assignment stmt; i.e.,
# look for an = operator
! endpos = string.find(str, '\n', startpos) + 1
found = level = 0
while i < endpos:
--- 514,518 ----
# See whether the initial line starts an assignment stmt; i.e.,
# look for an = operator
! endpos = str.find('\n', startpos) + 1
found = level = 0
while i < endpos:
***************
*** 553,559 ****
i = i+1
! return len(string.expandtabs(str[self.stmt_start :
! i],
! self.tabwidth)) + 1
# Return the leading whitespace on the initial line of the last
--- 550,554 ----
i = i+1
! return len(str[self.stmt_start : i].expandtabs(self.tabwidth)) + 1
# Return the leading whitespace on the initial line of the last
Index: IdleHistory.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/idle/IdleHistory.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** IdleHistory.py 13 Aug 2000 13:20:20 -0000 1.1
--- IdleHistory.py 9 Aug 2008 16:47:07 -0000 1.2
***************
*** 23,31 ****
# Get source code from start index to end index. Lines in the
# text control may be separated by sys.ps2 .
! lines = string.split(self.text.get(start, end), self.output_sep)
! return string.join(lines, "\n")
def _put_source(self, where, source):
! output = string.join(string.split(source, "\n"), self.output_sep)
self.text.insert(where, output)
--- 23,31 ----
# Get source code from start index to end index. Lines in the
# text control may be separated by sys.ps2 .
! lines = self.text.get(start, end).split(self.output_sep)
! return "\n".join(lines)
def _put_source(self, where, source):
! output = self.output_sep.join(source.split("\n"))
self.text.insert(where, output)
***************
*** 69,73 ****
def history_store(self, source):
! source = string.strip(source)
if len(source) > 2:
# avoid duplicates
--- 69,73 ----
def history_store(self, source):
! source = source.strip()
if len(source) > 2:
# avoid duplicates
***************
*** 81,85 ****
def recall(self, s):
! s = string.strip(s)
self.text.tag_remove("sel", "1.0", "end")
self.text.delete("iomark", "end-1c")
--- 81,85 ----
def recall(self, s):
! s = s.strip()
self.text.tag_remove("sel", "1.0", "end")
self.text.delete("iomark", "end-1c")
|