📄 importer.py
字号:
# Module loading error or some other runtime error. debug = int(config.get("PythonDebug", 0)) try: exc_type, exc_value, exc_traceback = sys.exc_info() result = self.ReportError(exc_type, exc_value, exc_traceback, req=req, phase=phase, hname=hlist.handler, debug=debug) finally: exc_traceback = None return result_callback.ConnectionDispatch = new.instancemethod( ConnectionDispatch, _callback, apache.CallBack)_callback.FilterDispatch = new.instancemethod( FilterDispatch, _callback, apache.CallBack)_callback.HandlerDispatch = new.instancemethod( HandlerDispatch, _callback, apache.CallBack)def IncludeDispatch(self, filter, tag, code): # Setup transient per request modules cache. Note # that this will only actually do anything in this # case if no Python request phase handlers have been # specified. A cleanup handler is registered to # later discard the cache entry if it was created. _setup_request_modules_cache(filter.req) try: try: # Cache the server configuration for the # current request so that it will be # available from within 'import_module()'. config = filter.req.get_config() options = filter.req.get_options() cache = _setup_current_cache(config, options, None) debug = int(config.get("PythonDebug", 0)) if not hasattr(filter.req,"ssi_globals"): filter.req.ssi_globals = {} filter.req.ssi_globals["filter"] = filter class _InstanceInfo: def __init__(self, label, file, cache): self.label = label self.file = file self.cache = cache self.children = {} filter.req.ssi_globals["__file__"] = filter.req.filename filter.req.ssi_globals["__mp_info__"] = _InstanceInfo( None, filter.req.filename, None) filter.req.ssi_globals["__mp_path__"] = [] code = code.replace('\r\n', '\n').rstrip() if tag == 'eval': result = eval(code, filter.req.ssi_globals) if result is not None: filter.write(str(result)) elif tag == 'exec': exec(code, filter.req.ssi_globals) filter.flush() finally: filter.req.ssi_globals["filter"] = None # Restore any previous cached configuration. _setup_current_cache(*cache) except: try: exc_type, exc_value, exc_traceback = sys.exc_info() result = self.ReportError(exc_type, exc_value, exc_traceback, filter=filter, phase=filter.name, hname=filter.req.filename, debug=debug) finally: exc_traceback = None raise return apache.OK_callback.IncludeDispatch = new.instancemethod( IncludeDispatch, _callback, apache.CallBack)def ImportDispatch(self, name): config = apache.main_server.get_config() debug = int(config.get("PythonDebug", "0")) # evaluate pythonpath and set sys.path to # resulting value if not already done if config.has_key("PythonPath"): apache._path_cache_lock.acquire() try: pathstring = config["PythonPath"] if not apache._path_cache.has_key(pathstring): newpath = eval(pathstring) apache._path_cache[pathstring] = None sys.path[:] = newpath finally: apache._path_cache_lock.release() # split module::function l = name.split('::', 1) module_name = l[0] func_name = None if len(l) != 1: func_name = l[1] try: # Setup transient per request modules cache. # Note that this cache will always be thrown # away when the module has been imported. _setup_request_modules_cache() # Import the module. module = import_module(module_name, log=debug) # Optionally call function within module. if func_name: getattr(module, func_name)() finally: # Discard the modules cache entry. _cleanup_request_modules_cache()_callback.ImportDispatch = new.instancemethod( ImportDispatch, _callback, apache.CallBack)def ReportError(self, etype, evalue, etb, conn=None, req=None, filter=None, phase="N/A", hname="N/A", debug=0): try: try: if str(etype) == "exceptions.IOError" \ and str(evalue)[:5] == "Write": # If this is an I/O error while writing to # client, it is probably better not to try to # write to the cleint even if debug is on. # XXX Note that a failure to write back data in # a response should be indicated by a special # exception type which is caught here and not a # generic I/O error as there could be false # positives. See MODPYTHON-92. debug = 0 # Determine which log function we are going # to use to output any messages. if filter and not req: req = filter.req if req: log_error = req.log_error elif conn: log_error = conn.log_error else: log_error = apache.main_server.log_error # Always log the details of any exception. pid = os.getpid() iname = apache.interpreter flags = apache.APLOG_NOERRNO|apache.APLOG_ERR text = "mod_python (pid=%d, interpreter=%s, " % (pid, `iname`) text = text + "phase=%s, handler=%s)" % (`phase`, `hname`) text = text + ": Application error" log_error(text, flags) if req: location = None directory = None context = req.hlist if context: while context.parent != None: context = context.parent location = context.location directory = context.directory hostname = req.server.server_hostname root = req.document_root() log_error('ServerName: %s' % `hostname`, flags) log_error('DocumentRoot: %s' % `root`, flags) log_error('URI: %s' % `req.uri`, flags) log_error('Location: %s' % `location`, flags) log_error('Directory: %s' % `directory`, flags) log_error('Filename: %s' % `req.filename`, flags) log_error('PathInfo: %s' % `req.path_info`, flags) tb = traceback.format_exception(etype, evalue, etb) for line in tb: log_error(line[:-1], flags) if not debug or not req: return apache.HTTP_INTERNAL_SERVER_ERROR output = StringIO.StringIO() req.status = apache.HTTP_INTERNAL_SERVER_ERROR req.content_type = 'text/html' print >> output print >> output, '<pre>' print >> output, 'MOD_PYTHON ERROR' print >> output print >> output, 'ProcessId: %s' % pid print >> output, 'Interpreter: %s' % `iname` if req: print >> output print >> output, 'ServerName: %s' % `hostname` print >> output, 'DocumentRoot: %s' % `root` print >> output print >> output, 'URI: %s' % `req.uri` print >> output, 'Location: %s' % `location` print >> output, 'Directory: %s' % `directory` print >> output, 'Filename: %s' % `req.filename` print >> output, 'PathInfo: %s' % `req.path_info` print >> output print >> output, 'Phase: %s' % `phase` print >> output, 'Handler: %s' % cgi.escape(repr(hname)) print >> output for line in tb: print >> output, cgi.escape(line) modules = _get_request_modules_cache() if modules.ctime != 0: accessed = time.asctime(time.localtime(modules.ctime)) print >> output print >> output, 'MODULE CACHE DETAILS' print >> output print >> output, 'Accessed: %s' % accessed print >> output, 'Generation: %s' % modules.generation print >> output labels = {} keys = modules.keys() for key in keys: module = modules[key] labels[module.__file__] = key keys = labels.keys() keys.sort() for key in keys: label = labels[key] module = modules[label] name = module.__name__ filename = module.__file__ cache = module.__mp_info__.cache ctime = time.asctime(time.localtime(cache.ctime)) mtime = time.asctime(time.localtime(cache.mtime)) atime = time.asctime(time.localtime(cache.atime)) instance = cache.instance generation = cache.generation direct = cache.direct indirect = cache.indirect path = module.__mp_path__ print >> output, '%s {' % name print >> output, ' FileName: %s' % `filename` print >> output, ' Instance: %s' % instance, if instance == 1 and (cache.reload or \ generation > modules.generation): print >> output, '[IMPORT]' elif cache.reload or generation > modules.generation: print >> output, '[RELOAD]' else: print >> output print >> output, ' Generation: %s' % generation, if cache.reload: print >> output, '[ERROR]' else: print >> output if cache.mtime: print >> output, ' Modified: %s' % mtime if cache.ctime: print >> output, ' Imported: %s' % ctime if path: text = ',\n '.join(map(repr, path)) print >> output, ' ModulePath: %s' % text friends = [] children = [] if cache.reload: for child in module.__mp_info__.children: entry = modules[child].__mp_info__.file children.append(entry) else: for child in module.__mp_info__.cache.children: entry = modules[child].__mp_info__.file children.append(entry) for child in module.__mp_info__.children: if child not in module.__mp_info__.cache.children: try: entry = modules[child].__mp_info__.file friends.append(entry) except: try: entry = apache.module_info(child).file friends.append(entry) except: pass children.sort() friends.sort() if children: text = ',\n '.join(map(repr, children)) print >> output, ' Children: %s' % text if friends: text = ',\n '.join(map(repr, friends)) print >> output, ' Friends: %s' % text print >> output, '}' print >> output print >> output, '</pre>' text = output.getvalue() if filter: filter.write(text) filter.flush() else: req.write(text) return apache.DONE except: # When all else fails try and dump traceback # directory standard error and flush it. traceback.print_exc() sys.stderr.flush() finally: etb = None_callback.ReportError = new.instancemethod( ReportError, _callback, apache.CallBack)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -