示例#1
0
class ApwalDispatcher:
    def __init__(self, req, config_file='config.xml'):
        self.req = req
        self.__wwwroot = self.req.document_root()
        self.vhosts = {}
        self.error_handlers = {}
        self.__read_config(os.path.join(self.__wwwroot, config_file))
        self.__load_pluggables()

    def __read_config(self, cfg_file):
        """
		Load configuration file (generally 'config.xml' at web server's document root
		"""
        self.settings = SettingsLoader(cfg_file).read()

    def __load_pluggables(self):
        """
		Load every loadable pluggables
		"""
        vhosts = self.settings.getVhosts()
        for vhost_name in vhosts:
            # for each vhost, load every pluggable defined in configuration
            self.vhosts[vhost_name] = []
            self.error_handlers[vhost_name] = {}
            for plug in vhosts[vhost_name]:
                # for every plug, try to load it
                try:
                    try:
                        # try to load plug from web root
                        a, b, c = find_module(plug['src'], [self.__wwwroot])
                        x = load_module(plug['src'], a, b, c)
                    except ImportError, e:
                        # if not found, try to load from python defined tools
                        # this feature can be useful to load predefined tools
                        # included in some packages, such as apwal.tools
                        x = load_tool(plug['src'])
                    for attr in dir(x):
                        # is pluggable a handler ? (decorated with @main)
                        if is_handler(getattr(x, attr)):
                            try:
                                z = getattr(x, attr)(route=plug['route'],
                                                     request=self.req,
                                                     params=plug['params'])
                                for err_code, method in z.getErrorHandlers():
                                    self.error_handlers[vhost_name][
                                        err_code] = method
                                self.vhosts[vhost_name].append(z)
                            except TypeError, e:
                                raise DebugMsg(plug['src'] + '::' + attr +
                                               "->%s" % e)
                except ImportError, e:
                    # Import error: handle error
                    raise DebugMsg('import error: %s' % e)
                    # TODO: gestion des erreurs
                    pass
示例#2
0
class ApwalDispatcher:

	def __init__(self, req,config_file='config.xml'):
		self.req = req
		self.__wwwroot = self.req.document_root()
		self.vhosts = {}
		self.error_handlers = {}
		self.__read_config(os.path.join(self.__wwwroot,config_file))
		self.__load_pluggables()
	
	def __read_config(self, cfg_file):
		"""
		Load configuration file (generally 'config.xml' at web server's document root
		"""
		self.settings = SettingsLoader(cfg_file).read()
	
	def __load_pluggables(self):
		"""
		Load every loadable pluggables
		"""
		vhosts = self.settings.getVhosts()
		for vhost_name in vhosts:
			# for each vhost, load every pluggable defined in configuration
			self.vhosts[vhost_name] = []
			self.error_handlers[vhost_name] = {}
			for plug in vhosts[vhost_name]:
				# for every plug, try to load it
				try:
					try:
						# try to load plug from web root
						a,b,c=find_module(plug['src'],[self.__wwwroot])
						x=load_module(plug['src'],a,b,c)
					except ImportError,e:
						# if not found, try to load from python defined tools
						# this feature can be useful to load predefined tools
						# included in some packages, such as apwal.tools
						x = load_tool(plug['src'])
					for attr in dir(x):
						# is pluggable a handler ? (decorated with @main)
						if is_handler(getattr(x,attr)):
							try:
								z = getattr(x,attr)(route=plug['route'],request=self.req,params=plug['params'])
								for err_code,method in z.getErrorHandlers():
									self.error_handlers[vhost_name][err_code]=method
								self.vhosts[vhost_name].append(z)
							except TypeError,e:
								raise DebugMsg(plug['src']+'::'+attr+"->%s"%e)
				except ImportError,e:
					# Import error: handle error
					raise DebugMsg('import error: %s'%e)
					# TODO: gestion des erreurs
					pass
示例#3
0
	def __read_config(self, cfg_file):
		"""
		Load configuration file (generally 'config.xml' at web server's document root
		"""
		self.settings = SettingsLoader(cfg_file).read()
示例#4
0
    def __read_config(self, cfg_file):
        """
		Load configuration file (generally 'config.xml' at web server's document root
		"""
        self.settings = SettingsLoader(cfg_file).read()