diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2007-04-17 08:48:32 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2007-04-17 08:48:32 (GMT) |
commit | 9d72bb452bced3a100f07f8a9e30c4495a9ec41a (patch) | |
tree | c39762a764fcc16f2cfc42e2504e58ff31e159e6 /Lib/pydoc.py | |
parent | ff11334927ee616d765b54a3851016b76a20bcec (diff) | |
download | cpython-9d72bb452bced3a100f07f8a9e30c4495a9ec41a.zip cpython-9d72bb452bced3a100f07f8a9e30c4495a9ec41a.tar.gz cpython-9d72bb452bced3a100f07f8a9e30c4495a9ec41a.tar.bz2 |
Remove functions in string module that are also string methods. Also remove:
* all calls to functions in the string module (except maketrans)
* everything from stropmodule except for maketrans() which is still used
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 125 |
1 files changed, 64 insertions, 61 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 9fca8c2..59c4593 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -54,7 +54,6 @@ Richard Chamberlain, for the first implementation of textdoc. import sys, imp, os, re, types, inspect, __builtin__, pkgutil from repr import Repr -from string import expandtabs, find, join, lower, split, strip, rfind, rstrip try: from collections import deque except ImportError: @@ -80,16 +79,16 @@ def pathdirs(): def getdoc(object): """Get the doc string or comments for an object.""" result = inspect.getdoc(object) or inspect.getcomments(object) - return result and re.sub('^ *\n', '', rstrip(result)) or '' + return result and re.sub('^ *\n', '', result.rstrip()) or '' def splitdoc(doc): """Split a doc string into a synopsis line (if any) and the rest.""" - lines = split(strip(doc), '\n') + lines = doc.strip().split('\n') if len(lines) == 1: return lines[0], '' - elif len(lines) >= 2 and not rstrip(lines[1]): - return lines[0], join(lines[2:], '\n') - return '', join(lines, '\n') + elif len(lines) >= 2 and not lines[1].rstrip(): + return lines[0], '\n'.join(lines[2:]) + return '', '\n'.join(lines) def classname(object, modname): """Get a class name and qualify it with a module name if necessary.""" @@ -107,7 +106,7 @@ def isdata(object): def replace(text, *pairs): """Do a series of global replacements on a string.""" while pairs: - text = join(split(text, pairs[0]), pairs[1]) + text = pairs[1].join(text.split(pairs[0])) pairs = pairs[2:] return text @@ -190,18 +189,18 @@ def ispackage(path): def source_synopsis(file): line = file.readline() - while line[:1] == '#' or not strip(line): + while line[:1] == '#' or not line.strip(): line = file.readline() if not line: break - line = strip(line) + line = line.strip() if line[:4] == 'r"""': line = line[1:] if line[:3] == '"""': line = line[3:] if line[-1:] == '\\': line = line[:-1] - while not strip(line): + while not line.strip(): line = file.readline() if not line: break - result = strip(split(line, '"""')[0]) + result = line.split('"""')[0].strip() else: result = None return result @@ -297,13 +296,13 @@ def safeimport(path, forceload=0, cache={}): # A SyntaxError occurred before we could execute the module. raise ErrorDuringImport(value.filename, info) elif exc is ImportError and \ - split(lower(str(value)))[:2] == ['no', 'module']: + str(value).lower().split()[:2] == ['no', 'module']: # The module was not found. return None else: # Some other error occurred during the importing process. raise ErrorDuringImport(path, sys.exc_info()) - for part in split(path, '.')[1:]: + for part in path.split('.')[1:]: try: module = getattr(module, part) except AttributeError: return None return module @@ -382,7 +381,7 @@ class HTMLRepr(Repr): def repr1(self, x, level): if hasattr(type(x), '__name__'): - methodname = 'repr_' + join(split(type(x).__name__), '_') + methodname = 'repr_' + '_'.join(type(x).__name__.split()) if hasattr(self, methodname): return getattr(self, methodname)(x, level) return self.escape(cram(stripid(repr(x)), self.maxother)) @@ -466,7 +465,7 @@ class HTMLDoc(Doc): def preformat(self, text): """Format literal preformatted text.""" - text = self.escape(expandtabs(text)) + text = self.escape(text.expandtabs()) return replace(text, '\n\n', '\n \n', '\n\n', '\n \n', ' ', ' ', '\n', '<br>\n') @@ -551,7 +550,7 @@ class HTMLDoc(Doc): results.append(self.namelink(name, classes)) here = end results.append(escape(text[here:])) - return join(results, '') + return ''.join(results) # ---------------------------------------------- type-specific routines @@ -567,7 +566,7 @@ class HTMLDoc(Doc): parents = [] for base in bases: parents.append(self.classlink(base, modname)) - result = result + '(' + join(parents, ', ') + ')' + result = result + '(' + ', '.join(parents) + ')' result = result + '\n</font></dt>' elif type(entry) is type([]): result = result + '<dd>\n%s</dd>\n' % self.formattree( @@ -581,13 +580,13 @@ class HTMLDoc(Doc): all = object.__all__ except AttributeError: all = None - parts = split(name, '.') + parts = name.split('.') links = [] for i in range(len(parts)-1): links.append( '<a href="%s.html"><font color="#ffffff">%s</font></a>' % - (join(parts[:i+1], '.'), parts[i])) - linkedname = join(links + parts[-1:], '.') + ('.'.join(parts[:i+1]), parts[i])) + linkedname = '.'.join(links + parts[-1:]) head = '<big><big><strong>%s</strong></big></big>' % linkedname try: path = inspect.getabsfile(object) @@ -602,12 +601,12 @@ class HTMLDoc(Doc): if hasattr(object, '__version__'): version = str(object.__version__) if version[:11] == '$' + 'Revision: ' and version[-1:] == '$': - version = strip(version[11:-1]) + version = version[11:-1].strip() info.append('version %s' % self.escape(version)) if hasattr(object, '__date__'): info.append(self.escape(str(object.__date__))) if info: - head = head + ' (%s)' % join(info, ', ') + head = head + ' (%s)' % ', '.join(info) docloc = self.getdocloc(object) if docloc is not None: docloc = '<br><a href="%(docloc)s">Module Docs</a>' % locals() @@ -674,19 +673,19 @@ class HTMLDoc(Doc): for key, value in classes: contents.append(self.document(value, key, name, fdict, cdict)) result = result + self.bigsection( - 'Classes', '#ffffff', '#ee77aa', join(contents)) + 'Classes', '#ffffff', '#ee77aa', ' '.join(contents)) if funcs: contents = [] for key, value in funcs: contents.append(self.document(value, key, name, fdict, cdict)) result = result + self.bigsection( - 'Functions', '#ffffff', '#eeaa77', join(contents)) + 'Functions', '#ffffff', '#eeaa77', ' '.join(contents)) if data: contents = [] for key, value in data: contents.append(self.document(value, key)) result = result + self.bigsection( - 'Data', '#ffffff', '#55aa55', join(contents, '<br>\n')) + 'Data', '#ffffff', '#55aa55', '<br>\n'.join(contents)) if hasattr(object, '__author__'): contents = self.markup(str(object.__author__), self.preformat) result = result + self.bigsection( @@ -831,7 +830,7 @@ class HTMLDoc(Doc): parents = [] for base in bases: parents.append(self.classlink(base, object.__module__)) - title = title + '(%s)' % join(parents, ', ') + title = title + '(%s)' % ', '.join(parents) doc = self.markup(getdoc(object), self.preformat, funcs, classes, mdict) doc = doc and '<tt>%s<br> </tt>' % doc @@ -951,7 +950,7 @@ class TextRepr(Repr): def repr1(self, x, level): if hasattr(type(x), '__name__'): - methodname = 'repr_' + join(split(type(x).__name__), '_') + methodname = 'repr_' + '_'.join(type(x).__name__.split()) if hasattr(self, methodname): return getattr(self, methodname)(x, level) return cram(stripid(repr(x)), self.maxother) @@ -983,19 +982,20 @@ class TextDoc(Doc): def bold(self, text): """Format a string in bold by overstriking.""" - return join(map(lambda ch: ch + '\b' + ch, text), '') + return ''.join(map(lambda ch: ch + '\b' + ch, text)) def indent(self, text, prefix=' '): """Indent text by prepending a given prefix to each line.""" if not text: return '' - lines = split(text, '\n') + lines = text.split('\n') lines = map(lambda line, prefix=prefix: prefix + line, lines) - if lines: lines[-1] = rstrip(lines[-1]) - return join(lines, '\n') + if lines: lines[-1] = lines[-1].rstrip() + return '\n'.join(lines) def section(self, title, contents): """Format a section with a given heading.""" - return self.bold(title) + '\n' + rstrip(self.indent(contents)) + '\n\n' + clean_contents = self.indent(contents).rstrip() + return self.bold(title) + '\n' + clean_contents + '\n\n' # ---------------------------------------------- type-specific routines @@ -1008,7 +1008,7 @@ class TextDoc(Doc): result = result + prefix + classname(c, modname) if bases and bases != (parent,): parents = map(lambda c, m=modname: classname(c, m), bases) - result = result + '(%s)' % join(parents, ', ') + result = result + '(%s)' % ', '.join(parents) result = result + '\n' elif type(entry) is type([]): result = result + self.formattree( @@ -1068,7 +1068,7 @@ class TextDoc(Doc): modpkgs.sort() result = result + self.section( - 'PACKAGE CONTENTS', join(modpkgs, '\n')) + 'PACKAGE CONTENTS', '\n'.join(modpkgs)) if classes: classlist = map(lambda (key, value): value, classes) @@ -1076,24 +1076,24 @@ class TextDoc(Doc): inspect.getclasstree(classlist, 1), name)] for key, value in classes: contents.append(self.document(value, key, name)) - result = result + self.section('CLASSES', join(contents, '\n')) + result = result + self.section('CLASSES', '\n'.join(contents)) if funcs: contents = [] for key, value in funcs: contents.append(self.document(value, key, name)) - result = result + self.section('FUNCTIONS', join(contents, '\n')) + result = result + self.section('FUNCTIONS', '\n'.join(contents)) if data: contents = [] for key, value in data: contents.append(self.docother(value, key, name, maxlen=70)) - result = result + self.section('DATA', join(contents, '\n')) + result = result + self.section('DATA', '\n'.join(contents)) if hasattr(object, '__version__'): version = str(object.__version__) if version[:11] == '$' + 'Revision: ' and version[-1:] == '$': - version = strip(version[11:-1]) + version = version[11:-1].strip() result = result + self.section('VERSION', version) if hasattr(object, '__date__'): result = result + self.section('DATE', str(object.__date__)) @@ -1118,7 +1118,7 @@ class TextDoc(Doc): title = self.bold(name) + ' = class ' + realname if bases: parents = map(makename, bases) - title = title + '(%s)' % join(parents, ', ') + title = title + '(%s)' % ', '.join(parents) doc = getdoc(object) contents = doc and [doc + '\n'] or [] @@ -1214,7 +1214,7 @@ class TextDoc(Doc): contents = '\n'.join(contents) if not contents: return title + '\n' - return title + '\n' + self.indent(rstrip(contents), ' | ') + '\n' + return title + '\n' + self.indent(contents.rstrip(), ' | ') + '\n' def formatvalue(self, object): """Format an argument default value as text.""" @@ -1267,7 +1267,7 @@ class TextDoc(Doc): return decl + '\n' else: doc = getdoc(object) or '' - return decl + '\n' + (doc and rstrip(self.indent(doc)) + '\n') + return decl + '\n' + (doc and self.indent(doc).rstrip() + '\n') def _docdescriptor(self, name, value, mod): results = [] @@ -1368,7 +1368,7 @@ def tempfilepager(text, cmd): def ttypager(text): """Page through text on a text terminal.""" - lines = split(plain(text), '\n') + lines = plain(text).split('\n') try: import tty fd = sys.stdin.fileno() @@ -1381,7 +1381,7 @@ def ttypager(text): try: r = inc = os.environ.get('LINES', 25) - 1 - sys.stdout.write(join(lines[:inc], '\n') + '\n') + sys.stdout.write('\n'.join(lines[:inc]) + '\n') while lines[r:]: sys.stdout.write('-- more --') sys.stdout.flush() @@ -1397,7 +1397,7 @@ def ttypager(text): if c in ('b', 'B', '\x1b'): r = r - inc - inc if r < 0: r = 0 - sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n') + sys.stdout.write('\n' + '\n'.join(lines[r:r+inc]) + '\n') r = r + inc finally: @@ -1437,10 +1437,10 @@ def describe(thing): def locate(path, forceload=0): """Locate an object by name or dotted path, importing as necessary.""" - parts = [part for part in split(path, '.') if part] + parts = [part for part in path.split('.') if part] module, n = None, 0 while n < len(parts): - nextmodule = safeimport(join(parts[:n+1], '.'), forceload) + nextmodule = safeimport('.'.join(parts[:n+1]), forceload) if nextmodule: module, n = nextmodule, n + 1 else: break if module: @@ -1637,8 +1637,8 @@ class Helper: for dir in [os.environ.get('PYTHONDOCS'), homedir and os.path.join(homedir, 'doc'), os.path.join(execdir, 'doc'), - '/usr/doc/python-docs-' + split(sys.version)[0], - '/usr/doc/python-' + split(sys.version)[0], + '/usr/doc/python-docs-' + sys.version.split()[0], + '/usr/doc/python-' + sys.version.split()[0], '/usr/doc/python-docs-' + sys.version[:3], '/usr/doc/python-' + sys.version[:3], os.path.join(sys.prefix, 'Resources/English.lproj/Documentation')]: @@ -1672,8 +1672,8 @@ has the same effect as typing a particular string at the help> prompt. if not request: break except (KeyboardInterrupt, EOFError): break - request = strip(replace(request, '"', '', "'", '')) - if lower(request) in ('q', 'quit'): break + request = replace(request, '"', '', "'", '').strip() + if request.lower() in ('q', 'quit'): break self.help(request) def getline(self, prompt): @@ -1692,7 +1692,7 @@ has the same effect as typing a particular string at the help> prompt. elif request == 'topics': self.listtopics() elif request == 'modules': self.listmodules() elif request[:8] == 'modules ': - self.listmodules(split(request)[1]) + self.listmodules(request.split()[1]) elif request in self.keywords: self.showtopic(request) elif request in self.topics: self.showtopic(request) elif request: doc(request, 'Help on %s:') @@ -1786,11 +1786,11 @@ running "hh -decompile . PythonNN.chm" in the C:\PythonNN\Doc> directory. parser.start_td = parser.start_th = lambda a, b=buffer: b.write('\t') parser.feed(document) buffer = replace(buffer.getvalue(), '\xa0', ' ', '\n', '\n ') - pager(' ' + strip(buffer) + '\n') + pager(' ' + buffer.strip() + '\n') if xrefs: buffer = StringIO.StringIO() formatter.DumbWriter(buffer).send_flowing_data( - 'Related help topics: ' + join(split(xrefs), ', ') + '\n') + 'Related help topics: ' + ', '.join(xrefs.split()) + '\n') self.output.write('\n%s\n' % buffer.getvalue()) def listmodules(self, key=''): @@ -1809,7 +1809,7 @@ Please wait a moment while I gather a list of all available modules... def callback(path, modname, desc, modules=modules): if modname and modname[-9:] == '.__init__': modname = modname[:-9] + ' (package)' - if find(modname, '.') < 0: + if modname.find('.') < 0: modules[modname] = 1 ModuleScanner().run(callback) self.list(modules.keys()) @@ -1848,7 +1848,7 @@ class ModuleScanner: """An interruptible scanner that searches module synopses.""" def run(self, callback, key=None, completer=None): - if key: key = lower(key) + if key: key = key.lower() self.quit = False seen = {} @@ -1858,8 +1858,10 @@ class ModuleScanner: if key is None: callback(None, modname, '') else: - desc = split(__import__(modname).__doc__ or '', '\n')[0] - if find(lower(modname + ' - ' + desc), key) >= 0: + name = __import__(modname).__doc__ or '' + desc = name.split('\n')[0] + name = modname + ' - ' + desc + if name.lower().find(key) >= 0: callback(None, modname, desc) for importer, modname, ispkg in pkgutil.walk_packages(): @@ -1882,7 +1884,8 @@ class ModuleScanner: module = loader.load_module(modname) desc = (module.__doc__ or '').splitlines()[0] path = getattr(module,'__file__',None) - if find(lower(modname + ' - ' + desc), key) >= 0: + name = modname + ' - ' + desc + if name.lower().find(key) >= 0: callback(path, modname, desc) if completer: @@ -1953,7 +1956,7 @@ def serve(port, callback=None, completer=None): seen = {} for dir in sys.path: indices.append(html.index(dir, seen)) - contents = heading + join(indices) + '''<p align=right> + contents = heading + ' '.join(indices) + '''<p align=right> <font color="#909090" face="helvetica, arial"><strong> pydoc</strong> by Ka-Ping Yee <ping@lfw.org></font>''' self.send_document('Index of Modules', contents) @@ -2135,7 +2138,7 @@ def gui(): def goto(self, event=None): selection = self.result_lst.curselection() if selection: - modname = split(self.result_lst.get(selection[0]))[0] + modname = self.result_lst.get(selection[0]).split()[0] self.open(url=self.server.url + modname + '.html') def collapse(self): @@ -2180,7 +2183,7 @@ def gui(): # -------------------------------------------------- command-line interface def ispath(x): - return isinstance(x, str) and find(x, os.sep) >= 0 + return isinstance(x, str) and x.find(os.sep) >= 0 def cli(): """Command-line interface (looks at sys.argv to decide what to do).""" |