Re: viewing pydoc output in FireFox

From: Jeff Epler (jepler_at_unpythonic.net)
Date: 10/17/04


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 != '.':






Relevant Pages

  • Re: Firefox Running Slow in Linux
    ... I'm also running Firefox 3.0.x, but I've noticed that it's not very ... smooth compared to it running on a Windows machine and I'm little confused ... ruining the surfing experience and I'm a little embarrassed to let other ... All instances of Firefox on Linux that I have tried run arbitrarily ...
    (Fedora)
  • Re: firefox
    ... All I did after the install was yum update and let it do everything it ... being that you are moving to linux, it may well be beneficial to move ... right click on 'ethernet 0 up' to hilite and select 'new item'. ... to make things a little more enjoyable with firefox, open firefox, look ...
    (Fedora)
  • [PATCH] mmu notifiers #v2
    ... In short when the linux VM decides to free a page, ... This patch allows the shadow pagetables to be dropped and the page to ... behavior of the KVM gphysical memory. ...
    (Linux-Kernel)
  • Re: [Announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]
    ... Con Kolivas wrote: ... surprising Ingo made it a separate patch set as Con has repeatedly ... gzip simply doesn't play well with others... ... than the scheduler in linux, and that's how much writes hurt just about ...
    (Linux-Kernel)
  • Re: 8.10 freezing a lot more recently.
    ... Gig of memory is quite adequate. ... times have suffered lock ups have always been hardware problems. ... Firefox on her windows laptop at her house for these sites without ... in Linux, you get an error saying that the site only works under IE ...
    (Ubuntu)