1- # $Id: client.py,v 1.219 2006-01-25 02:59:27 richard Exp $
1+ # $Id: client.py,v 1.220 2006-02-08 03:47:28 richard Exp $
22
33"""WWW request handler (also used in the stand-alone server).
44"""
@@ -46,6 +46,10 @@ def clean_message_callback(match, ok={'a':1,'i':1,'b':1,'br':1}):
4646 return match .group (1 )
4747 return '<%s>' % match .group (2 )
4848
49+ error_message = '''<h1>An error has occurred</h1>
50+ <p>A problem was encountered processing your request. The tracker maintainers
51+ have been notified of the problem.</p>'''
52+
4953class Client :
5054 '''Instantiate to handle one CGI request.
5155
@@ -302,8 +306,11 @@ def inner_main(self):
302306 self .error_message .append (self ._ ('Form Error: ' ) + str (e ))
303307 self .write_html (self .renderContext ())
304308 except :
305- # everything else
306- self .write_html (cgitb .html (i18n = self .translator ))
309+ if self .db .config .WEB_DEBUG :
310+ self .write_html (cgitb .html (i18n = self .translator ))
311+ else :
312+ self .mailer .exception_message ()
313+ return self .write_html (error_message )
307314
308315 def clean_sessions (self ):
309316 """Age sessions, remove when they haven't been used for a week.
@@ -854,9 +861,10 @@ def header(self, headers=None, response=None):
854861 for entry in headers .items ():
855862 self .request .send_header (* entry )
856863 for ((path , name ), (value , expire )) in self .add_cookies .items ():
857- self .request .send_header ('Set-Cookie' ,
858- "%s=%s; expires=%s; Path=%s;"
859- % (name , value , Cookie ._getdate (expire ), path ))
864+ cookie = "%s=%s; Path=%s;" % (name , value , path )
865+ if expire is not None :
866+ cookie += " expires=%s;" % Cookie ._getdate (expire )
867+ self .request .send_header ('Set-Cookie' , cookie )
860868 self .request .end_headers ()
861869 self .headers_done = 1
862870 if self .debug :
@@ -875,6 +883,7 @@ def add_cookie(self, name, value, expire=86400*365, path=None):
875883 If value is empty (meaning "delete cookie"),
876884 expiration time is forced in the past
877885 and this argument is ignored.
886+ If None, the cookie will expire at end-of-session.
878887 If omitted, the cookie will be kept for a year.
879888 path:
880889 cookie path (optional)
@@ -886,7 +895,7 @@ def add_cookie(self, name, value, expire=86400*365, path=None):
886895 expire = - 1
887896 self .add_cookies [(path , name )] = (value , expire )
888897
889- def set_cookie (self , user ):
898+ def set_cookie (self , user , expire = None ):
890899 """Set up a session cookie for the user.
891900
892901 Also store away the user's login info against the session.
@@ -913,7 +922,7 @@ def set_cookie(self, user):
913922 self .db .commit ()
914923
915924 # add session cookie
916- self .add_cookie (self .cookie_name , self .session )
925+ self .add_cookie (self .cookie_name , self .session , expire = expire )
917926
918927 def make_user_anonymous (self ):
919928 ''' Make us anonymous
0 commit comments