當前位置: 首頁>>代碼示例>>Python>>正文


Python voluptuous.All方法代碼示例

本文整理匯總了Python中voluptuous.All方法的典型用法代碼示例。如果您正苦於以下問題:Python voluptuous.All方法的具體用法?Python voluptuous.All怎麽用?Python voluptuous.All使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在voluptuous的用法示例。


在下文中一共展示了voluptuous.All方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_pagination_options

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [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: _init_schema

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [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: _show_setup_form

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [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 All [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: async_step_init

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [as 別名]
def async_step_init(self, user_input=None):
        """Handle options flow."""
        if user_input is not None:
            return self.async_create_entry(title="", data=user_input)

        data_schema = vol.Schema(
            {
                vol.Optional(
                    CONF_QUEUE_DELAY,
                    default=self.config_entry.options.get(
                        CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY
                    ),
                ): vol.All(vol.Coerce(float), vol.Clamp(min=0))
            }
        )
        return self.async_show_form(step_id="init", data_schema=data_schema) 
開發者ID:macbury,項目名稱:SmartHouse,代碼行數:18,代碼來源:config_flow.py

示例6: schema_ext

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [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

示例7: MetricSchema

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [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

示例8: post

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [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

示例9: __init__

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [as 別名]
def __init__(self, config, devices):
        """Initialize the Aarlo siren switch device."""
        super().__init__("All Sirens", "alarm-light", config.get(CONF_SIREN_DURATION), config.get(CONF_SIREN_ALLOW_OFF))
        self._volume = config.get(CONF_SIREN_VOLUME)
        self._devices = devices
        self._state = "off" 
開發者ID:pschmitt,項目名稱:hass-config,代碼行數:8,代碼來源:switch.py

示例10: get_schema

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [as 別名]
def get_schema(cls):
        return voluptuous.All(cls.validator, voluptuous.Coerce(cls)) 
開發者ID:Mergifyio,項目名稱:mergify-engine,代碼行數:4,代碼來源:__init__.py

示例11: build_range_spec_validator

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [as 別名]
def build_range_spec_validator(  # type: ignore
    min_value: int, max_value: int
) -> vol.Schema:
    """Returns a validator for range specifications with the given
    min/max values."""

    return vol.All(
        vol.Any(int, str), lambda v: util.expand_range_spec(v, min_value, max_value)
    ) 
開發者ID:efficiosoft,項目名稱:hass-apps,代碼行數:11,代碼來源:config.py

示例12: _validate

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [as 別名]
def _validate(self):
        schema = Schema(
            All(self._schema, *self._custom_validators),
            extra=ALLOW_EXTRA,
        )
        schema(self._confdata) 
開發者ID:italia,項目名稱:spid-testenv2,代碼行數:8,代碼來源:config.py

示例13: paginated

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [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

示例14: __init__

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [as 別名]
def __init__(self):
        """Initialize the config flow."""
        self.login = None
        self.config = OrderedDict()
        self.data_schema = OrderedDict(
            [
                (vol.Required(CONF_EMAIL), str),
                (vol.Required(CONF_PASSWORD), str),
                (vol.Required(CONF_URL, default="amazon.com"), str),
                (vol.Optional(CONF_DEBUG, default=False), bool),
                (vol.Optional(CONF_INCLUDE_DEVICES, default=""), str),
                (vol.Optional(CONF_EXCLUDE_DEVICES, default=""), str),
                (vol.Optional(CONF_SCAN_INTERVAL, default=60), int),
            ]
        )
        self.captcha_schema = OrderedDict(
            [(vol.Required(CONF_PASSWORD), str), (vol.Required("captcha"), str)]
        )
        self.twofactor_schema = OrderedDict([(vol.Required("securitycode"), str)])
        self.claimspicker_schema = OrderedDict(
            [
                (
                    vol.Required("claimsoption", default=0),
                    vol.All(cv.positive_int, vol.Clamp(min=0)),
                )
            ]
        )
        self.authselect_schema = OrderedDict(
            [
                (
                    vol.Required("authselectoption", default=0),
                    vol.All(cv.positive_int, vol.Clamp(min=0)),
                )
            ]
        )
        self.verificationcode_schema = OrderedDict(
            [(vol.Required("verificationcode"), str)]
        ) 
開發者ID:macbury,項目名稱:SmartHouse,代碼行數:40,代碼來源:config_flow.py

示例15: __init__

# 需要導入模塊: import voluptuous [as 別名]
# 或者: from voluptuous import All [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


注:本文中的voluptuous.All方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。