Update of /cvsroot/tmda/tmda/contrib/cgi
In directory sc8-pr-cvs1:/tmp/cvs-serv25978
Added Files:
CgiUtil.py
Log Message:
CgiUtil.py provides a few random functions needed in the CGI.
Size - Convert a number of bytes into a more human-readible format.
GetPendingList - Return list of all pending e-mails (filenames).
Escape - Safely escape a string, even if it turns out to be None.
--- NEW FILE ---
#!/usr/bin/env python
#
# Copyright (C) 2002 Gre7g Luterman <[EMAIL PROTECTED]>
#
# This file is part of TMDA.
#
# TMDA is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. A copy of this license should
# be included in the file COPYING.
#
# TMDA is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with TMDA; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"Utilities for tmda-cgi."
import cgi
import email
import glob
import os
from TMDA import Defaults
def Size(MsgObj):
MsgSize = len(MsgObj.as_string())
if MsgSize > 512:
if MsgSize > 5120:
if MsgSize > 524288:
if MsgSize > 5242880:
MsgSize = "%dM" % (MsgSize / 1048576)
else:
MsgSize = "%3.1fM" % (MsgSize / 1048576.0)
else:
MsgSize = "%dk" % (MsgSize / 1024)
else:
MsgSize = "%3.1fk" % (MsgSize / 1024.0)
else:
MsgSize = "%d" % MsgSize
return MsgSize
def RevCmp(x, y):
if x == y: return 0
if x < y: return 1
return -1
def GetPendingList():
"Return a list of all pending message filenames."
# Locate messages in pending dir
os.chdir(os.path.join(Defaults.DATADIR, 'pending'))
Msgs = glob.glob('*.*.msg')
if PVars["SortDir"] == "desc":
Msgs.sort(RevCmp)
else:
Msgs.sort()
return Msgs
def Escape(s):
if s:
return cgi.escape(s)
return ""
_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs