Kaydet (Commit) ec3bbdef authored tarafından Eric S. Raymond's avatar Eric S. Raymond

String method conversion.

üst 92852ad9
...@@ -7,7 +7,6 @@ MimeWriter - the only thing here. ...@@ -7,7 +7,6 @@ MimeWriter - the only thing here.
""" """
import string
import mimetools import mimetools
__all__ = ["MimeWriter"] __all__ = ["MimeWriter"]
...@@ -87,12 +86,12 @@ class MimeWriter: ...@@ -87,12 +86,12 @@ class MimeWriter:
self._headers = [] self._headers = []
def addheader(self, key, value, prefix=0): def addheader(self, key, value, prefix=0):
lines = string.splitfields(value, "\n") lines = value.split("\n")
while lines and not lines[-1]: del lines[-1] while lines and not lines[-1]: del lines[-1]
while lines and not lines[0]: del lines[0] while lines and not lines[0]: del lines[0]
for i in range(1, len(lines)): for i in range(1, len(lines)):
lines[i] = " " + string.strip(lines[i]) lines[i] = " " + lines[i].strip()
value = string.joinfields(lines, "\n") + "\n" value = "\n".join(lines) + "\n"
line = key + ": " + value line = key + ": " + value
if prefix: if prefix:
self._headers.insert(0, line) self._headers.insert(0, line)
......
...@@ -229,7 +229,7 @@ def escape(pattern): ...@@ -229,7 +229,7 @@ def escape(pattern):
if char not in alphanum: if char not in alphanum:
if char=='\000': result[i] = '\\000' if char=='\000': result[i] = '\\000'
else: result[i] = '\\'+char else: result[i] = '\\'+char
return string.join(result, '') return ''.join(result)
def compile(pattern, flags=0): def compile(pattern, flags=0):
"""compile(pattern[, flags]) -> RegexObject """compile(pattern[, flags]) -> RegexObject
...@@ -398,7 +398,7 @@ class RegexObject: ...@@ -398,7 +398,7 @@ class RegexObject:
append(source[lastmatch:pos]) append(source[lastmatch:pos])
n = n + 1 n = n + 1
append(source[pos:]) append(source[pos:])
return (string.join(results, ''), n) return (''.join(results), n)
def split(self, source, maxsplit=0): def split(self, source, maxsplit=0):
"""split(source[, maxsplit=0]) -> list of strings """split(source[, maxsplit=0]) -> list of strings
......
...@@ -160,11 +160,11 @@ def readmodule_ex(module, path=[], inpackage=0): ...@@ -160,11 +160,11 @@ def readmodule_ex(module, path=[], inpackage=0):
dict = {} dict = {}
i = string.rfind(module, '.') i = module.rfind('.')
if i >= 0: if i >= 0:
# Dotted module name # Dotted module name
package = string.strip(module[:i]) package = module[:i].strip()
submodule = string.strip(module[i+1:]) submodule = module[i+1:].strip()
parent = readmodule(package, path, inpackage) parent = readmodule(package, path, inpackage)
child = readmodule(submodule, parent['__path__'], 1) child = readmodule(submodule, parent['__path__'], 1)
return child return child
...@@ -260,15 +260,15 @@ def readmodule_ex(module, path=[], inpackage=0): ...@@ -260,15 +260,15 @@ def readmodule_ex(module, path=[], inpackage=0):
inherit = m.group("ClassSupers") inherit = m.group("ClassSupers")
if inherit: if inherit:
# the class inherits from other classes # the class inherits from other classes
inherit = string.strip(inherit[1:-1]) inherit = inherit[1:-1].strip()
names = [] names = []
for n in string.splitfields(inherit, ','): for n in inherit.split(','):
n = string.strip(n) n = n.strip()
if dict.has_key(n): if dict.has_key(n):
# we know this super class # we know this super class
n = dict[n] n = dict[n]
else: else:
c = string.splitfields(n, '.') c = n.split('.')
if len(c) > 1: if len(c) > 1:
# super class # super class
# is of the # is of the
...@@ -291,8 +291,8 @@ def readmodule_ex(module, path=[], inpackage=0): ...@@ -291,8 +291,8 @@ def readmodule_ex(module, path=[], inpackage=0):
elif m.start("Import") >= 0: elif m.start("Import") >= 0:
# import module # import module
for n in string.split(m.group("ImportList"), ','): for n in m.group("ImportList").split(','):
n = string.strip(n) n = n.strip()
try: try:
# recursively read the imported module # recursively read the imported module
d = readmodule(n, path, inpackage) d = readmodule(n, path, inpackage)
...@@ -303,7 +303,7 @@ def readmodule_ex(module, path=[], inpackage=0): ...@@ -303,7 +303,7 @@ def readmodule_ex(module, path=[], inpackage=0):
elif m.start("ImportFrom") >= 0: elif m.start("ImportFrom") >= 0:
# from module import stuff # from module import stuff
mod = m.group("ImportFromPath") mod = m.group("ImportFromPath")
names = string.split(m.group("ImportFromList"), ',') names = m.group("ImportFromList").split(',')
try: try:
# recursively read the imported module # recursively read the imported module
d = readmodule(mod, path, inpackage) d = readmodule(mod, path, inpackage)
...@@ -314,7 +314,7 @@ def readmodule_ex(module, path=[], inpackage=0): ...@@ -314,7 +314,7 @@ def readmodule_ex(module, path=[], inpackage=0):
# imported module to our name space if they # imported module to our name space if they
# were mentioned in the list # were mentioned in the list
for n in names: for n in names:
n = string.strip(n) n = n.strip()
if d.has_key(n): if d.has_key(n):
dict[n] = d[n] dict[n] = d[n]
elif n == '*': elif n == '*':
...@@ -334,3 +334,4 @@ def readmodule_ex(module, path=[], inpackage=0): ...@@ -334,3 +334,4 @@ def readmodule_ex(module, path=[], inpackage=0):
def _indent(ws, _expandtabs=string.expandtabs): def _indent(ws, _expandtabs=string.expandtabs):
return len(_expandtabs(ws, TABWIDTH)) return len(_expandtabs(ws, TABWIDTH))
...@@ -18,7 +18,7 @@ def print_list(extracted_list, file=None): ...@@ -18,7 +18,7 @@ def print_list(extracted_list, file=None):
_print(file, _print(file,
' File "%s", line %d, in %s' % (filename,lineno,name)) ' File "%s", line %d, in %s' % (filename,lineno,name))
if line: if line:
_print(file, ' %s' % string.strip(line)) _print(file, ' %s' % line.strip())
def format_list(extracted_list): def format_list(extracted_list):
"""Given a list of tuples as returned by extract_tb() or """Given a list of tuples as returned by extract_tb() or
...@@ -31,7 +31,7 @@ def format_list(extracted_list): ...@@ -31,7 +31,7 @@ def format_list(extracted_list):
for filename, lineno, name, line in extracted_list: for filename, lineno, name, line in extracted_list:
item = ' File "%s", line %d, in %s\n' % (filename,lineno,name) item = ' File "%s", line %d, in %s\n' % (filename,lineno,name)
if line: if line:
item = item + ' %s\n' % string.strip(line) item = item + ' %s\n' % line.strip()
list.append(item) list.append(item)
return list return list
...@@ -56,7 +56,7 @@ def print_tb(tb, limit=None, file=None): ...@@ -56,7 +56,7 @@ def print_tb(tb, limit=None, file=None):
_print(file, _print(file,
' File "%s", line %d, in %s' % (filename,lineno,name)) ' File "%s", line %d, in %s' % (filename,lineno,name))
line = linecache.getline(filename, lineno) line = linecache.getline(filename, lineno)
if line: _print(file, ' ' + string.strip(line)) if line: _print(file, ' ' + line.strip())
tb = tb.tb_next tb = tb.tb_next
n = n+1 n = n+1
...@@ -85,7 +85,7 @@ def extract_tb(tb, limit = None): ...@@ -85,7 +85,7 @@ def extract_tb(tb, limit = None):
filename = co.co_filename filename = co.co_filename
name = co.co_name name = co.co_name
line = linecache.getline(filename, lineno) line = linecache.getline(filename, lineno)
if line: line = string.strip(line) if line: line = line.strip()
else: line = None else: line = None
list.append((filename, lineno, name, line)) list.append((filename, lineno, name, line))
tb = tb.tb_next tb = tb.tb_next
...@@ -157,7 +157,7 @@ def format_exception_only(etype, value): ...@@ -157,7 +157,7 @@ def format_exception_only(etype, value):
while i < len(line) and \ while i < len(line) and \
line[i] in string.whitespace: line[i] in string.whitespace:
i = i+1 i = i+1
list.append(' %s\n' % string.strip(line)) list.append(' %s\n' % line.strip())
s = ' ' s = ' '
for c in line[i:offset-1]: for c in line[i:offset-1]:
if c in string.whitespace: if c in string.whitespace:
...@@ -246,7 +246,7 @@ def extract_stack(f=None, limit = None): ...@@ -246,7 +246,7 @@ def extract_stack(f=None, limit = None):
filename = co.co_filename filename = co.co_filename
name = co.co_name name = co.co_name
line = linecache.getline(filename, lineno) line = linecache.getline(filename, lineno)
if line: line = string.strip(line) if line: line = line.strip()
else: line = None else: line = None
list.append((filename, lineno, name, line)) list.append((filename, lineno, name, line))
f = f.f_back f = f.f_back
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment