当前位置: 首页>>代码示例>>Python>>正文


Python RawConfigParser.sections方法代码示例

本文整理汇总了Python中six.moves.configparser.RawConfigParser.sections方法的典型用法代码示例。如果您正苦于以下问题:Python RawConfigParser.sections方法的具体用法?Python RawConfigParser.sections怎么用?Python RawConfigParser.sections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.configparser.RawConfigParser的用法示例。


在下文中一共展示了RawConfigParser.sections方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CredentialStore

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import sections [as 别名]
class CredentialStore(object):
    def __init__(self, **kwargs):
        self.credential_search_path = [
            os.path.join(os.path.sep, "etc", "cbdefense", "credentials"),
            os.path.join(os.path.expanduser("~"), ".cbdefense", "credentials"),
            os.path.join(".", ".cbdefense", "credentials"),
        ]

        if "credential_file" in kwargs:
            if isinstance(kwargs["credential_file"], six.string_types):
                self.credential_search_path = [kwargs["credential_file"]]
            elif type(kwargs["credential_file"]) is list:
                self.credential_search_path = kwargs["credential_file"]

        self.credentials = RawConfigParser(defaults=default_profile)
        self.credential_files = self.credentials.read(self.credential_search_path)

    def get_credentials(self, profile=None):
        credential_profile = profile or "default"
        if credential_profile not in self.get_profiles():
            raise CredentialError("Cannot find credential profile '%s' after searching in these files: %s." %
                                  (credential_profile, ", ".join(self.credential_search_path)))

        retval = {}
        for k, v in six.iteritems(default_profile):
                retval[k] = self.credentials.get(credential_profile, k)
		
        if not retval["api_key"] or not retval["conn_id"] or not retval["cbd_api_url"]:
            raise CredentialError("API Key and Connector ID not available for profile %s" % credential_profile)

        return Credentials(retval)

    def get_profiles(self):
        return self.credentials.sections()
开发者ID:bigblueswope,项目名称:python-projects,代码行数:36,代码来源:auth.py

示例2: update_providers

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import sections [as 别名]
def update_providers(args, verbose=False):
    filepath = args.data_dir.joinpath('references', 'bibtex', 'BIBFILES.ini')
    p = RawConfigParser()
    with io.open(filepath, encoding='utf-8-sig') as fp:
        p.readfp(fp)

    provider_map = get_map(Provider)
    for section in p.sections():
        sectname = section[:-4] if section.endswith('.bib') else section
        id_ = slug(sectname)
        attrs = {
            'name': p.get(section, 'title'),
            'description': p.get(section, 'description'),
            'abbr': p.get(section, 'abbr'),
        }
        if id_ in provider_map:
            provider = provider_map[id_]
            for a in list(attrs):
                before, after = getattr(provider, a), attrs[a]
                if before == after:
                    del attrs[a]
                else:
                    setattr(provider, a, after)
                    attrs[a] = (before, after)
            if attrs:
                args.log.info('updating provider %s %s' % (slug(id_), sorted(attrs)))
            if verbose:
                for a, (before, after) in attrs.items():
                    before, after = (' '.join(_.split()) for _ in (before, after))
                    if before != after:
                        args.log.info('%s\n%r\n%r' % (a, before, after))
        else:
            args.log.info('adding provider %s' % slug(id_))
            DBSession.add(Provider(id=id_, **attrs))
开发者ID:pombredanne,项目名称:glottolog3,代码行数:36,代码来源:util.py

示例3: check_buildout

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import sections [as 别名]
def check_buildout(script_path):
    """ Are we running from within a buildout which supplies 'zopepy'?
    """
    buildout_cfg = os.path.join(os.path.dirname(script_path), 'buildout.cfg')
    if os.path.exists(buildout_cfg):
        parser = RawConfigParser()
        try:
            parser.read(buildout_cfg)
            return 'zopepy' in parser.sections()
        except ParsingError:
            # zc.buildout uses its own parser and it allows syntax that
            # ConfigParser does not like. Here's one really stupid workaround.
            # The alternative is using the zc.buildout parser, which would
            # introduce a hard dependency.
            zope_py = os.path.join(os.path.dirname(script_path),
                                   'bin', 'zopepy')
            if os.path.isfile(zope_py) and os.access(zope_py, os.X_OK):
                return True
开发者ID:zopefoundation,项目名称:Zope,代码行数:20,代码来源:mkwsgiinstance.py

示例4: GOAProvidersLoader

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import sections [as 别名]
class GOAProvidersLoader(object):
    """
    GOA providers reader
    """
    def __init__(self, providers_file):
        """
        Class initialization
        """
        self.path = providers_file
        self._providers = {}
        self._configparser = RawConfigParser()
        try:
            self._configparser.read(providers_file)
        except IOError as e:
            logging.error(
                'Could not find GOA providers file %s' % providers_file)
            raise e
        except ParsingError as e:
            logging.error(
                'There was an error parsing %s' % providers_file)
            raise e
        except Exception as e:
            logging.error(
                'There was an unknown error parsing %s' % providers_file)
            raise e
        self.read_data()

    def read_data(self):
        for section in self._configparser.sections():
            if section.startswith('Provider '):
                provider = section.split()[1]
                self._providers[provider] = {
                    'name': self.generate_readable_name(provider),
                    'services': {}
                }
                for option in self._configparser.options(section):
                    if option == 'providername':
                        name = self._configparser.get(
                            section, option)
                        self._providers[provider]['name'] = name
                    elif option.endswith('enabled'):
                        service = option[:-7].title() + 'Enabled'
                        name = self.generate_readable_name(service[:-7])
                        enabled = self._configparser.getboolean(
                            section, option)
                        # Generate readable name
                        self._providers[provider]['services'][service] = {
                            'name': name,
                            'enabled': enabled
                        }

    def generate_readable_name(self, identifier):
        """
        Generates readable names for providers and services
        """
        stripped = identifier.strip()
        if stripped:
            return stripped.title().replace('_', ' ')
        else:
            return 'Enabled'

    def get_providers(self):
        return self._providers
开发者ID:fleet-commander,项目名称:fc-admin,代码行数:65,代码来源:goa.py


注:本文中的six.moves.configparser.RawConfigParser.sections方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。