def publish_module(module_name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ, debug=0, request=None, response=None, extra={}): must_die=0 status=200 after_list=[None] from Response import Response from Request import Request from Publish import publish try: try: if response is None: response=Response(stdout=stdout, stderr=stderr) else: stdout=response.stdout if request is None: request=Request(stdin, environ, response) for k, v in extra.items(): request[k]=v response = publish(request, module_name, after_list, debug=debug) except SystemExit, v: if hasattr(sys, 'exc_info'): must_die=sys.exc_info() else: must_die = SystemExit, v, sys.exc_info()[2] response.exception(must_die) except ImportError, v: if type(v) is type(()) and len(v)==3: must_die=v elif hasattr(sys, 'exc_info'): must_die=sys.exc_info() else: must_die = SystemExit, v, sys.exc_info()[2] response.exception(1, v)
def main(): import sys, os, getopt global repeat_count try: optlist, args = getopt.getopt(sys.argv[1:], 'dtu:p:r:e:s') if len(args) < 1 or len(args) > 2: raise TypeError, None elif len(args) == 1: args = args[0], '/' path_info = args[1] except: sys.stderr.write(__doc__) sys.exit(-1) silent = profile = u = debug = timeit = None env = {} for opt, val in optlist: if opt == '-d': debug = 1 if opt == '-s': silent = 1 if opt == '-t': timeit = 1 if opt == '-u': u = val elif opt == '-p': profile = val elif opt == '-r': repeat_count = int(val) elif opt == '-e': opt = val.find('=') if opt <= 0: raise ValueError, 'Invalid argument to -e: %s' % val env[val[:opt]] = val[opt + 1:] if (debug or 0) + (timeit or 0) + (profile and 1 or 0) > 1: raise ValueError, ( 'Invalid options: only one of -p, -t, and -d are allowed') module = args[0] publish(module, path_info, u=u, p=profile, d=debug, t=timeit, e=env, s=silent)
def main(): import sys, os, getopt global repeat_count try: optlist, args = getopt.getopt(sys.argv[1:], "dtu:p:r:e:s") if len(args) < 1 or len(args) > 2: raise TypeError, None elif len(args) == 1: args = args[0], "/" path_info = args[1] except: sys.stderr.write(__doc__) sys.exit(-1) silent = profile = u = debug = timeit = None env = {} for opt, val in optlist: if opt == "-d": debug = 1 if opt == "-s": silent = 1 if opt == "-t": timeit = 1 if opt == "-u": u = val elif opt == "-p": profile = val elif opt == "-r": repeat_count = int(val) elif opt == "-e": opt = val.find("=") if opt <= 0: raise ValueError, "Invalid argument to -e: %s" % val env[val[:opt]] = val[opt + 1 :] if (debug or 0) + (timeit or 0) + (profile and 1 or 0) > 1: raise ValueError, ("Invalid options: only one of -p, -t, and -d are allowed") module = args[0] publish(module, path_info, u=u, p=profile, d=debug, t=timeit, e=env, s=silent)
def main(): import sys, os, getopt global repeat_count try: optlist,args=getopt.getopt(sys.argv[1:], 'dtu:p:r:e:s') if len(args) < 1 or len(args) > 2: raise TypeError, None elif len(args)==1: args=args[0],'/' path_info=args[1] except: sys.stderr.write(__doc__) sys.exit(-1) silent=profile=u=debug=timeit=None env={} for opt,val in optlist: if opt=='-d': debug=1 if opt=='-s': silent=1 if opt=='-t': timeit=1 if opt=='-u': u=val elif opt=='-p': profile=val elif opt=='-r': repeat_count=int(val) elif opt=='-e': opt=val.find('=') if opt <= 0: raise ValueError, 'Invalid argument to -e: %s' % val env[val[:opt]]=val[opt+1:] if (debug or 0)+(timeit or 0)+(profile and 1 or 0) > 1: raise ValueError, ( 'Invalid options: only one of -p, -t, and -d are allowed') module=args[0] publish(module,path_info,u=u,p=profile,d=debug,t=timeit,e=env, s=silent)
def publish_module_pm(module_name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ, debug=0,extra={}): from Response import Response from Request import Request from Publish import publish after_list=[None] response=Response(stdout=stdout, stderr=stderr) request=Request(stdin, environ, response) for k, v in extra.items(): request[k]=v response = publish(request, module_name, after_list, debug=debug)
def publish_module_pm(module_name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ, debug=0, extra={}): from Response import Response from Request import Request from Publish import publish after_list = [None] response = Response(stdout=stdout, stderr=stderr) request = Request(stdin, environ, response) for k, v in extra.items(): request[k] = v response = publish(request, module_name, after_list, debug=debug)
def publish_module( module_name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ, debug=0, request=None, response=None, extra={}, ): must_die = 0 status = 200 after_list = [None] from Response import Response from Request import Request from Publish import publish try: try: if response is None: response = Response(stdout=stdout, stderr=stderr) else: stdout = response.stdout if request is None: request = Request(stdin, environ, response) # make sure that the request we hand over has the # default layer/skin set on it; subsequent code that # wants to look up views will likely depend on it from zope.app.publication.browser import setDefaultSkin setDefaultSkin(request) for k, v in extra.items(): request[k] = v response = publish(request, module_name, after_list, debug=debug) except SystemExit, v: must_die = sys.exc_info() response.exception(must_die) except ImportError, v: if isinstance(v, TupleType) and len(v) == 3: must_die = v else: must_die = sys.exc_info() response.exception(1, v)
def publish_module(module_name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ, debug=0, request=None, response=None, extra={}): must_die = 0 status = 200 after_list = [None] from Response import Response from Request import Request from Publish import publish try: try: if response is None: response = Response(stdout=stdout, stderr=stderr) else: stdout = response.stdout if request is None: request = Request(stdin, environ, response) # make sure that the request we hand over has the # default layer/skin set on it; subsequent code that # wants to look up views will likely depend on it from zope.publisher.browser import setDefaultSkin setDefaultSkin(request) for k, v in extra.items(): request[k] = v response = publish(request, module_name, after_list, debug=debug) except SystemExit, v: must_die = sys.exc_info() response.exception(must_die) except ImportError, v: if isinstance(v, TupleType) and len(v) == 3: must_die = v else: must_die = sys.exc_info() response.exception(1, v)
def publish_module(module_name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ, debug=0, request=None, response=None, extra={}): must_die=0 status=200 after_list=[None] from Response import Response from Request import Request from Publish import publish from zope.publisher.interfaces import ISkinnable from zope.publisher.skinnable import setDefaultSkin try: try: if response is None: response=Response(stdout=stdout, stderr=stderr) else: stdout=response.stdout # debug is just used by tests (has nothing to do with debug_mode!) response.handle_errors = not debug if request is None: request=Request(stdin, environ, response) # make sure that the request we hand over has the # default layer/skin set on it; subsequent code that # wants to look up views will likely depend on it if ISkinnable.providedBy(request): setDefaultSkin(request) for k, v in extra.items(): request[k]=v response = publish(request, module_name, after_list, debug=debug) except (SystemExit, ImportError): # XXX: Rendered ImportErrors were never caught here because they # were re-raised as string exceptions. Maybe we should handle # ImportErrors like all other exceptions. Currently they are not # re-raised at all, so they don't show up here. must_die = sys.exc_info() request.response.exception(1) except: # debug is just used by tests (has nothing to do with debug_mode!) if debug: raise request.response.exception() status = response.getStatus() if response: outputBody=getattr(response, 'outputBody', None) if outputBody is not None: outputBody() else: response=str(response) if response: stdout.write(response) # The module defined a post-access function, call it if after_list[0] is not None: after_list[0]() finally: if request is not None: request.close() 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] finally: must_die=None return status
def publish_module(module_name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ, debug=0, request=None, response=None, extra={}): must_die = 0 status = 200 after_list = [None] from Response import Response from Request import Request from Publish import publish from zope.publisher.interfaces import ISkinnable from zope.publisher.skinnable import setDefaultSkin try: try: if response is None: response = Response(stdout=stdout, stderr=stderr) else: stdout = response.stdout # debug is just used by tests (has nothing to do with debug_mode!) response.handle_errors = not debug if request is None: request = Request(stdin, environ, response) # make sure that the request we hand over has the # default layer/skin set on it; subsequent code that # wants to look up views will likely depend on it if ISkinnable.providedBy(request): setDefaultSkin(request) for k, v in extra.items(): request[k] = v response = publish(request, module_name, after_list, debug=debug) except (SystemExit, ImportError): # XXX: Rendered ImportErrors were never caught here because they # were re-raised as string exceptions. Maybe we should handle # ImportErrors like all other exceptions. Currently they are not # re-raised at all, so they don't show up here. must_die = sys.exc_info() request.response.exception(1) except: # debug is just used by tests (has nothing to do with debug_mode!) if debug: raise request.response.exception() status = response.getStatus() if response: outputBody = getattr(response, 'outputBody', None) if outputBody is not None: outputBody() else: response = str(response) if response: stdout.write(response) # The module defined a post-access function, call it if after_list[0] is not None: after_list[0]() finally: if request is not None: request.close() 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] finally: must_die = None return status