當前位置: 首頁>>代碼示例>>Python>>正文


Python ConfigParser.DuplicateSectionError方法代碼示例

本文整理匯總了Python中ConfigParser.DuplicateSectionError方法的典型用法代碼示例。如果您正苦於以下問題:Python ConfigParser.DuplicateSectionError方法的具體用法?Python ConfigParser.DuplicateSectionError怎麽用?Python ConfigParser.DuplicateSectionError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ConfigParser的用法示例。


在下文中一共展示了ConfigParser.DuplicateSectionError方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import ConfigParser [as 別名]
# 或者: from ConfigParser import DuplicateSectionError [as 別名]
def __init__(self, config_file):
        if sys.version[0] == "2":
            CP.__init__(self)
        else:
            super().__init__()
        if not os.path.exists(config_file):
            raise Exception("Could not find " + config_file)
        f = open(config_file)
        id_string = f.readline().split("=")

        if id_string[0].strip().upper() in ["CAPI", "SAPI"]:
            self.type = id_string[0]
        else:
            raise SyntaxError("Could not find API type in " + config_file)
        try:
            self.version = int(id_string[1].strip())
        except ValueError:
            raise SyntaxError("Unknown version '{}'".format(id_string[1].strip()))

        except IndexError:
            raise SyntaxError("Could not find API version in " + config_file)
        if sys.version[0] == "2":
            exceptions = (configparser.ParsingError, configparser.DuplicateSectionError)
        else:
            exceptions = (
                configparser.ParsingError,
                configparser.DuplicateSectionError,
                configparser.DuplicateOptionError,
            )
        try:
            if sys.version[0] == "2":
                self.readfp(f)
            else:
                self.read_file(f)
        except configparser.MissingSectionHeaderError:
            raise SyntaxError("Missing section header")
        except exceptions as e:
            raise SyntaxError(e.message) 
開發者ID:olofk,項目名稱:fusesoc,代碼行數:40,代碼來源:fusesocconfigparser.py

示例2: get

# 需要導入模塊: import ConfigParser [as 別名]
# 或者: from ConfigParser import DuplicateSectionError [as 別名]
def get(self, section, item):
		result = ''
		try:
			result = self.data_conf.get(section, item)
		except ConfigParser.NoSectionError:
			self.read()
			try:
				self.data_conf.add_section(section)
			except ConfigParser.DuplicateSectionError: pass
			self.data_conf.set(section, item, '')
			self.write()
		except ConfigParser.NoOptionError:
			self.set(section, item, '')
		return result 
開發者ID:sailoog,項目名稱:openplotter,代碼行數:16,代碼來源:conf.py

示例3: test_weird_errors

# 需要導入模塊: import ConfigParser [as 別名]
# 或者: from ConfigParser import DuplicateSectionError [as 別名]
def test_weird_errors(self):
        cf = self.newconfig()
        cf.add_section("Foo")
        self.assertRaises(ConfigParser.DuplicateSectionError,
                          cf.add_section, "Foo") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_cfgparser.py

示例4: test_duplicatesectionerror

# 需要導入模塊: import ConfigParser [as 別名]
# 或者: from ConfigParser import DuplicateSectionError [as 別名]
def test_duplicatesectionerror(self):
        import pickle
        e1 = ConfigParser.DuplicateSectionError('section')
        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            pickled = pickle.dumps(e1, proto)
            e2 = pickle.loads(pickled)
            self.assertEqual(e1.message, e2.message)
            self.assertEqual(e1.args, e2.args)
            self.assertEqual(e1.section, e2.section)
            self.assertEqual(repr(e1), repr(e2)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_cfgparser.py

示例5: test_duplicatesectionerror

# 需要導入模塊: import ConfigParser [as 別名]
# 或者: from ConfigParser import DuplicateSectionError [as 別名]
def test_duplicatesectionerror(self):
        import pickle
        e1 = ConfigParser.DuplicateSectionError('section')
        pickled = pickle.dumps(e1)
        e2 = pickle.loads(pickled)
        self.assertEqual(e1.message, e2.message)
        self.assertEqual(e1.args, e2.args)
        self.assertEqual(e1.section, e2.section)
        self.assertEqual(repr(e1), repr(e2)) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:11,代碼來源:test_cfgparser.py

示例6: ensure_required_groups

# 需要導入模塊: import ConfigParser [as 別名]
# 或者: from ConfigParser import DuplicateSectionError [as 別名]
def ensure_required_groups(self, groups):
        for group in groups:
            try:
                self.debug("Adding group {0}".format(group))
                self.config.add_section(group)
            except configparser.DuplicateSectionError:
                pass 
開發者ID:wso2,項目名稱:streaming-integrator,代碼行數:9,代碼來源:inventory.py

示例7: build_main_config

# 需要導入模塊: import ConfigParser [as 別名]
# 或者: from ConfigParser import DuplicateSectionError [as 別名]
def build_main_config(add_conf, main_config):
    """Build configuration from all found conf files.

    :param add_conf: ``object`` ConfigParser object
    :param main_config: ``object`` ConfigParser object
    """
    for section in add_conf.sections():
        try:
            main_config.add_section(section)
        except ConfigParser.DuplicateSectionError:
            pass

        for k, v in add_conf.items(section):
            main_config.set(section, k, v) 
開發者ID:rcbops,項目名稱:ansible-lxc-rpc,代碼行數:16,代碼來源:pip-link-build.py

示例8: build_install_section

# 需要導入模塊: import ConfigParser [as 別名]
# 或者: from ConfigParser import DuplicateSectionError [as 別名]
def build_install_section(main_dir_path, main_config):
    """Build the install section with links.

    :param main_dir_path: ``str`` Directory path
    :param main_config: ``object`` ConfigParser object
    """
    links = []
    links_dir = os.path.join(main_dir_path, 'links.d')
    if os.path.isdir(links_dir):
        _link = config_files(config_dir_path=links_dir, extension='.link')
        links.extend(pip_links(_link))

    # Add install section if not already found
    try:
        main_config.add_section('install')
    except ConfigParser.DuplicateSectionError:
        pass

    # Get all items from the install section
    try:
        install_items = main_config.items('install')
    except ConfigParser.NoSectionError:
        install_items = None

    link_strings = set_links(links)
    if install_items:
        for item in install_items:
            if item[0] != 'find-links':
                main_config.set('install', *item)

    main_config.set('install', 'find-links', link_strings) 
開發者ID:rcbops,項目名稱:ansible-lxc-rpc,代碼行數:33,代碼來源:pip-link-build.py

示例9: save

# 需要導入模塊: import ConfigParser [as 別名]
# 或者: from ConfigParser import DuplicateSectionError [as 別名]
def save(self, filename=None):
        #TODO: Maybe unused
        """Save configuration settings from the file filename, if filename
        is None then the value from get_configfile() is used

        :param filename: file name to be used for config saving.
        :type filename: str.

        """
        fname = self.get_configfile()
        if filename is not None and len(filename) > 0:
            fname = filename

        if fname is None or len(fname) == 0:
            return

        config = ConfigParser.RawConfigParser()
        try:
            config.add_section(self._sectionname)
        except ConfigParser.DuplicateSectionError:
            pass # ignored

        for key in self._get_ac_keys():
            ackey = '_ac__%s' % key
            config.set(self._sectionname, key, str(self.__dict__[ackey]))

        fileh = open(self._configfile, 'wb')
        config.write(fileh)
        fileh.close() 
開發者ID:HewlettPackard,項目名稱:python-ilorest-library-old,代碼行數:31,代碼來源:config.py


注:本文中的ConfigParser.DuplicateSectionError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。