def getPluginNameAndModuleFromStream(self,
                                         infoFileObject,
                                         candidate_infofile=None):
        """
		Extract the name and module of a plugin from the
		content of the info file that describes it and which
		is stored in ``infoFileObject``.
		
		.. note:: Prefer using ``_extractCorePluginInfo``
		          instead, whenever possible...
		
		.. warning:: ``infoFileObject`` must be a file-like object:
		             either an opened file for instance or a string
		             buffer wrapped in a StringIO instance as another
		             example.
		      
		.. note:: ``candidate_infofile`` must be provided
		          whenever possible to get better error messages.
		
		Return a 3-uple with the name of the plugin, its
		module and the config_parser used to gather the core
		data *in a tuple*, if the required info could be
		localised, else return ``(None,None,None)``.
		
		.. note:: This is supposed to be used internally by subclasses
			      and decorators.
		"""
        # parse the information buffer to get info about the plugin
        config_parser = ConfigParser()
        try:
            if is_py2:
                config_parser.readfp(infoFileObject)
            else:
                config_parser.read_file(infoFileObject)
        except Exception as e:
            log.debug(
                "Could not parse the plugin file '%s' (exception raised was '%s')"
                % (candidate_infofile, e))
            return (None, None, None)
        # check if the basic info is available
        if not config_parser.has_section("Core"):
            log.debug("Plugin info file has no 'Core' section (in '%s')" %
                      candidate_infofile)
            return (None, None, None)
        if not config_parser.has_option(
                "Core", "Name") or not config_parser.has_option(
                    "Core", "Module"):
            log.debug(
                "Plugin info file has no 'Name' or 'Module' section (in '%s')"
                % candidate_infofile)
            return (None, None, None)
        # check that the given name is valid
        name = config_parser.get("Core", "Name")
        name = name.strip()
        if PLUGIN_NAME_FORBIDEN_STRING in name:
            log.debug("Plugin name contains forbiden character: %s (in '%s')" %
                      (PLUGIN_NAME_FORBIDEN_STRING, candidate_infofile))
            return (None, None, None)
        return (name, config_parser.get("Core", "Module"), config_parser)
Esempio n. 2
0
	def getPluginNameAndModuleFromStream(self, infoFileObject, candidate_infofile=None):
		"""
		Extract the name and module of a plugin from the
		content of the info file that describes it and which
		is stored in ``infoFileObject``.
		
		.. note:: Prefer using ``_extractCorePluginInfo``
		          instead, whenever possible...
		
		.. warning:: ``infoFileObject`` must be a file-like object:
		             either an opened file for instance or a string
		             buffer wrapped in a StringIO instance as another
		             example.
		      
		.. note:: ``candidate_infofile`` must be provided
		          whenever possible to get better error messages.
		
		Return a 3-uple with the name of the plugin, its
		module and the config_parser used to gather the core
		data *in a tuple*, if the required info could be
		localised, else return ``(None,None,None)``.
		
		.. note:: This is supposed to be used internally by subclasses
			      and decorators.
		"""
		# parse the information buffer to get info about the plugin
		config_parser = ConfigParser()
		try:
			if is_py2:
				config_parser.readfp(infoFileObject)
			else:
				config_parser.read_file(infoFileObject)
		except Exception as e:
			log.debug("Could not parse the plugin file '%s' (exception raised was '%s')" % (candidate_infofile,e))
			return (None, None, None)
		# check if the basic info is available
		if not config_parser.has_section("Core"):
			log.debug("Plugin info file has no 'Core' section (in '%s')" % candidate_infofile)
			return (None, None, None)
		if not config_parser.has_option("Core","Name") or not config_parser.has_option("Core","Module"):
			log.debug("Plugin info file has no 'Name' or 'Module' section (in '%s')" % candidate_infofile)
			return (None, None, None)
		# check that the given name is valid
		name = config_parser.get("Core", "Name")
		name = name.strip()
		if PLUGIN_NAME_FORBIDEN_STRING in name:
			log.debug("Plugin name contains forbiden character: %s (in '%s')" % (PLUGIN_NAME_FORBIDEN_STRING,
																					candidate_infofile))
			return (None, None, None)
		return (name, config_parser.get("Core", "Module"), config_parser)