Update of /cvsroot/mailman/mailman3/src/mailman/cgi
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31133/src/mailman/cgi
Added Files:
Tag: 3.0
__init__.py do_admin.py do_create.py do_front.py
do_listinfo.py do_login.py do_styles.py do_varhelp.py zpt.py
Log Message:
Initial checkin of Mailman3 source
--- NEW FILE: __init__.py ---
--- NEW FILE: do_admin.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# This program 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.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
import logging
from mailman import categories
from mailman.adapters import MailListAdapter
from mailman.cgi import do_login
from mailman.cgi.zpt import MailmanTemplate
from mailman.config import configuration
from mailman.mlist import MailList
log = logging.getLogger('mailman.error')
def process(request, parts):
try:
listname = parts.pop(0)
except IndexError:
return do_login.process(request, parts)
webhost = request.getRequestHostname()
domain = configuration.domains.bywebhost[webhost]
listid = '%s.%s' % (listname, domain)
mlist = MailList(listid)
if parts:
catname = parts.pop(0)
else:
catname = 'general'
category = categories.allcats.get(catname)
# Access subcategory, if there is one
if category and parts:
subcatname = parts.pop(0)
subcat = category.subcategories.get(subcatname)
print 'subcategory:', subcat
if subcat is not None:
category = subcat
# XXX what to do if the category or subcategory is bad?
zpt = MailmanTemplate('admin.pt',
category=category,
mlist=MailListAdapter(mlist, category))
# See if we're self-posting or not
args = request.args
if not args:
return zpt()
# Self-posted, so process the form arguments, but only those which match
# attributes in the current category.
for key, val in args.items():
# Ignore form goo
if key == 'submit':
continue
prop, category = categories.allvars.get(key, (None, None))
if prop:
try:
pval = prop.parse(val)
except ValueError:
log.warning('bad value for prop %s: %s', key, val)
else:
if pval <> getattr(mlist, key):
setattr(mlist, key, pval)
else:
# See if this is an action
action = actions.get(key)
if action:
print 'Doing action:', key
else:
log.warning('mischievous form key ignored: %s', key)
return zpt()
actions = {
'action_new_volume': True,
'action_send_digest': True,
}
--- NEW FILE: do_create.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# This program 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.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
import logging
from mailman import errors
from mailman.cgi.zpt import MailmanTemplate
from mailman.config import configuration
from mailman.dbmgr import dbmgr
from mailman.mlist import MailList
from mailman.text.strings import dstring
from mailman.utils import isValidAddress
_default = [None]
log = logging.getLogger('mailman.error')
class ZPTResults:
def __init__(self, listname, listinfo, general):
self.listname = listname
self.listinfo = listinfo
self.general = general
def process(request, parts):
zpt = MailmanTemplate('create.pt', request=request)
if not request.args:
return zpt()
# Self-posted. First, parse arguments.
listname = request.args.get('listname', _default)[0]
owneremail = request.args.get('owneremail', _default)[0]
ownername = request.args.get('ownername', _default)[0]
listname = unicode(listname, 'utf-8')
owneremail = unicode(owneremail, 'utf-8')
ownername = unicode(ownername, 'utf-8')
# Sanity check the address
if not owneremail or not isValidAddress(owneremail):
log.error('bad owner email: %s', owneremail)
return zpt()
try:
# owneremail must contain ascii only
owneremail.encode('ascii')
except UnicodeError:
log.error('unicode error')
return zpt()
# Because this create request is coming from the web, we need to look up
# the hostname in the list of registered domains, returning the domain
# that this list should be created in.
requesthost = request.getRequestHostname()
domain = configuration.domains.bywebhost.get(requesthost)
if not domain:
log.error('No domain found for web host: %s', requesthost)
return zpt()
try:
mlist = MailList.create(listname, domain, owneremail, ownername)
except errors.MailingListError, e:
log.error('Could not create list: %s, %s, %s, %s\n%s',
listname, requesthost, owneremail, ownername, e)
return zpt()
log.info('List created: %s, %s, %s, %s',
listname, requesthost, owneremail, ownername)
# Create a ZPT path object for the results page
baseurl = dstring(configuration.webserver.baseurl + '$page/$listname')
d = {'hostname': configuration.domains.bydomain[domain][1],
'port': configuration.webserver.port,
'listname': listname}
d['page'] = 'listinfo'
listinfourl = baseurl % d
d['page'] = 'admin'
adminurl = baseurl % d
return MailmanTemplate(
'create_result.pt',
mlist=ZPTResults(listname, listinfourl, adminurl))()
--- NEW FILE: do_front.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# This program 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.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
from mailman.cgi.zpt import MailmanTemplate
def process(request, parts):
return MailmanTemplate('front.pt')()
--- NEW FILE: do_listinfo.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# This program 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.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
import logging
from mailman.cgi import do_front
from mailman.cgi.zpt import MailmanTemplate
from mailman.config import configuration
from mailman.mlist import MailList
log = logging.getLogger('mailman.error')
def process(request, parts):
try:
listname = parts.pop(0)
except IndexError:
return do_front.process(request, parts)
domain = configuration.domains.bywebhost[request.getRequestHostname()]
listid = '%s.%s' % (listname, domain)
mlist = MailList(listid)
zpt = MailmanTemplate('listinfo.pt', mlist=mlist)
# See if we're self-posting or not
args = request.args
if not args:
return zpt()
# XXX What to do with posted args...
from pprint import pprint
pprint(args)
--- NEW FILE: do_login.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# This program 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.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
from mailman.cgi.zpt import MailmanTemplate
from mailman.cgi.do_front import process as front
def process(request, parts):
usernames = request.args.get('username')
passwords = request.args.get('password')
if not usernames or not passwords:
return front(request, parts)
# We only care about the first item in the lists
username = usernames[0]
password = passwords[0]
if not username or not password:
return front(request, parts)
return MailmanTemplate('overview_admin.pt')()
--- NEW FILE: do_styles.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# This program 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.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
import os
from mailman.config import configuration
def process(request, parts):
cssfile = parts[0]
fp = open(os.path.join(configuration.layout.templates, 'styles', cssfile))
try:
data = fp.read()
finally:
fp.close()
request.setHeader('Content-Type', 'text/css')
return data
--- NEW FILE: do_varhelp.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# This program 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.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
from mailman.adapters import MailListAdapter, AttributeWrapper
from mailman.categories import allvars
from mailman.cgi import do_login
from mailman.cgi.zpt import MailmanTemplate
from mailman.mlist import MailList
def process(request, parts):
try:
listname = parts.pop(0)
except IndexError:
return do_login.process(request, parts)
varname = parts.pop(0)
domain = request.getRequestHostname()
listid = '%s.%s' % (listname, domain)
mlist = MailList(listid)
prop, category = allvars[varname]
zpt = MailmanTemplate('varhelp.pt',
category=category,
mlist=MailListAdapter(mlist, category),
item=AttributeWrapper(prop, mlist))
# See if we're self posting or not.
args = request.args
if not args:
return zpt()
# Self-posted so process the form arguments, but only for the variable
# being viewed.
for key, val in args.items():
# Ignore form goo
if key == 'submit':
continue
prop, category = allvars.get(key)
if key <> varname or not prop:
web.warning('mischievous form key ignored: %s', key)
continue
try:
pval = prop.parse(val)
except ValueError:
web.warning('bad value for prop %s: %s', key, val)
continue
if pval <> getattr(mlist, key):
setattr(mlist, key, pval)
return zpt()
--- NEW FILE: zpt.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# This program 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.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
import os
from mailman.config import configuration
from mailman.text.safedict import safedict
from mailman.text.strings import dstring
from zope.tales.tales import Context, ExpressionEngine
from zope.tales.expressions import PathExpr, StringExpr, NotExpr, DeferExpr
from zope.tales.pythonexpr import PythonExpr
from zope.pagetemplate.pagetemplatefile import PageTemplateFile
class MailmanContext(Context):
def translate(self, msgid, domain=None, mapping=None, default=None):
# XXX translate msgid
msgstr = unicode(msgid)
pstr = dstring(msgstr)
if mapping is None:
mapping = safedict()
elif not isinstance(mapping, safedict):
mapping = safedict(mapping.items())
return pstr % mapping
## def evaluateMacro(self, macroExpr, macroName):
## # Mailman's ZPT hooks return page templates here, so we need to dig
## # the macro out of the returned object.
## return super(MailmanContext, self).evaluateMacro(macroExpr)
class MailmanEngine(ExpressionEngine):
def getContext(self, contexts=None, **kwcontexts):
return MailmanContext(self, contexts)
class MailmanTemplate(PageTemplateFile):
def __init__(self, filename, **kws):
dir = configuration.layout.templates
super(MailmanTemplate, self).__init__(filename, dir)
self._kws = kws
# We need to override this one so we can return our own engine
def pt_getEngine(self):
self._engine = e = MailmanEngine()
for pt in PathExpr._default_type_names:
e.registerType(pt, PathExpr)
e.registerType('string', StringExpr)
e.registerType('not', NotExpr)
e.registerType('defer', DeferExpr)
e.registerType('python', PythonExpr)
for k, v in self._kws.items():
e.registerBaseName(k, v)
return e
# We need to override this one so we can get our own engine's context
def pt_getEngineContext(self, contexts=None, **kwcontexts):
return self._engine.getContext(contexts, **kwcontexts)
_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org