當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。