本文整理汇总了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
示例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)
示例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 {},
)
示例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)),
}
),
)
示例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))
示例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
示例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)
示例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)
示例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)
示例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)
示例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,
)
示例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)