Commit e7515c33 authored by 's avatar

re-synced publish_module with Publish.publish_module_standard

parent 84deecad
...@@ -99,7 +99,6 @@ DONE_STRING_DEFAULT = '\n%s\n\n' % ('_'*60) ...@@ -99,7 +99,6 @@ DONE_STRING_DEFAULT = '\n%s\n\n' % ('_'*60)
import sys, traceback, profile, os, getopt import sys, traceback, profile, os, getopt
from time import clock from time import clock
repeat_count=100 repeat_count=100
TupleType=type(())
def main(): def main():
import sys, os, getopt import sys, os, getopt
...@@ -181,6 +180,8 @@ def publish_module(module_name, ...@@ -181,6 +180,8 @@ def publish_module(module_name,
from Response import Response from Response import Response
from Request import Request from Request import Request
from Publish import publish from Publish import publish
from zope.publisher.interfaces import ISkinnable
from zope.publisher.skinnable import setDefaultSkin
try: try:
try: try:
if response is None: if response is None:
...@@ -192,31 +193,31 @@ def publish_module(module_name, ...@@ -192,31 +193,31 @@ def publish_module(module_name,
if request is None: if request is None:
request=Request(stdin, environ, response) request=Request(stdin, environ, response)
# make sure that the request we hand over has the
# default layer/skin set on it; subsequent code that # make sure that the request we hand over has the
# wants to look up views will likely depend on it # default layer/skin set on it; subsequent code that
from zope.publisher.interfaces import ISkinnable # wants to look up views will likely depend on it
from zope.publisher.skinnable import setDefaultSkin if ISkinnable.providedBy(request):
if ISkinnable.providedBy(request): setDefaultSkin(request)
setDefaultSkin(request)
for k, v in extra.items(): request[k]=v for k, v in extra.items(): request[k]=v
response = publish(request, module_name, after_list, debug=debug) response = publish(request, module_name, after_list, debug=debug)
except SystemExit, v: except (SystemExit, ImportError):
must_die=sys.exc_info() must_die = sys.exc_info()
response.exception(must_die) request.response.exception(1)
except ImportError, v:
if isinstance(v, TupleType) and len(v)==3: must_die=v
else: must_die=sys.exc_info()
response.exception(1, v)
except: except:
if debug: if debug:
raise raise
response.exception() request.response.exception()
status=response.getStatus() status = response.getStatus()
if response: if response:
response=str(response) outputBody=getattr(response, 'outputBody', None)
if response: stdout.write(response) if outputBody is not None:
outputBody()
else:
response=str(response)
if response: stdout.write(response)
# The module defined a post-access function, call it # The module defined a post-access function, call it
if after_list[0] is not None: after_list[0]() if after_list[0] is not None: after_list[0]()
...@@ -225,6 +226,16 @@ def publish_module(module_name, ...@@ -225,6 +226,16 @@ def publish_module(module_name,
if request is not None: request.close() if request is not None: request.close()
if must_die: if must_die:
# Try to turn exception value into an exit code.
try:
if hasattr(must_die[1], 'code'):
code = must_die[1].code
else: code = int(must_die[1])
except:
code = must_die[1] and 1 or 0
if hasattr(request.response, '_requestShutdown'):
request.response._requestShutdown(code)
try: raise must_die[0], must_die[1], must_die[2] try: raise must_die[0], must_die[1], must_die[2]
finally: must_die=None finally: must_die=None
...@@ -354,7 +365,7 @@ def publish(script=None,path_info='/', ...@@ -354,7 +365,7 @@ def publish(script=None,path_info='/',
if b: exec b in dbdata if b: exec b in dbdata
for b in dbdata['breakpoints']: for b in dbdata['breakpoints']:
if isinstance(b, TupleType): if isinstance(b, tuple):
apply(db.set_break,b) apply(db.set_break,b)
else: else:
fbreak(db,b) fbreak(db,b)
......
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