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


Python voluptuous.Required方法代码示例

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


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

示例1: _check_server

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def _check_server(self):
        if not self.is_server_correct_version:
            return False

        try:
            resp = self.get('/versions').json()
            version = resp['versions']['xbox-smartglass-rest']
            if version != REQUIRED_SERVER_VERSION:
                self.is_server_correct_version = False
                _LOGGER.error("Invalid xbox-smartglass-rest version: %s. Required: %s",
                              version, REQUIRED_SERVER_VERSION)
        except requests.exceptions.RequestException:
            self.is_server_up = False
            return False

        self.is_server_up = True
        return True 
开发者ID:hunterjm,项目名称:hassio-addons,代码行数:19,代码来源:xboxone.py

示例2: __init__

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def __init__(self, *args, **kwargs):
        super(ResourceTypeSchemaManager, self).__init__(*args, **kwargs)
        type_schemas = tuple([ext.plugin.meta_schema()
                              for ext in self.extensions])
        self._schema = voluptuous.Schema({
            "name": six.text_type,
            voluptuous.Required("attributes", default={}): {
                six.text_type: voluptuous.Any(*tuple(type_schemas))
            }
        })

        type_schemas = tuple([ext.plugin.meta_schema(for_update=True)
                              for ext in self.extensions])
        self._schema_for_update = voluptuous.Schema({
            "name": six.text_type,
            voluptuous.Required("attributes", default={}): {
                six.text_type: voluptuous.Any(*tuple(type_schemas))
            }
        }) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:21,代码来源:resource_type.py

示例3: get_pagination_options

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

示例4: patch

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def patch(self):
        ap = pecan.request.indexer.get_archive_policy(self.archive_policy)
        if not ap:
            abort(404, six.text_type(
                indexer.NoSuchArchivePolicy(self.archive_policy)))
        enforce("update archive policy", ap)

        body = deserialize_and_validate(voluptuous.Schema({
            voluptuous.Required("definition"): ArchivePolicyDefinitionSchema,
        }))
        # Validate the data
        try:
            ap_items = [archive_policy.ArchivePolicyItem(**item) for item in
                        body['definition']]
        except ValueError as e:
            abort(400, six.text_type(e))

        try:
            return pecan.request.indexer.update_archive_policy(
                self.archive_policy, ap_items)
        except indexer.UnsupportedArchivePolicyChange as e:
            abort(400, six.text_type(e)) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:24,代码来源:api.py

示例5: from_dict

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def from_dict(cls, dict_, legacy=False):
        try:
            schema = DATAFRAME_SCHEMA
            if legacy:
                validator = functools.partial(DataPoint.from_dict, legacy=True)
                # NOTE(peschk_l): __name__ is required for voluptuous exception
                # message formatting
                validator.__name__ = 'DataPoint.from_dict'
                # NOTE(peschk_l): In case the legacy format is required, we
                # create a new schema where DataPoint.from_dict is called with
                # legacy=True. The "extend" method does create a new objects,
                # and replaces existing keys with new ones.
                schema = DATAFRAME_SCHEMA.extend({
                    voluptuous.Required('usage'): vutils.IterableValuesDict(
                        str, validator
                    ),
                })
            valid = schema(dict_)
            return cls(
                valid["period"]["begin"],
                valid["period"]["end"],
                usage=valid["usage"])
        except (voluptuous.error.Invalid, KeyError) as e:
            raise ValueError("{} isn't a valid DataFrame: {}".format(dict_, e)) 
开发者ID:openstack,项目名称:cloudkitty,代码行数:26,代码来源:dataframe.py

示例6: test_simple_add_input_schema_query

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def test_simple_add_input_schema_query(self):

        @api_utils.add_input_schema('query', {
            voluptuous.Required(
                'arg_one', default='one'): api_utils.SingleQueryParam(str),
        })
        def test_func(self, arg_one=None):
            self.assertEqual(arg_one, 'one')

        self.assertEqual(len(test_func.input_schema.schema.keys()), 1)
        self.assertEqual(
            list(test_func.input_schema.schema.keys())[0], 'arg_one')

        with mock.patch('flask.request') as m:
            m.args = MultiDict({})
            test_func(self)
            m.args = MultiDict({'arg_one': 'one'})
            test_func(self) 
开发者ID:openstack,项目名称:cloudkitty,代码行数:20,代码来源:test_utils.py

示例7: test_simple_add_input_schema_body

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def test_simple_add_input_schema_body(self):

        @api_utils.add_input_schema('body', {
            voluptuous.Required(
                'arg_one', default='one'): api_utils.SingleQueryParam(str),
        })
        def test_func(self, arg_one=None):
            self.assertEqual(arg_one, 'one')

        self.assertEqual(len(test_func.input_schema.schema.keys()), 1)
        self.assertEqual(
            list(test_func.input_schema.schema.keys())[0], 'arg_one')

        with mock.patch('flask.request') as m:
            m.get_json.return_value = {}
            test_func(self)

        with mock.patch('flask.request') as m:
            m.get_json.return_value = {'arg_one': 'one'}
            test_func(self) 
开发者ID:openstack,项目名称:cloudkitty,代码行数:22,代码来源:test_utils.py

示例8: _show_setup_form

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

示例9: _show_icon_form

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def _show_icon_form(self, user_input):
        icon_normal = DEFAULT_ICON_NORMAL
        icon_today = DEFAULT_ICON_TODAY
        days_as_soon = DEFAULT_SOON
        icon_soon = DEFAULT_ICON_SOON
        if user_input is not None:
            if CONF_ICON_NORMAL in user_input:
                icon_normal = user_input[CONF_ICON_NORMAL]
            if CONF_ICON_TODAY in user_input:
                icon_today = user_input[CONF_ICON_TODAY]
            if CONF_SOON in user_input:
                days_as_soon = user_input[CONF_SOON]
            if CONF_ICON_SOON in user_input:
                icon_soon = user_input[CONF_ICON_SOON]
        data_schema = OrderedDict()
        data_schema[vol.Required(CONF_ICON_NORMAL, default=icon_normal)] = str
        data_schema[vol.Required(CONF_ICON_TODAY, default=icon_today)] = str
        data_schema[vol.Required(CONF_SOON, default=days_as_soon)] = int
        data_schema[vol.Required(CONF_ICON_SOON, default=icon_soon)] = str
        return self.async_show_form(step_id="icons", data_schema=vol.Schema(data_schema), errors=self._errors) 
开发者ID:pinkywafer,项目名称:Anniversaries,代码行数:22,代码来源:config_flow.py

示例10: _show_init_form

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def _show_init_form(self, user_input):
        data_schema = OrderedDict()
        one_time = self.config_entry.options.get(CONF_ONE_TIME)
        unit_of_measurement = self.config_entry.options.get(CONF_UNIT_OF_MEASUREMENT)
        half_anniversary = self.config_entry.options.get(CONF_HALF_ANNIVERSARY)
        if one_time is None:
            one_time = DEFAULT_ONE_TIME
        if half_anniversary is None:
            half_anniversary = DEFAULT_HALF_ANNIVERSARY
        if unit_of_measurement is None:
            unit_of_measurement = DEFAULT_UNIT_OF_MEASUREMENT
        data_schema[vol.Required(CONF_NAME,default=self.config_entry.options.get(CONF_NAME),)] = str
        data_schema[vol.Required(CONF_DATE, default=self.config_entry.options.get(CONF_DATE),)] = str
        data_schema[vol.Required(CONF_ONE_TIME, default=one_time,)] = bool
        data_schema[vol.Required(CONF_HALF_ANNIVERSARY,default=half_anniversary,)] = bool
        data_schema[vol.Required(CONF_DATE_FORMAT,default=self.config_entry.options.get(CONF_DATE_FORMAT),)] = str
        data_schema[vol.Required(CONF_UNIT_OF_MEASUREMENT,default=unit_of_measurement,)] = str
        return self.async_show_form(
            step_id="init", data_schema=vol.Schema(data_schema), errors=self._errors
        ) 
开发者ID:pinkywafer,项目名称:Anniversaries,代码行数:22,代码来源:config_flow.py

示例11: meta_schema

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def meta_schema(cls, for_update=False):
        d = {
            voluptuous.Required('type'): cls.typename,
            voluptuous.Required('required', default=True): bool
        }
        if for_update:
            d[voluptuous.Required('options', default={})] = OperationOptions
        if callable(cls.meta_schema_ext):
            d.update(cls.meta_schema_ext())
        else:
            d.update(cls.meta_schema_ext)
        return d 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:14,代码来源:resource_type.py

示例12: post

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

示例13: async_step_user

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def async_step_user(self, user_input=None):
        errors = {}
        if user_input is not None:
            if len(user_input['code']) != 4:
                errors["base"] = "not_hex"
            else:
                try:
                    if hex(int(user_input['code'], 16)).lower() != "0x" + user_input['code'].lower():
                        errors["base"] = "not_hex"
                except ValueError:
                    errors["base"] = "not_hex"
            if not errors:
                return self.async_create_entry(
                    title='duofern', data=user_input
                )
        if os.path.isdir("/dev/serial/by-id"):
            serialdevs = set(os.listdir("/dev/serial/by-id/"))
        else:
            serialdevs=["could not find /dev/serial/by-id/, did you plug in your dufoern stick correctly?"]
        return self.async_show_form(
            step_id='user',
            data_schema=vol.Schema({
                vol.Required('code'): str,
                vol.Optional('serial_port',
                             default="/dev/serial/by-id/usb-Rademacher_DuoFern_USB-Stick_WR04ZFP4-if00-port0"): vol.In(serialdevs),
                vol.Optional('config_file', default=os.path.join(os.path.dirname(__file__), "../../duofern.json")): str
            }),
            errors=errors
        ) 
开发者ID:gluap,项目名称:pyduofern,代码行数:31,代码来源:config_flow.py

示例14: hacs_base_config_schema

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def hacs_base_config_schema(config: dict = {}) -> dict:
    """Return a shcema configuration dict for HACS."""
    if not config:
        config = {
            TOKEN: "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
        }
    return {
        vol.Required(TOKEN, default=config.get(TOKEN)): str,
    } 
开发者ID:hacs,项目名称:integration,代码行数:11,代码来源:configuration_schema.py

示例15: create_parameters1

# 需要导入模块: import voluptuous [as 别名]
# 或者: from voluptuous import Required [as 别名]
def create_parameters1(options):
    # Panel settings - can only be set on creation
    return {
        vol.Required(CONF_LANGUAGE,         default=create_default(options, CONF_LANGUAGE, "EN") )         : str,
        vol.Optional(CONF_EXCLUDE_SENSOR,   default=create_default(options, CONF_EXCLUDE_SENSOR, ""))      : str,
        vol.Optional(CONF_EXCLUDE_X10,      default=create_default(options, CONF_EXCLUDE_X10, ""))         : str,
        vol.Optional(CONF_DOWNLOAD_CODE,    default=create_default(options, CONF_DOWNLOAD_CODE, "") )      : str,
        vol.Optional(CONF_FORCE_STANDARD,   default=create_default(options, CONF_FORCE_STANDARD, False))   : bool, 
        vol.Optional(CONF_FORCE_AUTOENROLL, default=create_default(options, CONF_FORCE_AUTOENROLL, False)) : bool, 
        vol.Optional(CONF_AUTO_SYNC_TIME,   default=create_default(options, CONF_AUTO_SYNC_TIME, True))    : bool
    } 
开发者ID:davesmeghead,项目名称:visonic,代码行数:13,代码来源:create_schema.py


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