Commit c30829ba authored by Jim Fulton's avatar Jim Fulton

fixed error handling problems

parent 00a0ec19
......@@ -72,7 +72,7 @@ that allows one to simply make a single web request.
The module also provides a command-line interface for calling objects.
"""
__version__='$Revision: 1.24 $'[11:-2]
__version__='$Revision: 1.25 $'[11:-2]
import sys, regex, socket, mimetools
from httplib import HTTP
......@@ -185,8 +185,8 @@ class Function:
ec,em,headers=h.getreply()
response =h.getfile().read()
except:
raise NotAvailable, \
RemoteException(NotAvailable,sys.exc_value,self.url,query)
raise NotAvailable, RemoteException(
NotAvailable,sys.exc_value,self.url,query)
if ec==200: return (headers,response)
self.handleError(query, ec, em, headers, response)
......@@ -588,7 +588,6 @@ def main():
kw[name]=v
except:
# print "%s: %s\n%s" % (sys.exc_type, sys.exc_value, usage)
print usage
sys.exit(1)
......
......@@ -478,11 +478,11 @@ Publishing a module using CGI
containing the module to be published) to the module name in the
cgi-bin directory.
$Id: Publish.py,v 1.92 1998/09/03 14:50:17 jim Exp $"""
$Id: Publish.py,v 1.93 1998/09/03 16:59:11 jim Exp $"""
#'
#
##########################################################################
__version__='$Revision: 1.92 $'[11:-2]
__version__='$Revision: 1.93 $'[11:-2]
import sys, os, string, cgi, regex
from string import *
......@@ -646,7 +646,7 @@ class ModulePublisher:
raise 'NotFound',self.html(
"Resource not found",
"Sorry, the requested document does not exist.<p>"
"\n<!--\n%s\n-->" % entry), sys.exc_traceback
"\n<!--\n%s\n-->" % entry)
forbiddenError=notFoundError # If a resource is forbidden,
# why reveal that it exists?
......@@ -953,6 +953,7 @@ def get_module_info(module_name, modules={},
if module_name[-4:]=='.cgi': module_name=module_name[:-4]
acquire()
tb=None
try:
try:
module=__import__(module_name)
......@@ -1015,9 +1016,13 @@ def get_module_info(module_name, modules={},
return info
except:
raise ImportError, (
sys.exc_type, sys.exc_value, sys.exc_traceback)
finally: release()
if hasattr(sys, 'exc_info'): t,v,tb=sys.exc_info()
else: t, v, tb = sys.exc_type, sys.exc_value, sys.exc_traceback
v=str(v)
raise ImportError, (t, v), tb
finally:
tb=None
release()
def str_field(v):
if type(v) is ListType:
......@@ -1448,14 +1453,15 @@ def publish_module(module_name,
pass
response = publisher.publish(module_name,after_list,
debug=debug)
except SystemExit:
must_die=1
except SystemExit, v:
if hasattr(sys, 'exc_info'): must_die=sys.exc_info()
else: must_die = SystemExit, v, sys.exc_traceback
response.exception(must_die)
except ImportError, v:
if type(v)==TupleType and len(v)==3:
sys.exc_type, sys.exc_value, sys.exc_traceback = v
must_die=1
response.exception(must_die)
if type(v) is tyoe(()) and len(v)==3: must_die=v
elif hasattr(sys, 'exc_info'): must_die=sys.exc_info()
else: must_die = SystemExit, v, sys.exc_traceback
response.exception(1, v)
except:
response.exception()
status=response.getStatus()
......@@ -1469,8 +1475,7 @@ def publish_module(module_name,
finally:
if request is not None: request.other={}
if must_die:
raise sys.exc_type, sys.exc_value, sys.exc_traceback
if must_die: raise must_die[0], must_die[1], must_die[2]
sys.exc_type, sys.exc_value, sys.exc_traceback = None, None, None
return status
'''CGI Response Output formatter
$Id: Response.py,v 1.36 1998/09/03 14:50:16 jim Exp $'''
$Id: Response.py,v 1.37 1998/09/03 16:59:10 jim Exp $'''
#
# Copyright (c) 1998, Digital Creations, Fredericksburg, VA, USA.
# All rights reserved.
......@@ -51,7 +51,7 @@ $Id: Response.py,v 1.36 1998/09/03 14:50:16 jim Exp $'''
#
# (540) 371-6909
#
__version__='$Revision: 1.36 $'[11:-2]
__version__='$Revision: 1.37 $'[11:-2]
import string, types, sys, regex
from string import find, rfind, lower, upper, strip, split, join, translate
......@@ -412,7 +412,6 @@ class Response:
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 _traceback(self,t,v,tb):
......@@ -429,13 +428,16 @@ class Response:
headers['location']=location
return location
def exception(self, fatal=0,
def exception(self, fatal=0, info=None,
absuri_match=regex.compile(
"[a-zA-Z0-9+.-]+:[^\0- \"\#<>]+\(#[^\0- \"\#<>]*\)?"
).match,
tag_search=regex.compile('[a-zA-Z]>').search,
):
t,v,tb=sys.exc_type, sys.exc_value,sys.exc_traceback
if type(info) is type(()) and len(info)==3: t,v,tb = info
elif hasattr(sys, 'exc_info'): t,v,tb = sys.exc_info()
else: t,v,tb = sys.exc_type, sys.exc_value, sys.exc_traceback
stb=tb
# Abort running transaction, if any:
......
......@@ -130,9 +130,9 @@ Examples
s
$Id: Test.py,v 1.18 1998/09/03 14:50:17 jim Exp $
$Id: Test.py,v 1.19 1998/09/03 16:59:11 jim Exp $
'''
__version__='$Revision: 1.18 $'[11:-2]
__version__='$Revision: 1.19 $'[11:-2]
import sys,traceback, profile, os
repeat_count=100
......@@ -229,6 +229,11 @@ def publish_module_pm(module_name,
except: pass
if after_list[0] is not None: after_list[0]()
try: from codehack import getlineno
except:
def getlineno(code):
return code.co_firstlineno
def publish(script,path_info,u=None,p=None,d=None,t=None,e={},s=None,pm=0):
import sys, os, getopt, string
......@@ -307,14 +312,13 @@ def publish(script,path_info,u=None,p=None,d=None,t=None,e={},s=None,pm=0):
self.do_c('')
self.done_ob=1
import codehack
db=Pdb()
def fbreak(db,meth,codehack=codehack):
def fbreak(db,meth):
try: meth=meth.im_func
except AttributeError: pass
code=meth.func_code
lineno = codehack.getlineno(code)
lineno = getlineno(code)
filename = code.co_filename
db.set_break(filename,lineno)
......
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