Re: viewing pydoc output in FireFox
From: Jeff Epler (jepler_at_unpythonic.net)
Date: 10/17/04
- Next message: Jeff Epler: "Re: Message from exception raised in generator disappears"
- Previous message: andrew blah: "Re: Secure Python code - volunteers for code review?"
- Maybe in reply to: Kent Tenney: "viewing pydoc output in FireFox"
- Next in thread: Kent Tenney: "Re: viewing pydoc output in FireFox"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 16 Oct 2004 20:49:03 -0500 To: Kent Tenney <kent@springfed.com>
I don't know. My mozilla (firefox 0.9.3 on linux) displays ".py" files
from the file: URLs as text without any special configuration.
Here's a patch to pydoc to serve .py source files over http as
text/plain. It should be fairly easy to apply manually if you don't
have a unix-style "patch" program on your windows machine (just remove
the lines marked with "-" and add the ones marked with "+", at around
the line numbers given in the '@@" line).
I tested it minimally (again, on my linux machine with firefox 0.9.3)
and it works nicely. Modules and packages display their source code,
and non-.py files are no longer linked. instead you see text like
/usr/lib/python2.3/lib-dynload/_tkinter.so (Shared module)
Please feel free to use these changes under the terms of the python
license.
--- /usr/lib/python2.3/pydoc.py 2004-05-07 09:52:46.000000000 -0500
+++ ./pydoc.py 2004-10-16 20:38:59.618007763 -0500
@@ -515,11 +515,10 @@
head = '<big><big><strong>%s</strong></big></big>' % linkedname
try:
path = inspect.getabsfile(object)
- url = path
- if sys.platform == 'win32':
- import nturl2path
- url = nturl2path.pathname2url(path)
- filelink = '%s' % (url, path)
+ if not path.endswith(".py"):
+ filelink = "%s (Shared module)" % path
+ else:
+ filelink = '%s' % (".".join(parts), path)
except TypeError:
filelink = '(built-in)'
info = []
@@ -1812,8 +1811,28 @@
self.wfile.write(html.page(title, contents))
except IOError: pass
+ def send_text(self, contents):
+ try:
+ self.send_response(200)
+ self.send_header('Content-Type', 'text/plain')
+ self.end_headers()
+ self.wfile.write(contents)
+ except IOError: pass
+
def do_GET(self):
path = self.path
+ if path.endswith(".txt"):
+ path = path[:-4]
+ if path[:1] == '/': path = path[1:]
+ try:
+ obj = locate(path, forceload=1)
+ except ErrorDuringImport, value:
+ self.send_document(path, html.escape(str(value)))
+ return
+ f = inspect.getabsfile(obj)
+
+ self.send_text(open(f).read())
+ return
if path[-5:] == '.html': path = path[:-5]
if path[:1] == '/': path = path[1:]
if path and path != '.':
- application/pgp-signature attachment: stored
- Next message: Jeff Epler: "Re: Message from exception raised in generator disappears"
- Previous message: andrew blah: "Re: Secure Python code - volunteers for code review?"
- Maybe in reply to: Kent Tenney: "viewing pydoc output in FireFox"
- Next in thread: Kent Tenney: "Re: viewing pydoc output in FireFox"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|