Back to index

plone3  3.1.7
browserview.py
Go to the documentation of this file.
00001 # Copyright (c) 2006-2007
00002 # Authors: KSS Project Contributors (see docs/CREDITS.txt)
00003 #
00004 # This program is free software; you can redistribute it and/or modify
00005 # it under the terms of the GNU General Public License version 2 as published
00006 # by the Free Software Foundation.
00007 #
00008 # This program is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 # GNU General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU General Public License
00014 # along with this program; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00016 # 02111-1307, USA.
00017 #
00018 
00019 import cgi, warnings
00020 
00021 try:
00022     from Products.Five import BrowserView
00023 except ImportError:
00024     from zope.app.publisher.browser import BrowserView
00025 from zope.pagetemplate.pagetemplatefile import PageTemplateFile
00026 
00027 class KSSBrowserView(BrowserView):
00028 
00029     # XML output gets rendered via a page template
00030     # XXX note: barefoot rendering, use python: only after zope2.9
00031     render_error = PageTemplateFile('browser/errorresponse.pt')
00032 
00033     def attach_error(self, err_type, err_value):
00034         'Attach the error payload on the response'
00035         message = '%s: %s' % (err_type, err_value)
00036         message = cgi.escape(message)
00037         payload = self.render_error(type='system', message=message)
00038         self.attach_payload(payload)
00039 
00040     def attach_payload(self, payload, header_name='X-KSSCOMMANDS'):
00041         'Attach the commands on the response'
00042         # get rid of newlines
00043         payload = payload.replace('\n', ' ')
00044         self.request.response.setHeader(header_name, payload)
00045 
00046 # coherent naming KSS 
00047 # deprecate Kss
00048 class KssBrowserView(KSSBrowserView):
00049     def __init__(self, *args, **kw):
00050         message = "'KssBrowserView' is deprecated," \
00051             "use 'KSSBrowserView'- KSS uppercase instead."
00052         warnings.warn(message, DeprecationWarning, 2)
00053         KSSBrowserView.__init__(self, *args, **kw)
00054