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


Python voluptuous.Length方法代码示例

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


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

示例1: test_raise_invalid_if_provisioner_schema_is_not_satisfied

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Length [as 别名]
def test_raise_invalid_if_provisioner_schema_is_not_satisfied(self, mock_Provisioner):
        mock_Provisioner.provisioners = {
            'mp1': MockProvisioner1,
            'mp2': MockProvisioner2,
            'mp3': MockProvisioner3}
        schema = get_schema()
        with pytest.raises(Invalid) as e:
            schema({
                'name': 'dummy-test',
                'provisioning': [{
                    'type': 'mp1',
                    'a': 'dummy',
                    'b': '16'
                }, {
                    'type': 'mp2',
                    'a': 'dummydummy',  # Exceeds Length(min=5, max=5)
                }, {
                    'type': 'mp3',
                    'b': 'yes'
                }]
            })
            assert "['provisioning'][1]['a']" in str(e) 
开发者ID:lxdock,项目名称:lxdock,代码行数:24,代码来源:test_schema.py

示例2: _init_schema

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Length [as 别名]
def _init_schema(self):
        self._schema = {
            Required('key_file'): str,
            Required('cert_file'): str,
            Required('base_url'): Url(),
            'host': str,
            'port': Any(int, str),
            'debug': bool,
            'https': bool,
            'https_cert_file': str,
            'https_key_file': str,
            'users_file': str,
            'behind_reverse_proxy': bool,
            'can_add_user': bool,
            'storage': All(str, In(['file', 'postgres'])),
            'db_url': str,
            'endpoints': {
                'single_logout_service': str,
                'single_sign_on_service': str,
            },
            'metadata': {
                'local': All([str], Length(min=0)),
                'remote': All([str], Length(min=0)),
            }
        } 
开发者ID:italia,项目名称:spid-testenv2,代码行数:27,代码来源:config.py

示例3: schema_ext

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Length [as 别名]
def schema_ext(self):
        return voluptuous.All(six.text_type,
                              voluptuous.Length(
                                  min=self.min_length,
                                  max=self.max_length)) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:7,代码来源:resource_type.py

示例4: MetricSchema

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Length [as 别名]
def MetricSchema(v):
    """metric keyword schema

    It could be:

    ["metric", "metric-ref", "aggregation"]

    or

    ["metric, ["metric-ref", "aggregation"], ["metric-ref", "aggregation"]]
    """
    if not isinstance(v, (list, tuple)):
        raise voluptuous.Invalid("Expected a tuple/list, got a %s" % type(v))
    elif not v:
        raise voluptuous.Invalid("Operation must not be empty")
    elif len(v) < 2:
        raise voluptuous.Invalid("Operation need at least one argument")
    elif v[0] != u"metric":
        # NOTE(sileht): this error message doesn't looks related to "metric",
        # but because that the last schema validated by voluptuous, we have
        # good chance (voluptuous.Any is not predictable) to print this
        # message even if it's an other operation that invalid.
        raise voluptuous.Invalid("'%s' operation invalid" % v[0])

    return [u"metric"] + voluptuous.Schema(voluptuous.Any(
        voluptuous.ExactSequence([six.text_type, six.text_type]),
        voluptuous.All(
            voluptuous.Length(min=1),
            [voluptuous.ExactSequence([six.text_type, six.text_type])],
        )), required=True)(v[1:]) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:32,代码来源:api.py

示例5: __init__

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Length [as 别名]
def __init__(self, allow_extra):
        self.schema = v.Schema(
            {
                v.Required('id'): int,
                v.Required('client_name'): v.All(str, v.Length(max=255)),
                v.Required('sort_index'): float,
                # v.Optional('client_email'): v.Maybe(v.Email),
                v.Optional('client_phone'): v.Maybe(v.All(str, v.Length(max=255))),
                v.Optional('location'): v.Maybe(
                    v.Schema(
                        {
                            'latitude': v.Maybe(float),
                            'longitude': v.Maybe(float)
                        },
                        required=True
                    )
                ),
                v.Optional('contractor'): v.Maybe(v.All(v.Coerce(int), v.Range(min=1))),
                v.Optional('upstream_http_referrer'): v.Maybe(v.All(str, v.Length(max=1023))),
                v.Required('grecaptcha_response'): v.All(str, v.Length(min=20, max=1000)),
                v.Optional('last_updated'): v.Maybe(parse_datetime),
                v.Required('skills', default=[]): [
                    v.Schema(
                        {
                            v.Required('subject'): str,
                            v.Required('subject_id'): int,
                            v.Required('category'): str,
                            v.Required('qual_level'): str,
                            v.Required('qual_level_id'): int,
                            v.Required('qual_level_ranking', default=0): float,
                        }
                    )
                ],
            },
            extra=allow_extra,
        ) 
开发者ID:samuelcolvin,项目名称:pydantic,代码行数:38,代码来源:test_voluptuous.py

示例6: MetricSchema

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Length [as 别名]
def MetricSchema(definition):
        creator = pecan.request.auth_helper.get_current_user(
            pecan.request)

        # First basic validation
        schema = voluptuous.Schema({
            "archive_policy_name": six.text_type,
            "resource_id": functools.partial(ResourceID, creator=creator),
            "name": six.text_type,
            voluptuous.Optional("unit"):
            voluptuous.All(six.text_type, voluptuous.Length(max=31)),
        })
        definition = schema(definition)
        archive_policy_name = definition.get('archive_policy_name')

        name = definition.get('name')
        if name and '/' in name:
            abort(400, "'/' is not supported in metric name")
        if archive_policy_name is None:
            try:
                ap = pecan.request.indexer.get_archive_policy_for_metric(name)
            except indexer.NoArchivePolicyRuleMatch:
                # NOTE(jd) Since this is a schema-like function, we
                # should/could raise ValueError, but if we do so, voluptuous
                # just returns a "invalid value" with no useful message – so we
                # prefer to use abort() to make sure the user has the right
                # error message
                abort(400, "No archive policy name specified "
                      "and no archive policy rule found matching "
                      "the metric name %s" % name)
            else:
                definition['archive_policy_name'] = ap.name

        resource_id = definition.get('resource_id')
        if resource_id is None:
            original_resource_id = None
        else:
            if name is None:
                abort(400,
                      {"cause": "Attribute value error",
                       "detail": "name",
                       "reason": "Name cannot be null "
                       "if resource_id is not null"})
            original_resource_id, resource_id = resource_id

        enforce("create metric", {
            "creator": creator,
            "archive_policy_name": archive_policy_name,
            "resource_id": resource_id,
            "original_resource_id": original_resource_id,
            "name": name,
            "unit": definition.get('unit'),
        })

        return definition 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:57,代码来源:api.py

示例7: _ResourceSearchSchema

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Length [as 别名]
def _ResourceSearchSchema():
    user = pecan.request.auth_helper.get_current_user(
        pecan.request)
    _ResourceUUID = functools.partial(ResourceUUID, creator=user)

    return voluptuous.Schema(
        voluptuous.All(
            voluptuous.Length(min=0, max=1),
            {
                voluptuous.Any(
                    u"=", u"==", u"eq",
                    u"<", u"lt",
                    u">", u"gt",
                    u"<=", u"≤", u"le",
                    u">=", u"≥", u"ge",
                    u"!=", u"≠", u"ne",
                ): voluptuous.All(
                    voluptuous.Length(min=1, max=1),
                    {"id": _ResourceUUID,
                     NotIDKey: ResourceSearchSchemaAttributeValue},
                ),
                u"like": voluptuous.All(
                    voluptuous.Length(min=1, max=1),
                    {NotIDKey: ResourceSearchSchemaAttributeValue},
                ),
                u"in": voluptuous.All(
                    voluptuous.Length(min=1, max=1),
                    {"id": voluptuous.All(
                        [_ResourceUUID],
                        voluptuous.Length(min=1)),
                     NotIDKey: voluptuous.All(
                         [ResourceSearchSchemaAttributeValue],
                         voluptuous.Length(min=1))}
                ),
                voluptuous.Any(
                    u"and", u"∨",
                    u"or", u"∧",
                ): voluptuous.All(
                    [ResourceSearchSchema], voluptuous.Length(min=1)
                ),
                u"not": ResourceSearchSchema,
            }
        )
    ) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:46,代码来源:api.py


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