Commit e1717745 authored by Jeffrey Shell's avatar Jeffrey Shell

Added custom error message support

parent 69f09184
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
__doc__='''Application support __doc__='''Application support
$Id: Application.py,v 1.55 1998/03/09 19:37:09 jim Exp $''' $Id: Application.py,v 1.56 1998/03/23 15:01:22 jeffrey Exp $'''
__version__='$Revision: 1.55 $'[11:-2] __version__='$Revision: 1.56 $'[11:-2]
import Globals,Folder,os,regex,sys import Globals,Folder,os,regex,sys
...@@ -24,6 +24,11 @@ from App.ApplicationManager import ApplicationManager ...@@ -24,6 +24,11 @@ from App.ApplicationManager import ApplicationManager
from Persistence import Persistent from Persistence import Persistent
from ImageFile import ImageFile from ImageFile import ImageFile
_standard_error_msg='''\
<!--#var standard_html_header-->
<H2>Error: <!--#var error_type-->, <!--#var error_value--></H2>
<!-- <!--#var error_tb--> -->
<!--#var standard_html_footer-->'''
class Application(Folder.Folder): class Application(Folder.Folder):
title ='Principia' title ='Principia'
...@@ -74,6 +79,7 @@ class Application(Folder.Folder): ...@@ -74,6 +79,7 @@ class Application(Folder.Folder):
_reserved_names=('standard_html_header', _reserved_names=('standard_html_header',
'standard_html_footer', 'standard_html_footer',
#'standard_error_message',
'acl_users', 'acl_users',
'Control_Panel') 'Control_Panel')
...@@ -94,6 +100,9 @@ class Application(Folder.Folder): ...@@ -94,6 +100,9 @@ class Application(Folder.Folder):
self.manage_addDocument('standard_html_footer', self.manage_addDocument('standard_html_footer',
'Standard Html Footer', 'Standard Html Footer',
'</BODY></HTML>') '</BODY></HTML>')
self.manage_addDocument('standard_error_message',
'Standard Error Message',
_standard_error_msg)
def id(self): def id(self):
...@@ -178,6 +187,11 @@ def open_bobobase(): ...@@ -178,6 +187,11 @@ def open_bobobase():
cpl._init() cpl._init()
app._setObject('Control_Panel', cpl) app._setObject('Control_Panel', cpl)
get_transaction().commit() get_transaction().commit()
if not hasattr(app, 'standard_error_message'):
app.manage_addDocument('standard_error_message',
'Standard Error Message',
_standard_error_msg)
get_transaction().commit()
return Bobobase return Bobobase
...@@ -364,6 +378,9 @@ class Misc_: ...@@ -364,6 +378,9 @@ class Misc_:
############################################################################## ##############################################################################
# #
# $Log: Application.py,v $ # $Log: Application.py,v $
# Revision 1.56 1998/03/23 15:01:22 jeffrey
# Added custom error message support
#
# Revision 1.55 1998/03/09 19:37:09 jim # Revision 1.55 1998/03/09 19:37:09 jim
# Check for true need_license before doing license check. # Check for true need_license before doing license check.
# #
......
"""Document object""" """Document object"""
__version__='$Revision: 1.45 $'[11:-2] __version__='$Revision: 1.46 $'[11:-2]
from Globals import HTML, HTMLFile, MessageDialog from Globals import HTML, HTMLFile, MessageDialog
from string import join,split,strip,rfind,atoi from string import join,split,strip,rfind,atoi,lower
from AccessControl.Role import RoleManager from AccessControl.Role import RoleManager
from SimpleItem import Item_w__name__ from SimpleItem import Item_w__name__
from Acquisition import Explicit from Acquisition import Explicit
import regex, Globals import regex, Globals, sys
class Document(HTML, Explicit, RoleManager, Item_w__name__): class Document(HTML, Explicit, RoleManager, Item_w__name__):
...@@ -71,7 +71,34 @@ class Document(HTML, Explicit, RoleManager, Item_w__name__): ...@@ -71,7 +71,34 @@ class Document(HTML, Explicit, RoleManager, Item_w__name__):
""" """ """ """
kw['document_id'] =self.id kw['document_id'] =self.id
kw['document_title']=self.title kw['document_title']=self.title
r=apply(HTML.__call__, (self, client, REQUEST), kw) try: r=apply(HTML.__call__, (self, client, REQUEST), kw)
except:
if self.id()=='standard_error_message':
raise sys.exc_type, sys.exc_value, sys.exc_traceback
error_type=sys.exc_type
error_value=sys.exc_value
if lower(error_type) in ('redirect',):
raise error_type, error_value, sys.exc_traceback
if regex.search('[a-zA-Z]>', error_value) > 0:
error_message=error_value
else:
error_message=''
tb=sys.exc_traceback
error_tb=pretty_tb(error_type, error_value, tb)
if client is not None: c=client
else: c=self.aq_parent
try:
s=getattr(c, 'standard_error_message')
v=HTML.__call__(s, c, REQUEST, error_type=error_type,
error_value=error_value,
error_tb=error_tb,
error_message=error_message)
except:
v='Sorry, an error occured'
sys.exc_traceback=tb
tb=None
raise error_type, v, sys.exc_traceback
if RESPONSE is None: return r if RESPONSE is None: return r
return decapitate(r, RESPONSE) return decapitate(r, RESPONSE)
...@@ -270,3 +297,37 @@ def decapitate(html, RESPONSE=None, ...@@ -270,3 +297,37 @@ def decapitate(html, RESPONSE=None,
return html return html
def format_exception(etype,value,tb,limit=None):
import traceback
result=['Traceback (innermost last):']
if limit is None:
if hasattr(sys, 'tracebacklimit'):
limit = sys.tracebacklimit
n = 0
while tb is not None and (limit is None or n < limit):
f = tb.tb_frame
lineno = tb.tb_lineno
co = f.f_code
filename = co.co_filename
name = co.co_name
locals=f.f_locals
result.append(' File %s, line %d, in %s'
% (filename,lineno,name))
try: result.append(' (Object: %s)' %
locals[co.co_varnames[0]].__name__)
except: pass
try: result.append(' (Info: %s)' %
str(locals['__traceback_info__']))
except: pass
tb = tb.tb_next
n = n+1
result.append(join(traceback.format_exception_only(etype, value),
' '))
# sys.exc_type,sys.exc_value,sys.exc_traceback=etype,value,tb
return result
def pretty_tb(t,v,tb):
tb=format_exception(t,v,tb,200)
tb=join(tb,'\n')
return tb
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment