CVS: tmda-cgi Authenticate.py,1.13,1.14 CgiUtil.py,1.16,1.17 MyCgiTb.py,1.2,1.3 PendList.py,1.13,1.14 Release.py,1.2,1.3 THANKS,1.9,1.10 Template.py,1.6,1.7 View.py,1.18,1.19 tmda-cgi.py,1.31,1.32

Gre7g Luterman <[email protected]>
Newsgroups gmane.mail.spam.tmda.cvs
Message-ID <[email protected]>
Update of /cvsroot/tmda/tmda-cgi
In directory sc8-pr-cvs1:/tmp/cvs-serv6135

Modified Files:
	Authenticate.py CgiUtil.py MyCgiTb.py PendList.py Release.py 
	THANKS Template.py View.py tmda-cgi.py 
Log Message:
Moved HTML header handling code to Template.py instead of MyCgiTb.py.

Dumped special template functions for charset.  They just aren't needed.

Stripped out email dependency from Template.  Breaks OOP design.

Added a debugging method to the Template module.

Stripped out the FallbackCharset stuff.


Index: Authenticate.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/Authenticate.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Authenticate.py	19 Apr 2003 21:10:35 -0000	1.13
+++ Authenticate.py	13 May 2003 16:12:36 -0000	1.14
@@ -24,8 +24,6 @@
 import CgiUtil
 import crypt
 import os
-import os.path
-import pwd
 import random
 import sys
 

Index: CgiUtil.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/CgiUtil.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- CgiUtil.py	13 May 2003 15:11:54 -0000	1.16
+++ CgiUtil.py	13 May 2003 16:12:36 -0000	1.17
@@ -166,7 +166,7 @@
 
   if not CharSet:
     return Str
-  CS = email.Charset.Charset( CharSet )
+  CS = email.Charset.Charset(CharSet)
   CharSet = CS.input_charset
 
   # Find appropriate decoder

Index: MyCgiTb.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/MyCgiTb.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MyCgiTb.py	16 Apr 2003 01:47:24 -0000	1.2
+++ MyCgiTb.py	13 May 2003 16:12:36 -0000	1.3
@@ -22,7 +22,9 @@
 """A wrapper around cgitb that places errors in our framework and uses our 
 colors."""
 
-import sys, Template
+import sys
+
+import Template
 
 # Customizable colors to look for in prog_err.html
 ColorSwap = \
@@ -32,26 +34,8 @@
 }
 ErrTemplate = None
 
-ContentType = "text/html"
-
-def Content(Type = None):
-  "Print out the content type header (once only!)"
-  global ContentType
-  
-  if ContentType:
-    if Type: ContentType = Type
-    print "Content-Type: %s\n\n" % ContentType
-    ContentType = None
-
 def CgiTbReset():
   "Replacement function for cgitb.reset()"
-
-  global ContentType
-
-  if ContentType:
-    RetVal = "Content-Type: %s\n\n" % ContentType
-    ContentType = None
-    return RetVal
   return ""
 
 def ColorReplacer((etype, evalue, etb), context=5):
@@ -71,7 +55,7 @@
   T["ErrorMessage"] = HTML
 
   # Return new, frameworked page
-  return T.__repr__()
+  return str(T)
 
 # Try to import cgitb (not present in Python before version 2.2)
 try:

Index: PendList.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/PendList.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- PendList.py	12 May 2003 16:59:23 -0000	1.13
+++ PendList.py	13 May 2003 16:12:36 -0000	1.14
@@ -93,7 +93,7 @@
 
   # Load the display template
   T = Template.Template("pending.html")
-  T.set_charset( "utf-8" )
+  T["CharSet"] = "utf-8"
 
   # Find the message numbers we'll display
   FirstMsg = PVars["Pager"]

Index: Release.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/Release.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Release.py	16 Apr 2003 05:26:21 -0000	1.2
+++ Release.py	13 May 2003 16:12:36 -0000	1.3
@@ -44,7 +44,6 @@
 """
 
   # Prepare the traceback in case of uncaught exception
-  MyCgiTb.Content()
   MyCgiTb.ErrTemplate = "prog_err2.html"
   CgiUtil.ErrTemplate = "error2.html"
 

Index: THANKS
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/THANKS,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- THANKS	7 May 2003 16:31:53 -0000	1.9
+++ THANKS	13 May 2003 16:12:36 -0000	1.10
@@ -26,17 +26,20 @@
 
     * Remo Mattei -- bug finding
 
-    * Jim Ramsay -- authentication, brainstorming, user interface feature
-                    plans, and hopefully lots of the programming in the near
-                    future!
+    * Jim Ramsay -- authentication, brainstorming, user interface, feature
+                    plans, alternate character set stuff
 
     * Tim Rice -- compiler suggestions so we can work in more environments
 
     * Jeff Ross -- bug finding
 
+    * Ronald Wiplinger -- providing Chinese spam and feedback on whether
+                          tmda-cgi was rendering it correctly
+
     * Cory Wright -- providing insight into how to use vpopmail and gently
                      pointing out the obvious when I miss it, fixing my alt
-		     tags so they are not browser specific
+                     tags so they are not browser specific, adding in some neat
+                     little things that had been left out
 
 Includes:
 ---------

Index: Template.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/Template.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Template.py	12 May 2003 16:59:23 -0000	1.6
+++ Template.py	13 May 2003 16:12:36 -0000	1.7
@@ -108,13 +108,22 @@
 #
 # <center>Form may not be submitted.</center>
 
-import copy, re
-import email.Charset
+import copy
+import re
 from types import StringType
 
+# Module globals
+SentHeaders = 0
+
+def Debug(Str):
+  "Output a debugging string."
+  if not SentHeaders: print "Content-Type: text/html\n\n"
+  SentHeaders = 1
+  print Str
+
 class Template:
   # Members global across all instantiations:
-  Dict            = {}
+  Dict            = {"CharSet": "utf-8"}
   BaseDir         = "."
   VarSearchStr    = '<!--\s*var:\s*%s(?:="([^"]+)")?\s*-->'
   VarEndSearch    = re.compile("<!--\s*/var[^-]*-->", re.I)
@@ -122,8 +131,6 @@
   LonePctRepl     = r"\1%%\2"
   SearchDict      = {}
   BeenExpanded    = 0
-  FallbackCharset = "utf-8"
-  charset = None
 
   def __init__ \
   (
@@ -142,14 +149,6 @@
       F.close()
     self.Items = {}
 
-  def set_charset(self, Charset = None ):
-    "Sets the characterset for this page."
-    if Charset is None: Charset = self.FallbackCharset
-    # If this is an alias, find the "real" charset:
-    chsetObj = email.Charset.Charset( Charset )
-    self.charset = chsetObj.input_charset
-    self["CharSet"] = self.charset
-
   def __setitem__(self, Index, Value):
     "Assign a substitution variable."
     if self.Items.has_key(Index):
@@ -160,16 +159,14 @@
   def __str__(self):
     "Convert to string for printing in browser. (Adds content-type header)"
 
-    if not self.charset:
-        self.set_charset()
-    addStr = "; charset=%s" % self.charset
-    RetVal = "Content-Type: text/html%s\n\n" % addStr
-    RetVal += self.__repr__()
-    return RetVal
-
-  def __repr__(self):
-    "Dump contents of object."
-    RetVal = ""
+    global SentHeaders
+
+    if SentHeaders:
+      RetVal = ""
+    else:
+      RetVal = "Content-Type: text/html; charset=%(CharSet)s\n\n" % self.Dict
+    SentHeaders = 1
+
     for HTML in self.HTML:
       if type(HTML) == StringType:
         if self.BeenExpanded:
@@ -177,7 +174,7 @@
         else:
           RetVal += self.LonePctSearch.sub(self.LonePctRepl, HTML) % self.Dict
       else:
-        RetVal += repr(HTML)
+        RetVal += str(HTML)
     return RetVal
 
   def UpdateItems(self, Target):

Index: View.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/View.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- View.py	12 May 2003 16:59:23 -0000	1.18
+++ View.py	13 May 2003 16:12:36 -0000	1.19
@@ -226,7 +226,7 @@
       for decoded in email.Header.decode_header( Line ):
         Headers += decoded[0] + " "
         if decoded[1]:
-          T.set_charset( decoded[1] )
+          T["CharSet"] = email.Charset.Charset(decoded[1]).input_charset
       Headers += "\n"
     T["Headers"] = '<pre class="Headers">%s</pre>' % Headers
   else:
@@ -241,7 +241,7 @@
       for decoded in email.Header.decode_header( MsgObj.msgobj[Header] ):
         value += decoded[0] + " "
         if decoded[1]:
-          T.set_charset( decoded[1] )
+          T["CharSet"] = email.Charset.Charset(decoded[1]).input_charset
       T["Value"] = CgiUtil.Escape(value)
       HeaderRow.Add()
 
@@ -312,7 +312,8 @@
     if Type == "text/plain":
       # Check if there's a character set for this part.
       if Part.get_content_charset():
-        T.set_charset( Part.get_content_charset() )
+        T["CharSet"] = \
+          email.Charset.Charset(Part.get_content_charset()).input_charset
       # Escape & display
       try:
         Str = Part.get_payload(decode=1).strip()
@@ -326,7 +327,8 @@
       # Sterilize & display
       # Check if there's a character set for this part.
       if Part.get_content_charset():
-        T.set_charset( Part.get_content_charset() )
+        T["CharSet"] = \
+          email.Charset.Charset(Part.get_content_charset()).input_charset
       try:
         T["Content"] = \
           CgiUtil.Sterilize(Part.get_payload(decode=1), Allow, Remove)

Index: tmda-cgi.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/tmda-cgi.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- tmda-cgi.py	12 May 2003 16:59:23 -0000	1.31
+++ tmda-cgi.py	13 May 2003 16:12:36 -0000	1.32
@@ -22,7 +22,6 @@
 "Web interface to TMDA tools."
 
 import MyCgiTb
-import CharSetAlias
 
 import cgi
 import os
@@ -36,6 +35,7 @@
   "pythonlib"))
 from TMDA import Errors
 
+import CharSetAlias
 import CgiUtil
 import Session
 import Template
@@ -58,7 +58,6 @@
 # Make some global stuff available to all
 Template.Template.BaseDir = "%s/display/themes/Blue/template" % \
   os.path.abspath(os.path.split(sys.argv[0])[0])
-#Template.Template.FallbackCharset  = "iso-8859-1"
 Template.Template.Dict["Script"]   = os.environ["SCRIPT_NAME"]
 Template.Template.Dict["SID"]      = ""
 Template.Template.Dict["DispDir"]  = os.environ["TMDA_CGI_DISP_DIR"]

_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.