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


Python exceptions.ConfigurationError方法代码示例

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


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

示例1: includeme

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def includeme(config):
    if not hasattr(config.registry, 'heartbeats'):
        message = ('kinto-portier should be included once Kinto is initialized. '
                   'Use setting ``kinto.includes`` instead of ``pyramid.includes``'
                   ' or include it manually.')
        raise ConfigurationError(message)

    settings = config.get_settings()

    defaults = {k: v for k, v in DEFAULT_SETTINGS.items() if k not in settings}
    config.add_settings(defaults)

    # Register heartbeat to ping the portier broker.
    config.registry.heartbeats['portier'] = portier_ping

    config.add_api_capability(
        "portier",
        version=__version__,
        description="Authenticate users using Portier.",
        url="https://github.com/Kinto/kinto-portier")

    config.scan('kinto_portier.views') 
开发者ID:Kinto,项目名称:kinto-portier,代码行数:24,代码来源:__init__.py

示例2: test_resource_definition_format_fails_when_wrong

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def test_resource_definition_format_fails_when_wrong():
    resource = 'blahbla/bla'

    with pytest.raises(ConfigurationError):
        utils.parse_resource(resource) 
开发者ID:mozilla-services,项目名称:kinto-amo,代码行数:7,代码来源:test_utils.py

示例3: test_configuration_error_when_blocklist_resource_missing

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def test_configuration_error_when_blocklist_resource_missing(self):
        settings = {
            'amo.preview.addons': '/buckets/blocklists/collections/addons',
            'amo.preview.plugins': '/buckets/blocklists/collections/plugins'
        }

        with pytest.raises(ConfigurationError):
            self.make_app(settings) 
开发者ID:mozilla-services,项目名称:kinto-amo,代码行数:10,代码来源:test_views.py

示例4: test_configuration_error_when_unknown_blocklist_resource_present

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def test_configuration_error_when_unknown_blocklist_resource_present(self):
        settings = {
            'amo.preview.addons': '/buckets/blocklists/collections/addons',
            'amo.preview.plugins': '/buckets/blocklists/collections/plugins',
            'amo.preview.gfx': '/buckets/blocklists/collections/gfx',
            'amo.preview.certificates': '/buckets/blocklists/collections/certificates',
            'amo.preview.unknown': 'should fail',
        }

        with pytest.raises(ConfigurationError):
            self.make_app(settings) 
开发者ID:mozilla-services,项目名称:kinto-amo,代码行数:13,代码来源:test_views.py

示例5: parse_resource

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def parse_resource(resource):
    parts = resource.split('/')
    if len(parts) == 5:
        _, _, bucket, _, collection = parts
    else:
        raise ConfigurationError(ERROR_MSG % resource)
    return {
        'bucket': bucket,
        'collection': collection
    } 
开发者ID:mozilla-services,项目名称:kinto-amo,代码行数:12,代码来源:utils.py

示例6: test_include_fails_if_kinto_was_not_initialized

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def test_include_fails_if_kinto_was_not_initialized(self):
        config = testing.setUp()
        with self.assertRaises(ConfigurationError):
            config.include(includeme) 
开发者ID:Kinto,项目名称:kinto-ldap,代码行数:6,代码来源:test_includeme.py

示例7: test_include_fails_if_ldap_filters_contains_multiple_keys

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def test_include_fails_if_ldap_filters_contains_multiple_keys(self):
        config = testing.setUp()
        settings = config.get_settings()
        settings['ldap.filters'] = '{uid}{mail}'
        kinto.core.initialize(config, '0.0.1')
        with self.assertRaises(ConfigurationError) as e:
            config.include(includeme)
        message = "ldap.filters should take a 'mail' argument only, got: '{uid}{mail}'"
        self.assertEqual(str(e.exception), message) 
开发者ID:Kinto,项目名称:kinto-ldap,代码行数:11,代码来源:test_includeme.py

示例8: test_include_fails_if_ldap_filters_is_missing_the_mail_key

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def test_include_fails_if_ldap_filters_is_missing_the_mail_key(self):
        config = testing.setUp()
        settings = config.get_settings()
        settings['ldap.filters'] = 'toto'
        kinto.core.initialize(config, '0.0.1')
        with self.assertRaises(ConfigurationError) as e:
            config.include(includeme)
        message = "ldap.filters should take a 'mail' argument, got: 'toto'"
        self.assertEqual(str(e.exception), message) 
开发者ID:Kinto,项目名称:kinto-ldap,代码行数:11,代码来源:test_includeme.py

示例9: includeme

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def includeme(config):
    if not hasattr(config.registry, 'heartbeats'):
        message = ('kinto-ldap should be included once Kinto is initialized'
                   ' . Use setting ``kinto.includes`` instead of '
                   '``pyramid.includes`` or include it manually.')
        raise ConfigurationError(message)

    settings = config.get_settings()

    defaults = {k: v for k, v in DEFAULT_SETTINGS.items() if k not in settings}
    config.add_settings(defaults)
    config.add_api_capability(
        "ldap", version=__version__,
        description="Basic Auth user are validated against an LDAP server.",
        url="https://github.com/mozilla-services/kinto-ldap")

    try:
        settings['ldap.filters'].format(mail='test')
    except KeyError:
        msg = "ldap.filters should take a 'mail' argument only, got: %r" % settings['ldap.filters']
        raise ConfigurationError(msg)
    else:
        if settings['ldap.filters'].format(mail='test') == settings['ldap.filters']:
            msg = "ldap.filters should take a 'mail' argument, got: %r" % settings['ldap.filters']
            raise ConfigurationError(msg)

    # Register heartbeat to ping the LDAP server.
    config.registry.heartbeats['ldap'] = ldap_ping

    # LDAP pool connection manager
    conn_options = dict(uri=settings['ldap.endpoint'],
                        size=int(settings['ldap.pool_size']),
                        retry_max=int(settings['ldap.pool_retry_max']),
                        retry_delay=float(settings['ldap.pool_retry_delay']),
                        timeout=int(settings['ldap.pool_timeout']))
    config.registry.ldap_cm = ConnectionManager(**conn_options) 
开发者ID:Kinto,项目名称:kinto-ldap,代码行数:38,代码来源:__init__.py

示例10: test_no_secret_raises_error

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def test_no_secret_raises_error(self):
        from pyramid.exceptions import ConfigurationError
        settings = {}
        self.assertRaises(ConfigurationError, self._makeOne, settings) 
开发者ID:jvanasco,项目名称:pyramid_session_redis,代码行数:6,代码来源:test_util.py

示例11: test_prefix_and_generator_raises_error

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def test_prefix_and_generator_raises_error(self):
        from pyramid.exceptions import ConfigurationError
        settings = {'redis.sessions.secret': 'test',
                    'redis.sessions.prefix': 'test',
                    'redis.sessions.id_generator': 'test'}
        self.assertRaises(ConfigurationError, self._makeOne, settings) 
开发者ID:jvanasco,项目名称:pyramid_session_redis,代码行数:8,代码来源:test_util.py

示例12: includeme

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def includeme(config):
    # Parse resources
    settings = config.get_settings()
    resources = OrderedDict()

    # Configure default settings
    # We are using an OrderedDict to always present the resource in
    # the same order in the capability page, it also helps for tests.
    resources['blocklist'] = OrderedDict()
    resources['blocklist']['addons'] = parse_resource(DEFAULT_ADDONS)
    resources['blocklist']['plugins'] = parse_resource(DEFAULT_PLUGINS)
    resources['blocklist']['gfx'] = parse_resource(DEFAULT_GFX)
    resources['blocklist']['certificates'] = parse_resource(DEFAULT_CERTIFICATES)

    # Read blocklist settings
    for settings_key, settings_value in settings.items():
        if not settings_key.startswith('amo.'):
            continue
        parts = settings_key.split('.', 3)

        if len(parts) == 2:  # amo.addons
            prefix = 'blocklist'
            _, blocklist = parts
        else:  # amo.preview.addons
            _, prefix, blocklist = parts

        resource = resources.setdefault(prefix, OrderedDict())
        resource[blocklist] = parse_resource(settings_value)

    for resource in resources.values():
        inter = set(resource.keys()) & {'addons', 'plugins', 'gfx', 'certificates'}
        if len(inter) != 4:
            raise ConfigurationError("Incomplete blocklist configuration: %s" % inter)

    config.registry.amo_resources = resources

    # Expose capability
    url = "https://github.com/mozilla-services/kinto-amo/"
    desc = "An endpoint to generate v2 and v3 XML blocklist export."
    config.add_api_capability("blocklist-xml", version=__version__,
                              description=desc, url=url, resources=resources)

    config.scan('kinto_amo.views') 
开发者ID:mozilla-services,项目名称:kinto-amo,代码行数:45,代码来源:__init__.py

示例13: _parse_settings

# 需要导入模块: from pyramid import exceptions [as 别名]
# 或者: from pyramid.exceptions import ConfigurationError [as 别名]
def _parse_settings(settings):
    """
    Convenience function to collect settings prefixed by 'redis.sessions' and
    coerce settings to ``int``, ``float``, and ``bool`` as needed.
    """
    keys = [s for s in settings if s.startswith('redis.sessions.')]

    options = {}

    for k in keys:
        param = k.split('.')[-1]
        value = settings[k]
        options[param] = value

    # only required setting
    if 'secret' not in options:
        raise ConfigurationError('redis.sessions.secret is a required setting')

    # coerce bools
    for b in ('cookie_secure', 'cookie_httponly', 'cookie_on_exception',
              'set_redis_ttl', 'python_expires', ):
        if b in options:
            options[b] = asbool(options[b])

    # coerce ints
    for i in ('port', 'db', 'cookie_max_age'):
        if i in options:
            options[i] = int(options[i])

    # allow "None" to be a value for some ints
    for i in ('timeout', 'timeout_trigger'):
        if i in options:
            if options[i] == 'None':
                options[i] = None
            else:
                options[i] = int(options[i])
                if not options[i]:
                    options[i] = None

    # coerce float
    if 'socket_timeout' in options:
        options['socket_timeout'] = float(options['socket_timeout'])

    # check for settings conflict
    if 'prefix' in options and 'id_generator' in options:
        err = 'cannot specify custom id_generator and a key prefix'
        raise ConfigurationError(err)

    # convenience setting for overriding key prefixes
    if 'prefix' in options:
        prefix = options.pop('prefix')
        options['id_generator'] = partial(prefixed_id, prefix=prefix)

    return options 
开发者ID:jvanasco,项目名称:pyramid_session_redis,代码行数:56,代码来源:util.py


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