diff options
| author | bwarsaw | 1998-12-27 20:00:19 +0000 |
|---|---|---|
| committer | bwarsaw | 1998-12-27 20:00:19 +0000 |
| commit | 7662f82fb5e0413cabe6879be806a1e98b4f9fe8 (patch) | |
| tree | 7316af1d5a61edd690c78a368f99115550e57c27 /Mailman/Cgi/archives.py | |
| parent | 9ceaab7aec4050c86139eb461863df6e25a61217 (diff) | |
| download | mailman-7662f82fb5e0413cabe6879be806a1e98b4f9fe8.tar.gz mailman-7662f82fb5e0413cabe6879be806a1e98b4f9fe8.tar.zst mailman-7662f82fb5e0413cabe6879be806a1e98b4f9fe8.zip | |
Fixed bugs that occur when no list name is given in the URL.
Also, several stylistic fixes:
- ArchiveFilter() need not be nested
- Don't use eval(str) to convert a string to an integer; it's slower
and less safe than using int(str), but be sure to catch ValueError
which might result when a bad string is given.
- Note to anyone writing Mailman/Cgi scripts! Nothing but imports
should happen as a side effect of importing this module. Run
everything from inside a main() function (see scripts/driver for
details).
- get rid of unnecessary imports
- Fix #! line, even though this script isn't typically run from the
command line.
Diffstat (limited to 'Mailman/Cgi/archives.py')
| -rw-r--r-- | Mailman/Cgi/archives.py | 95 |
1 files changed, 50 insertions, 45 deletions
diff --git a/Mailman/Cgi/archives.py b/Mailman/Cgi/archives.py index 88df821bc..414795c7a 100644 --- a/Mailman/Cgi/archives.py +++ b/Mailman/Cgi/archives.py @@ -1,4 +1,4 @@ -#! /usr/bin/env/python +#! /usr/bin/env python # # Copyright (C) 1998 by the Free Software Foundation, Inc. # @@ -22,65 +22,70 @@ # data. import sys -import os, types, posix, string +import os +import string from Mailman import Utils, MailList, htmlformat -print "Content-type: text/html" -print -path = os.environ['PATH_INFO'] -list_info = Utils.GetPathPieces(path) - -if len(list_info) < 1: - print "<h2>Invalid options to CGI script.</h2>" - sys.exit(0) - -list_name = string.lower(list_info[0]) - -try: - list = MailList.MailList(list_name) -except: - print "<h2>%s: No such list.</h2>" % list_name - sys.exit(0) +def ArchiveFilter(str): + try: + if str[:7] <> 'volume_': + return 0 + try: + x = int(str[7:]) + except ValueError: + return 0 + if x < 1: + return 0 + return 1 + except IndexError: + return 0 -if not list._ready: - print "<h2>%s: No such list.</h2>" % list_name - sys.exit(0) -def GetArchiveList(list): +def GetArchiveList(mlist): archive_list = htmlformat.UnorderedList() - - def ArchiveFilter(str): - if str[:7] <> 'volume_': - return 0 - try: - x = eval(str[7:]) - if type(x) <> types.IntType: - return 0 - if x < 1: - return 0 - return 1 - except: - return 0 try: - dir_listing = filter(ArchiveFilter, os.listdir(list.archive_dir())) - except posix.error: + dir_listing = filter(ArchiveFilter, os.listdir(mlist.archive_dir())) + except os.error: return "<h3><em>No archives are currently available.</em></h3>" if not len(dir_listing): return "<h3><em>No archives are currently available.</em></h3>" for dir in dir_listing: - link = htmlformat.Link("%s/%s" % (list._base_archive_url, dir), + link = htmlformat.Link("%s/%s" % (mlist._base_archive_url, dir), "Volume %s" % dir[7:]) archive_list.AddItem(link) - return archive_list.Format() - +def main(): + print "Content-type: text/html" + print + + list_info = [] + try: + path = os.environ['PATH_INFO'] + list_info = Utils.GetPathPieces(path) + except KeyError: + pass + + if len(list_info) < 1: + print "<h2>Invalid options to CGI script.</h2>" + sys.exit(0) + + list_name = string.lower(list_info[0]) + try: + mlist = MailList.MailList(list_name) + except: + print "<h2>%s: No such list.</h2>" % list_name + sys.exit(0) + + if not mlist._ready: + print "<h2>%s: No such list.</h2>" % list_name + sys.exit(0) -replacements = list.GetStandardReplacements() -replacements['<mm-archive-list>'] = GetArchiveList(list) + replacements = mlist.GetStandardReplacements() + replacements['<mm-archive-list>'] = GetArchiveList(mlist) -# Just doing print list.ParseTags(...) calls ParseTags twice??? -text = list.ParseTags('archives.html', replacements) -print text + # Just doing print mlist.ParseTags(...) calls ParseTags twice??? + text = mlist.ParseTags('archives.html', replacements) + print text |
