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


Python voluptuous.Range方法代码示例

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


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

示例1: get_pagination_options

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Range [as 别名]
def get_pagination_options(params, default):
    try:
        opts = voluptuous.Schema({
            voluptuous.Required(
                "limit", default=pecan.request.conf.api.max_limit):
            voluptuous.All(voluptuous.Coerce(int),
                           voluptuous.Range(min=1),
                           voluptuous.Clamp(
                               min=1, max=pecan.request.conf.api.max_limit)),
            "marker": six.text_type,
            voluptuous.Required("sort", default=default):
            voluptuous.All(
                voluptuous.Coerce(arg_to_list),
                [six.text_type]),
        }, extra=voluptuous.REMOVE_EXTRA)(params)
    except voluptuous.Invalid as e:
        abort(400, {"cause": "Argument value error",
                    "reason": str(e)})
    opts['sorts'] = opts['sort']
    del opts['sort']
    return opts 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:23,代码来源:api.py

示例2: validate_config

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Range [as 别名]
def validate_config(_config):
        source_schema = voluptuous.Schema({
            "module": voluptuous.And(six.string_types[0],
                                     vu.NoSpaceCharacter()),
            "params": {
                "zk_host": voluptuous.And(six.string_types[0],
                                          vu.NoSpaceCharacter()),
                "zk_port": int,
                "group_id": voluptuous.And(six.string_types[0],
                                           vu.NoSpaceCharacter()),
                "topics": {
                    voluptuous.And(six.string_types[0],
                                   vu.NoSpaceCharacter()):
                    voluptuous.And(int, voluptuous.Range(min=1))
                }
            }
        }, required=True)
        return source_schema(_config) 
开发者ID:openstack,项目名称:monasca-analytics,代码行数:20,代码来源:kafka.py

示例3: _show_setup_form

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Range [as 别名]
def _show_setup_form(self, errors=None):
        """Show the setup form to the user."""
        return self.async_show_form(
            step_id="user",
            data_schema=vol.Schema(
                {
                    vol.Required(CONF_HOST): str,
                    vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
                    vol.Required(CONF_USERNAME): str,
                    vol.Required(CONF_PASSWORD): str,
                    vol.Optional(
                        CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
                    ): vol.All(vol.Coerce(int), vol.Range(min=2, max=20)),
                    vol.Optional(CONF_SNAPSHOT_DIRECT, default=False): bool,
                    vol.Optional(CONF_IR_ON, default=TYPE_IR_AUTO): vol.In(TYPES_IR_ON),
                    vol.Optional(CONF_IR_OFF, default=TYPE_IR_OFF): vol.In(
                        TYPES_IR_OFF
                    ),
                }
            ),
            errors=errors or {},
        ) 
开发者ID:briis,项目名称:unifiprotect,代码行数:24,代码来源:config_flow.py

示例4: async_step_init

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Range [as 别名]
def async_step_init(self, user_input=None):
        """Manage the options."""
        if user_input is not None:
            return self.async_create_entry(title="", data=user_input)

        return self.async_show_form(
            step_id="init",
            data_schema=vol.Schema(
                {
                    vol.Optional(
                        CONF_SNAPSHOT_DIRECT,
                        default=self.config_entry.options.get(
                            CONF_SNAPSHOT_DIRECT, False
                        ),
                    ): bool,
                    vol.Optional(
                        CONF_SCAN_INTERVAL,
                        default=self.config_entry.options.get(
                            CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
                        ),
                    ): vol.All(vol.Coerce(int), vol.Range(min=2, max=20)),
                }
            ),
        ) 
开发者ID:briis,项目名称:unifiprotect,代码行数:26,代码来源:config_flow.py

示例5: schema_ext

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

示例6: post

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Range [as 别名]
def post(self):
        enforce("create archive policy", {})
        # NOTE(jd): Initialize this one at run-time because we rely on conf
        conf = pecan.request.conf
        valid_agg_methods = list(
            archive_policy.ArchivePolicy.VALID_AGGREGATION_METHODS_VALUES
        )
        ArchivePolicySchema = voluptuous.Schema({
            voluptuous.Required("name"): six.text_type,
            voluptuous.Required("back_window", default=0): voluptuous.All(
                voluptuous.Coerce(int),
                voluptuous.Range(min=0),
            ),
            voluptuous.Required(
                "aggregation_methods",
                default=list(conf.archive_policy.default_aggregation_methods)):
            valid_agg_methods,
            voluptuous.Required("definition"): ArchivePolicyDefinitionSchema,
        })

        body = deserialize_and_validate(ArchivePolicySchema)
        # Validate the data
        try:
            ap = archive_policy.ArchivePolicy.from_dict(body)
        except ValueError as e:
            abort(400, six.text_type(e))
        enforce("create archive policy", ap)
        try:
            ap = pecan.request.indexer.create_archive_policy(ap)
        except indexer.ArchivePolicyAlreadyExists as e:
            abort(409, six.text_type(e))

        location = "/archive_policy/" + ap.name
        set_resp_location_hdr(location)
        pecan.response.status = 201
        return ap 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:38,代码来源:api.py

示例7: validate_config

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Range [as 别名]
def validate_config(_config):
        source_schema = voluptuous.Schema({
            "module": voluptuous.And(six.string_types[0],
                                     vu.NoSpaceCharacter()),
            "params": {
                "host": voluptuous.And(six.string_types[0],
                                       vu.NoSpaceCharacter()),
                "port": int,
                "model": {
                    "name": voluptuous.And(six.string_types[0],
                                           vu.NoSpaceCharacter()),
                    "params": {
                        "origin_types": voluptuous.And([
                            {
                                "origin_type": voluptuous.And(
                                    six.string_types[0],
                                    vu.NoSpaceCharacter()),
                                "weight": voluptuous.And(
                                    voluptuous.Or(int, float),
                                    voluptuous.Range(
                                        min=0, min_included=False)),
                            }
                        ], vu.NotEmptyArray()),
                        voluptuous.Optional("key_causes"): dict
                    }
                },
                "alerts_per_burst": voluptuous.And(
                    int, voluptuous.Range(min=1)),
                "idle_time_between_bursts": voluptuous.And(
                    voluptuous.Or(int, float),
                    voluptuous.Range(min=0, min_included=False))
            }
        }, required=True)
        return source_schema(_config) 
开发者ID:openstack,项目名称:monasca-analytics,代码行数:36,代码来源:randoms.py

示例8: validate_config

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Range [as 别名]
def validate_config(_config):
        source_schema = voluptuous.Schema({
            "module": voluptuous.And(six.string_types[0],
                                     vu.NoSpaceCharacter()),
            "sleep": voluptuous.And(
                float,
                voluptuous.Range(
                    min=0, max=1, min_included=False, max_included=False)),
        }, required=True)
        return source_schema(_config) 
开发者ID:openstack,项目名称:monasca-analytics,代码行数:12,代码来源:iptables_markov_chain.py

示例9: validate_config

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Range [as 别名]
def validate_config(_config):
        markov_schema = voluptuous.Schema({
            "module": voluptuous.And(six.string_types[0],
                                     vu.NoSpaceCharacter()),
            "sleep": voluptuous.And(
                float, voluptuous.Range(
                    min=0, max=1, min_included=False, max_included=False)),
        }, required=True)
        return markov_schema(_config) 
开发者ID:openstack,项目名称:monasca-analytics,代码行数:11,代码来源:monasca_markov_chain.py

示例10: paginated

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Range [as 别名]
def paginated(func):
    """Helper function for pagination.

    Adds two parameters to the decorated function:
    * ``offset``: int >=0. Defaults to 0.
    * ``limit``: int >=1. Defaults to 100.

    Example usage::

       class Example(base.BaseResource):

           @api_utils.paginated
           @api_utils.add_output_schema({
               voluptuous.Required(
                   'message',
                   default='This is an example endpoint',
               ): validation_utils.get_string_type(),
           })
           def get(self, offset=0, limit=100):
               # [...]
    """
    return add_input_schema('query', {
        voluptuous.Required('offset', default=0): voluptuous.All(
            SingleQueryParam(int), voluptuous.Range(min=0)),
        voluptuous.Required('limit', default=100): voluptuous.All(
            SingleQueryParam(int), voluptuous.Range(min=1)),
    })(func) 
开发者ID:openstack,项目名称:cloudkitty,代码行数:29,代码来源:utils.py

示例11: __init__

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Range [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

示例12: validate_config

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Range [as 别名]
def validate_config(_config):
        source_schema = voluptuous.Schema({
            "module": voluptuous.And(six.string_types[0],
                                     vu.NoSpaceCharacter()),
            "min_event_per_burst": voluptuous.Or(float, int),
            "sleep": voluptuous.And(
                float, voluptuous.Range(
                    min=0, max=1, min_included=False, max_included=False)),
            "transitions": {
                "web_service": {
                    "run=>slow": {
                        voluptuous.And(vu.NumericString()): voluptuous.And(
                            voluptuous.Or(int, float),
                            voluptuous.Range(min=0, max=1)),
                    },
                    "slow=>run": {
                        voluptuous.And(vu.NumericString()): voluptuous.And(
                            voluptuous.Or(int, float),
                            voluptuous.Range(min=0, max=1)),
                    },
                    "stop=>run": voluptuous.And(
                        voluptuous.Or(int, float),
                        voluptuous.Range(min=0, max=1)),
                },
                "switch": {
                    "on=>off": voluptuous.And(voluptuous.Or(int, float),
                                              voluptuous.Range(min=0, max=1)),
                    "off=>on": voluptuous.And(voluptuous.Or(int, float),
                                              voluptuous.Range(min=0, max=1)),
                },
                "host": {
                    "on=>off": voluptuous.And(voluptuous.Or(int, float),
                                              voluptuous.Range(min=0, max=1)),
                    "off=>on": voluptuous.And(voluptuous.Or(int, float),
                                              voluptuous.Range(min=0, max=1)),
                },
            },
            "triggers": {
                "support": {
                    "get_called": {
                        voluptuous.And(vu.NumericString()): voluptuous.And(
                            voluptuous.Or(int, float),
                            voluptuous.Range(min=0, max=1)),
                    },
                },
            },
            "graph": {
                voluptuous.And(six.string_types[0],
                               vu.ValidMarkovGraph()): [six.string_types[0]]
            }
        }, required=True)
        return source_schema(_config) 
开发者ID:openstack,项目名称:monasca-analytics,代码行数:54,代码来源:cloud_markov_chain.py


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