mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Clean up the handling of getsourcefile/getabsfile.
Remove __main__ from the index of built-in modules. Miscellaneous compatibility fixes.
This commit is contained in:
parent
c113c24e19
commit
239432a545
1 changed files with 37 additions and 23 deletions
50
Lib/pydoc.py
50
Lib/pydoc.py
|
@ -62,7 +62,7 @@ def synopsis(filename, cache={}):
|
||||||
while strip(line) == '':
|
while strip(line) == '':
|
||||||
line = file.readline()
|
line = file.readline()
|
||||||
if not line: break
|
if not line: break
|
||||||
result = split(line, '"""')[0]
|
result = strip(split(line, '"""')[0])
|
||||||
else: result = None
|
else: result = None
|
||||||
file.close()
|
file.close()
|
||||||
cache[filename] = (mtime, result)
|
cache[filename] = (mtime, result)
|
||||||
|
@ -86,7 +86,7 @@ def getdoc(object):
|
||||||
if not result:
|
if not result:
|
||||||
try: result = inspect.getcomments(object)
|
try: result = inspect.getcomments(object)
|
||||||
except: pass
|
except: pass
|
||||||
return result and rstrip(result) or ''
|
return result and re.sub('^ *\n', '', rstrip(result)) or ''
|
||||||
|
|
||||||
def classname(object, modname):
|
def classname(object, modname):
|
||||||
"""Get a class name and qualify it with a module name if necessary."""
|
"""Get a class name and qualify it with a module name if necessary."""
|
||||||
|
@ -393,9 +393,7 @@ class HTMLDoc(Doc):
|
||||||
linkedname = join(links + parts[-1:], '.')
|
linkedname = join(links + parts[-1:], '.')
|
||||||
head = '<big><big><strong>%s</strong></big></big>' % linkedname
|
head = '<big><big><strong>%s</strong></big></big>' % linkedname
|
||||||
try:
|
try:
|
||||||
path = os.path.abspath(inspect.getfile(object))
|
path = inspect.getabsfile(object)
|
||||||
sourcepath = os.path.abspath(inspect.getsourcefile(object))
|
|
||||||
if os.path.isfile(sourcepath): path = sourcepath
|
|
||||||
filelink = '<a href="file:%s">%s</a>' % (path, path)
|
filelink = '<a href="file:%s">%s</a>' % (path, path)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
filelink = '(built-in)'
|
filelink = '(built-in)'
|
||||||
|
@ -675,9 +673,9 @@ class TextDoc(Doc):
|
||||||
if lines[0]: name = name + ' - ' + lines[0]
|
if lines[0]: name = name + ' - ' + lines[0]
|
||||||
lines = lines[2:]
|
lines = lines[2:]
|
||||||
result = result + self.section('NAME', name)
|
result = result + self.section('NAME', name)
|
||||||
try: file = inspect.getfile(object) # XXX or getsourcefile?
|
try: file = inspect.getabsfile(object)
|
||||||
except TypeError: file = None
|
except TypeError: file = '(built-in)'
|
||||||
result = result + self.section('FILE', file or '(built-in)')
|
result = result + self.section('FILE', file)
|
||||||
if lines:
|
if lines:
|
||||||
result = result + self.section('DESCRIPTION', join(lines, '\n'))
|
result = result + self.section('DESCRIPTION', join(lines, '\n'))
|
||||||
|
|
||||||
|
@ -1049,6 +1047,7 @@ class ModuleScanner(Scanner):
|
||||||
seen = {}
|
seen = {}
|
||||||
|
|
||||||
for modname in sys.builtin_module_names:
|
for modname in sys.builtin_module_names:
|
||||||
|
if modname != '__main__':
|
||||||
seen[modname] = 1
|
seen[modname] = 1
|
||||||
desc = split(__import__(modname).__doc__ or '', '\n')[0]
|
desc = split(__import__(modname).__doc__ or '', '\n')[0]
|
||||||
if find(lower(modname + ' - ' + desc), lower(key)) >= 0:
|
if find(lower(modname + ' - ' + desc), lower(key)) >= 0:
|
||||||
|
@ -1124,10 +1123,13 @@ def serve(port, callback=None):
|
||||||
heading = html.heading(
|
heading = html.heading(
|
||||||
'<big><big><strong>Python: Index of Modules</strong></big></big>',
|
'<big><big><strong>Python: Index of Modules</strong></big></big>',
|
||||||
'#ffffff', '#7799ee')
|
'#ffffff', '#7799ee')
|
||||||
builtins = []
|
def bltinlink(name):
|
||||||
for name in sys.builtin_module_names:
|
return '<a href="%s.html">%s</a>' % (name, name)
|
||||||
builtins.append('<a href="%s.html">%s</a>' % (name, name))
|
names = filter(lambda x: x != '__main__', sys.builtin_module_names)
|
||||||
indices = ['<p>Built-in modules: ' + join(builtins, ', ')]
|
contents = html.multicolumn(names, bltinlink)
|
||||||
|
indices = ['<p>' + html.bigsection(
|
||||||
|
'Built-in Modules', '#ffffff', '#ee77aa', contents)]
|
||||||
|
|
||||||
seen = {}
|
seen = {}
|
||||||
for dir in pathdirs():
|
for dir in pathdirs():
|
||||||
indices.append(html.index(dir, seen))
|
indices.append(html.index(dir, seen))
|
||||||
|
@ -1206,8 +1208,8 @@ def gui():
|
||||||
self.search_frm.pack(side='top', fill='x')
|
self.search_frm.pack(side='top', fill='x')
|
||||||
self.search_ent.focus_set()
|
self.search_ent.focus_set()
|
||||||
|
|
||||||
self.result_lst = Tkinter.Listbox(window,
|
font = ('helvetica', sys.platform in ['win32', 'win', 'nt'] and 8 or 10)
|
||||||
font=('helvetica', 8), height=6)
|
self.result_lst = Tkinter.Listbox(window, font=font, height=6)
|
||||||
self.result_lst.bind('<Button-1>', self.select)
|
self.result_lst.bind('<Button-1>', self.select)
|
||||||
self.result_lst.bind('<Double-Button-1>', self.goto)
|
self.result_lst.bind('<Double-Button-1>', self.goto)
|
||||||
self.result_scr = Tkinter.Scrollbar(window,
|
self.result_scr = Tkinter.Scrollbar(window,
|
||||||
|
@ -1244,9 +1246,22 @@ def gui():
|
||||||
self.open_btn.config(state='normal')
|
self.open_btn.config(state='normal')
|
||||||
self.quit_btn.config(state='normal')
|
self.quit_btn.config(state='normal')
|
||||||
|
|
||||||
def open(self, event=None):
|
def open(self, event=None, url=None):
|
||||||
|
url = url or self.server.url
|
||||||
|
try:
|
||||||
import webbrowser
|
import webbrowser
|
||||||
webbrowser.open(self.server.url)
|
webbrowser.open(url)
|
||||||
|
except ImportError: # pre-webbrowser.py compatibility
|
||||||
|
if sys.platform in ['win', 'win32', 'nt']:
|
||||||
|
os.system('start "%s"' % url)
|
||||||
|
elif sys.platform == 'mac':
|
||||||
|
try:
|
||||||
|
import ic
|
||||||
|
ic.launchurl(url)
|
||||||
|
except ImportError: pass
|
||||||
|
else:
|
||||||
|
rc = os.system('netscape -remote "openURL(%s)" &' % url)
|
||||||
|
if rc: os.system('netscape "%s" &' % url)
|
||||||
|
|
||||||
def quit(self, event=None):
|
def quit(self, event=None):
|
||||||
if self.server:
|
if self.server:
|
||||||
|
@ -1296,9 +1311,8 @@ def gui():
|
||||||
def goto(self, event=None):
|
def goto(self, event=None):
|
||||||
selection = self.result_lst.curselection()
|
selection = self.result_lst.curselection()
|
||||||
if selection:
|
if selection:
|
||||||
import webbrowser
|
|
||||||
modname = split(self.result_lst.get(selection[0]))[0]
|
modname = split(self.result_lst.get(selection[0]))[0]
|
||||||
webbrowser.open(self.server.url + modname + '.html')
|
self.open(url=self.server.url + modname + '.html')
|
||||||
|
|
||||||
def collapse(self):
|
def collapse(self):
|
||||||
if not self.expanded: return
|
if not self.expanded: return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue