📄 importer.py
字号:
else: object_str = parts[1] # Update 'sys.path'. This will only be done if we # have not encountered the current value of the # 'PythonPath' config previously. 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() # Import module containing target object. Specify # the handler root directory in the search path so # that it is still checked even if 'PythonPath' set. path = [] if directory: path = [directory] module = import_module(module_name, path=path) # Obtain reference to actual target object. object = apache.resolve_object(module, object_str, arg, silent=silent) else: # Handler is the target object. object = handler # Lookup expected status values that allow us to # continue when multiple handlers exist. expected = _status_values.get(default, None) # Default to apache.DECLINED unless in content # handler phase. if not expected or apache.DECLINED not in expected: result = apache.OK else: result = apache.DECLINED if object is not None or not silent: result = _execute_target(config, req, object, arg) # Stop iteration when target object returns a # value other than expected values for the phase. if expected and result not in expected: return (True, result) return (False, result)def ConnectionDispatch(self, conn): """ This is the dispatcher for connection handlers. """ # Determine the default handler name. default_handler = "connectionhandler" # Be cautious and return server error as default. result = apache.HTTP_INTERNAL_SERVER_ERROR # Setup transient per request modules cache. Note # that this cache will always be thrown away when # connection handler returns as there is no way to # transfer ownership and responsibility for # discarding the cache entry to latter handlers. _setup_request_modules_cache() try: try: # Cache the server configuration for the # current request so that it will be # available from within 'import_module()'. config = conn.base_server.get_config() options = conn.base_server.get_options() cache = _setup_current_cache(config, options, None) (aborted, result) = _process_target(config=config, req=None, directory=None, handler=conn.hlist.handler, default=default_handler, arg=conn, silent=0) finally: # Restore any previous cached configuration. # There should not actually be any, but this # will cause the configuration cache entry to # be discarded. _setup_current_cache(*cache) # Also discard the modules cache entry. _cleanup_request_modules_cache() except apache.PROG_TRACEBACK, traceblock: # Program runtime error flagged by the application. debug = int(config.get("PythonDebug", 0)) try: (exc_type, exc_value, exc_traceback) = traceblock result = self.ReportError(exc_type, exc_value, exc_traceback, conn=conn, phase="ConnectionHandler", hname=conn.hlist.handler, debug=debug) finally: exc_traceback = None except: # 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, conn=conn, phase="ConnectionHandler", hname=conn.hlist.handler, debug=debug) finally: exc_traceback = None return resultdef FilterDispatch(self, filter): """ This is the dispatcher for input/output filters. """ # Determine the default handler name. if filter.is_input: default_handler = "inputfilter" else: default_handler = "outputfilter" # 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: directory = filter.dir handler = filter.handler # If directory for filter is not set, # then search back through parents and # inherit value from parent if found. if directory is None: parent = filter.parent while parent is not None: if parent.directory is not None: directory = parent.directory break parent = parent.parent # If directory for filter still not # able to be determined, use the server # document root. if directory is None: directory = filter.req.document_root() # Expand relative addressing shortcuts. if type(handler) == types.StringType: if handler[:2] == './': if directory is not None: handler = os.path.join(directory, handler[2:]) elif handler[:3] == '../': if directory is not None: handler = os.path.join(directory, handler) # 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, directory) (aborted, result) = _process_target(config=config, req=filter.req, directory=directory, handler=handler, default=default_handler, arg=filter, silent=0) if not filter.closed: filter.flush() finally: # Restore any previous cached configuration. _setup_current_cache(*cache) except apache.PROG_TRACEBACK, traceblock: # Program runtime error flagged by the application. debug = int(config.get("PythonDebug", 0)) filter.disable() try: (exc_type, exc_value, exc_traceback) = traceblock result = self.ReportError(exc_type, exc_value, exc_traceback, req=filter.req, filter=filter, phase="Filter (%s)"%filter.name, hname=filter.handler, debug=debug) finally: exc_traceback = None except: # Module loading error or some other runtime error. debug = int(config.get("PythonDebug", 0)) filter.disable() try: exc_type, exc_value, exc_traceback = sys.exc_info() result = self.ReportError(exc_type, exc_value, exc_traceback, req=filter.req, filter=filter, phase="Filter: " + filter.name, hname=filter.handler, debug=debug) finally: exc_traceback = None return apache.OKdef HandlerDispatch(self, req): """ This is the dispatcher for handler phases. """ # Cache name of phase in case something changes it. phase = req.phase # Determine the default handler name. default_handler = phase[len("python"):].lower() # Be cautious and return server error as default. result = apache.HTTP_INTERNAL_SERVER_ERROR # Setup transient per request modules cache. Note # that this will only do something if this is the # first Python request handler phase to be executed. # A cleanup handler is registered to later discard # the cache entry if it needed to be created. _setup_request_modules_cache(req) # Cache configuration for later. config = req.get_config() options = req.get_options() try: (aborted, hlist) = False, req.hlist # The actual handler root is the directory # associated with the handler first in the # chain. This may be a handler which was called # in an earlier phase if the req.add_handler() # method was used. The directory for those that # follow the first may have been overridden by # directory supplied to the req.add_handler() # method. root = hlist.directory parent = hlist.parent while parent is not None: root = parent.directory parent = parent.parent # If directory for handler still not able to be # determined, use the server document root. if root is None: root = req.document_root() # Iterate over the handlers defined for the # current phase and execute each in turn # until the last is reached or prematurely # aborted. while not aborted and hlist.handler is not None: try: cache = None directory = hlist.directory handler = hlist.handler # If directory for handler is not set, # then search back through parents and # inherit value from parent if found. # This directory is that where modules # are searched for first and may not be # the same as the handler root if it # was supplied explicitly to the method # req.add_handler(). if directory is None: parent = hlist.parent while parent is not None: if parent.directory is not None: directory = parent.directory break parent = parent.parent # Expand relative addressing shortcuts. if type(handler) == types.StringType: if handler[:2] == './': if directory is not None: handler = os.path.join(directory, handler[2:]) elif handler[:3] == '../': if directory is not None: handler = os.path.join(directory, handler) # Cache the server configuration for the # current request so that it will be # available from within 'import_module()'. cache = _setup_current_cache(config, options, root) (aborted, result) = _process_target(config=config, req=req, directory=directory, handler=handler, default=default_handler, arg=req, silent=hlist.silent) finally: # Restore any previous cached configuration. _setup_current_cache(*cache) hlist.next() except apache.PROG_TRACEBACK, traceblock: # Program runtime error flagged by the application. debug = int(config.get("PythonDebug", 0)) try: (exc_type, exc_value, exc_traceback) = traceblock result = self.ReportError(exc_type, exc_value, exc_traceback, req=req, phase=phase, hname=hlist.handler, debug=debug) finally: exc_traceback = None except:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -