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


Python configparser.NoOptionError方法代码示例

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


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

示例1: parse

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def parse(self):
        """

        :return:
        """
        parser = SafeConfigParser()
        parser.readfp(StringIO(self.obj.content))
        for section in parser.sections():
            try:
                content = parser.get(section=section, option="deps")
                for n, line in enumerate(content.splitlines()):
                    if self.is_marked_line(line):
                        continue
                    if line:
                        req = RequirementsTXTLineParser.parse(line)
                        if req:
                            req.dependency_type = self.obj.file_type
                            self.obj.dependencies.append(req)
            except NoOptionError:
                pass 
开发者ID:pypa,项目名称:pipenv,代码行数:22,代码来源:parser.py

示例2: config_default

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def config_default(option, default=None, type=None, section=cli.name):
    """Guesses a default value of a CLI option from the configuration.

    ::

       @click.option('--locale', default=config_default('locale'))

    """
    def f(option=option, default=default, type=type, section=section):
        config = read_config()
        if type is None and default is not None:
            # detect type from default.
            type = builtins.type(default)
        get_option = option_getter(type)
        try:
            return get_option(config, section, option)
        except (NoOptionError, NoSectionError):
            return default
    return f 
开发者ID:what-studio,项目名称:profiling,代码行数:21,代码来源:__main__.py

示例3: config_flag

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def config_flag(option, value, default=False, section=cli.name):
    """Guesses whether a CLI flag should be turned on or off from the
    configuration.  If the configuration option value is same with the given
    value, it returns ``True``.

    ::

       @click.option('--ko-kr', 'locale', is_flag=True,
                     default=config_flag('locale', 'ko_KR'))

    """
    class x(object):
        def __bool__(self, option=option, value=value,
                     default=default, section=section):
            config = read_config()
            type = builtins.type(value)
            get_option = option_getter(type)
            try:
                return get_option(config, section, option) == value
            except (NoOptionError, NoSectionError):
                return default
        __nonzero__ = __bool__
    return x() 
开发者ID:what-studio,项目名称:profiling,代码行数:25,代码来源:__main__.py

示例4: run

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def run(self):
        self.clientApiHttpServer.setup()
        self.replicationHttpsServer.setup()
        self.pusher.setup()

        internalport = self.cfg.get('http', 'internalapi.http.port')
        if internalport:
            try:
                interface = self.cfg.get('http', 'internalapi.http.bind_address')
            except configparser.NoOptionError:
                interface = '::1'
            self.internalApiHttpServer = InternalApiHttpServer(self)
            self.internalApiHttpServer.setup(interface, int(internalport))

        if self.pidfile:
            with open(self.pidfile, 'w') as pidfile:
                pidfile.write(str(os.getpid()) + "\n")

        self.reactor.run() 
开发者ID:matrix-org,项目名称:sydent,代码行数:21,代码来源:sydent.py

示例5: load

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def load(self, name=None):
        config = configparser.ConfigParser()
        config.read(self._get_config_file())
        try:
            if name is None:
                sections = config.sections()
                if len(sections) < 1:
                    self.credentials = None
                    return
                section_name = sections[-1]
            else:
                section_name = self._section_name(name)
            username = config.get(section_name, "username")
            session_id = config.get(section_name, "session_id")
            database = config.get(section_name, "database")
            server = config.get(section_name, "server")
            self.credentials = mygeotab.Credentials(username, session_id, database, server)
        except configparser.NoSectionError:
            self.credentials = None
        except configparser.NoOptionError:
            self.credentials = None 
开发者ID:Geotab,项目名称:mygeotab-python,代码行数:23,代码来源:cli.py

示例6: get_opt

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def get_opt(self, opt):
        """Get value of option from configuration file

        Parameters
        -----------
        opt : string
            Name of option (e.g. output-file-format)

        Returns
        --------
        value : string
            The value for the option. Returns None if option not present.
        """
        for sec in self.sections:
            try:
                key = self.cp.get(sec, opt)
                if key:
                    return key
            except ConfigParser.NoOptionError:
                pass

        return None 
开发者ID:gwastro,项目名称:pycbc,代码行数:24,代码来源:core.py

示例7: _get_config

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def _get_config():
    """
    Try to read config from the file /etc/privacyidea/apache.conf

    The config values are
        redis = IPAddress:Port
        privacyidea = https://hostname/path
        sslverify = True | filename to CA bundle
        timeout = seconds
    :return: The configuration
    :rtype: dict
    """
    config_file = configparser.ConfigParser()
    config_file.read(CONFIG_FILE)
    PRIVACYIDEA = DEFAULT_PRIVACYIDEA
    SSLVERIFY = DEFAULT_SSLVERIFY
    REDIS = DEFAULT_REDIS
    TIMEOUT = DEFAULT_TIMEOUT
    try:
        PRIVACYIDEA = config_file.get("DEFAULT", "privacyidea") or DEFAULT_PRIVACYIDEA
        SSLVERIFY = config_file.get("DEFAULT", "sslverify") or DEFAULT_SSLVERIFY
        if SSLVERIFY == "False":
            SSLVERIFY = False
        elif SSLVERIFY == "True":
            SSLVERIFY = True
        REDIS = config_file.get("DEFAULT", "redis") or DEFAULT_REDIS
        TIMEOUT = config_file.get("DEFAULT", "timeout") or DEFAULT_TIMEOUT
        TIMEOUT = int(TIMEOUT)
    except configparser.NoOptionError as exx:
        syslog.syslog(syslog.LOG_ERR, "{0!s}".format(exx))
    syslog.syslog(syslog.LOG_DEBUG, "Reading configuration {0!s}, {1!s}, {2!s}".format(
        PRIVACYIDEA, REDIS, SSLVERIFY))
    return PRIVACYIDEA, REDIS, SSLVERIFY, TIMEOUT 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:35,代码来源:privacyidea_apache.py

示例8: test_setup_excludes_sensitive_config

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def test_setup_excludes_sensitive_config(self, setup_experiment):
        config = get_config()
        # Auto detected as sensitive
        config.register("a_password", six.text_type)
        # Manually registered as sensitive
        config.register("something_sensitive", six.text_type, sensitive=True)
        # Not sensitive at all
        config.register("something_normal", six.text_type)

        config.extend(
            {
                "a_password": "secret thing",
                "something_sensitive": "hide this",
                "something_normal": "show this",
            }
        )

        exp_id, dst = setup_experiment(log=mock.Mock())

        # The temp dir should have a config with the sensitive variables missing
        deploy_config = configparser.ConfigParser()
        deploy_config.read(os.path.join(dst, "config.txt"))
        assert deploy_config.get("Parameters", "something_normal") == "show this"
        with raises(configparser.NoOptionError):
            deploy_config.get("Parameters", "a_password")
        with raises(configparser.NoOptionError):
            deploy_config.get("Parameters", "something_sensitive") 
开发者ID:Dallinger,项目名称:Dallinger,代码行数:29,代码来源:test_deployment.py

示例9: _has_profile_for_sso

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def _has_profile_for_sso(aws_profile):
    config = configparser.ConfigParser()
    config.read(os.path.realpath(AWS_CONFIG_PATH))
    section = 'profile {}'.format(aws_profile)

    if section not in config.sections():
        return False

    try:
        config.get(section, 'sso_start_url')
    except configparser.NoOptionError:
        return False

    return True 
开发者ID:dimagi,项目名称:commcare-cloud,代码行数:16,代码来源:aws.py

示例10: _has_valid_v1_session_credentials

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def _has_valid_v1_session_credentials(aws_profile):
    config = configparser.ConfigParser()
    config.read(os.path.realpath(AWS_CREDENTIALS_PATH))
    if aws_profile not in config.sections():
        return False
    try:
        expiration = datetime.strptime(config.get(aws_profile, 'expiration'), "%Y-%m-%dT%H:%M:%SZ")
    except configparser.NoOptionError:
        return False

    return datetime.utcnow() < expiration 
开发者ID:dimagi,项目名称:commcare-cloud,代码行数:13,代码来源:aws.py

示例11: get_PAT_from_file

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def get_PAT_from_file(self, key):
        ensure_dir(AZ_DEVOPS_GLOBAL_CONFIG_DIR)
        logger.debug('Keyring not configured properly or package not found.'
                     'Looking for credentials with key:%s in the file: %s', key, self._PAT_FILE)
        creds_list = self._get_credentials_list()
        try:
            return creds_list.get(key, self._USERNAME)
        except (configparser.NoOptionError, configparser.NoSectionError):
            return None 
开发者ID:Azure,项目名称:azure-devops-cli-extension,代码行数:11,代码来源:credential_store.py

示例12: testConfigCommands

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def testConfigCommands(self):
        self.assertFalse(os.path.exists(local_cfg))

        info = self._runConfigScript(['--help'])
        self.assertEqual(info['rc'], 0)
        self.assertEqual(info['stderr'], '')
        self.assertIn('Get and set configuration values for the worker',
                      info['stdout'])

        info = self._runConfigScript(['list'])
        self.assertEqual(info['rc'], 0)
        self.assertIn('[girder_worker]', info['stdout'])

        info = self._runConfigScript(['get', 'celery', 'app_main'])
        self.assertEqual(info['rc'], 0)
        self.assertEqual(info['stdout'].strip(), 'girder_worker')

        info = self._runConfigScript(['set', 'celery', 'app_main', 'foo'])
        self.assertEqual(info['rc'], 0)

        info = self._runConfigScript(['get', 'celery', 'app_main'])
        self.assertEqual(info['rc'], 0)
        self.assertEqual(info['stdout'].strip(), 'foo')

        info = self._runConfigScript(['rm', 'celery', 'app_main'])
        self.assertEqual(info['rc'], 0)

        with self.assertRaises(NoOptionError):
            self._runConfigScript(['get', 'celery', 'app_main']) 
开发者ID:girder,项目名称:girder_worker,代码行数:31,代码来源:config_test.py

示例13: get_value

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def get_value(cls, section, key):
        try:
            value = cls._translator_config.get(section, key)
        except configparser.NoOptionError:
            raise exception.ConfOptionNotDefined(key=key, section=section)
        except configparser.NoSectionError:
            raise exception.ConfSectionNotDefined(section=section)

        return value 
开发者ID:openstack,项目名称:heat-translator,代码行数:11,代码来源:config.py

示例14: get_all_values

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def get_all_values(cls):
        values = []
        for section in cls._sections:
            try:
                values.extend(cls._translator_config.items(section=section))
            except configparser.NoOptionError:
                raise exception.ConfSectionNotDefined(section=section)

        return values 
开发者ID:openstack,项目名称:heat-translator,代码行数:11,代码来源:config.py

示例15: pre_setup

# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoOptionError [as 别名]
def pre_setup(self):
        """ Make a copy of at the ini files and set the port number and host in the new testing.ini
        """
        self.working_config = self.workspace / self.config_filename

        # We need the other ini files as well here as they may be chained
        for filename in glob.glob(os.path.join(self.config_dir, '*.ini')):
            shutil.copy(filename, self.workspace)

        Path.copy(self.original_config, self.working_config)

        parser = configparser.ConfigParser()
        parser.read(self.original_config)
        parser.set('server:main', 'port', str(self.port))
        parser.set('server:main', 'host', self.hostname)
        [parser.set(section, k, v) for section, cfg in self.extra_config_vars.items() for (k, v) in cfg.items()]
        with open(str(self.working_config), 'w') as fp:
            parser.write(fp)

        try:
            parser.get('app:main', 'url_prefix')
        except configparser.NoOptionError:
            parser.set('app:main', 'url_prefix', '')

        # Set the uri to be the external hostname and the url prefix
        self._uri = "http://%s:%s/%s" % (os.uname()[1], self.port, parser.get('app:main', 'url_prefix')) 
开发者ID:man-group,项目名称:pytest-plugins,代码行数:28,代码来源:pytest_pyramid_server.py


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