[Mailman-Developers] Patch to private.py

Andrew M. Kuchling akuchlin@cnri.reston.va.us
Fri, 4 Dec 1998 13:22:25 -0500 (EST)


Here's a patch to private.py which makes it 1) return text/plain as
the content type if the file ends in .txt, and 2) look for
<filename>.gz if <filename> doesn't exist, and uses the gzip module to
read it.

-- 
A.M. Kuchling			http://starship.skyport.net/crew/amk/
How do you make sense of your life? Signal to noise: What's signal? What's
noise?
    -- The dying film director in SIGNAL TO NOISE



*** private.py	1998/12/04 16:26:29	1.1
--- private.py	1998/12/04 16:48:36
***************
*** 142,145 ****
--- 142,149 ----
      return path[1:]
  
+ def content_type(path):
+     if path[-3:] == '.gz': path = path[:-3]
+     if path[-4:] == '.txt': return 'text/plain'
+     return 'text/html'
  
  def main():
***************
*** 147,153 ****
      true_filename = os.path.join(ROOT, true_path(path) )
      list_name = getListName(path)
      if os.path.isdir(true_filename):
          true_filename = true_filename + '/index.html'
! 
      if not isAuthenticated(list_name):
          # Output the password form
--- 151,164 ----
      true_filename = os.path.join(ROOT, true_path(path) )
      list_name = getListName(path)
+ 
+     # If it's a directory, we have to append index.html in this script.
+     # We must also check for a gzipped file, because the text archives
+     # are usually stored in compressed form.
      if os.path.isdir(true_filename):
          true_filename = true_filename + '/index.html'
!     if (not os.path.exists(true_filename) and
!         os.path.exists(true_filename + '.gz') ):
!         true_filename = true_filename + '.gz'
!         
      if not isAuthenticated(list_name):
          # Output the password form
***************
*** 167,180 ****
          print '\n\n', page % vars()
          sys.exit(0)
!     print 'Content-type: text/html\n'
!     
!     print '\n\n'
      # Authorization confirmed... output the desired file
      try:
!         f = open(true_filename, 'r')
      except IOError:
          print "<H3>Archive File Not Found</H3>"
          print "No file", path
      else:
          while (1):
              data = f.read(16384)
--- 178,196 ----
          print '\n\n', page % vars()
          sys.exit(0)
! 
      # Authorization confirmed... output the desired file
      try:
!         if true_filename[-3:] == '.gz':
!             import gzip
!             f = gzip.open(true_filename, 'r')
!         else:
!             f = open(true_filename, 'r')
      except IOError:
+         print 'Content-type: text/html\n'
+     
          print "<H3>Archive File Not Found</H3>"
          print "No file", path
      else:
+         print 'Content-type:', content_type(path), '\n'
          while (1):
              data = f.read(16384)