本文整理汇总了Python中attr.validate方法的典型用法代码示例。如果您正苦于以下问题:Python attr.validate方法的具体用法?Python attr.validate怎么用?Python attr.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类attr
的用法示例。
在下文中一共展示了attr.validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def __init__(self, ld_type, ld_id=None, ld_context=None,
validator=DEFAULT_DATA_VALIDATOR, data=None):
"""Initialize a :class:`~.LazyLoadableModel` instance.
If a :attr:`data` is provided, a :class:`Model` is generated
as the instance's :attr:`~.LazyLoadableModel.loaded_model` using
the given arguments.
Ignores :attr:`ld_id`, see the :meth:`ld_id` property instead.
"""
self.ld_type = ld_type
self.ld_context = _make_context_immutable(ld_context or
get_default_ld_context())
self.validator = validator
self.loaded_model = None
attr.validate(self)
if data:
self.loaded_model = Model(data=data, ld_type=self.ld_type,
ld_context=self.ld_context,
validator=self.validator)
示例2: __init__
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def __init__(
self,
plaintext_uri, # type: str
plaintext, # type: bytes
ciphertext_uri, # type: str
ciphertext, # type: bytes
master_key_specs, # type: Iterable[MasterKeySpec]
master_key_provider, # type: MasterKeyProvider
description=None, # type: Optional[str]
): # noqa=D107
# type: (...) -> None
# Workaround pending resolution of attrs/mypy interaction.
# https://github.com/python/mypy/issues/2088
# https://github.com/python-attrs/attrs/issues/215
self.plaintext_uri = plaintext_uri
self.plaintext = plaintext
self.ciphertext_uri = ciphertext_uri
self.ciphertext = ciphertext
self.master_key_specs = master_key_specs
self.master_key_provider = master_key_provider
self.description = description
attr.validate(self)
示例3: __init__
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def __init__(
self,
metadata_writer, # type: MetadataWriter
interactive, # type: bool
no_overwrite, # type: bool
decode_input, # type: bool
encode_output, # type: bool
required_encryption_context, # type: Dict[str, str]
required_encryption_context_keys, # type: List[str]
):
# type: (...) -> None
"""Workaround pending resolution of attrs/mypy interaction.
https://github.com/python/mypy/issues/2088
https://github.com/python-attrs/attrs/issues/215
"""
self.metadata_writer = metadata_writer
self.interactive = interactive
self.no_overwrite = no_overwrite
self.decode_input = decode_input
self.encode_output = encode_output
self.required_encryption_context = required_encryption_context
self.required_encryption_context_keys = required_encryption_context_keys # pylint: disable=invalid-name
attr.validate(self)
示例4: __init__
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def __init__(
self,
signing_key, # type: DelegatedKey
encryption_key=None, # type: Optional[DelegatedKey]
material_description=None, # type: Optional[Dict[Text, Text]]
): # noqa=D107
# type: (...) -> None
# Workaround pending resolution of attrs/mypy interaction.
# https://github.com/python/mypy/issues/2088
# https://github.com/python-attrs/attrs/issues/215
if material_description is None:
material_description = {}
self._signing_key = signing_key
self._encryption_key = encryption_key
self._material_description = material_description
attr.validate(self)
self.__attrs_post_init__()
示例5: __init__
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def __init__(
self,
signing_key, # type: DelegatedKey
wrapping_key=None, # type: Optional[DelegatedKey]
unwrapping_key=None, # type: Optional[DelegatedKey]
material_description=None, # type: Optional[Dict[Text, Text]]
): # noqa=D107
# type: (...) -> None
# Workaround pending resolution of attrs/mypy interaction.
# https://github.com/python/mypy/issues/2088
# https://github.com/python-attrs/attrs/issues/215
if material_description is None:
material_description = {}
self._signing_key = signing_key
self._wrapping_key = wrapping_key
self._unwrapping_key = unwrapping_key
self._material_description = material_description
attr.validate(self)
self.__attrs_post_init__()
示例6: __init__
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def __init__(
self,
table_name=None, # type: Optional[Text]
partition_key_name=None, # type: Optional[Text]
sort_key_name=None, # type: Optional[Text]
attributes=None, # type: Optional[Dict[Text, Dict]]
material_description=None, # type: Optional[Dict[Text, Text]]
): # noqa=D107
# type: (...) -> None
# Workaround pending resolution of attrs/mypy interaction.
# https://github.com/python/mypy/issues/2088
# https://github.com/python-attrs/attrs/issues/215
if attributes is None:
attributes = {}
if material_description is None:
material_description = {}
self.table_name = table_name
self.partition_key_name = partition_key_name
self.sort_key_name = sort_key_name
self.attributes = attributes
self.material_description = material_description
attr.validate(self)
示例7: __init__
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def __init__(
self,
table, # type: ServiceResource
materials_provider, # type: CryptographicMaterialsProvider
table_info=None, # type: Optional[TableInfo]
attribute_actions=None, # type: Optional[AttributeActions]
auto_refresh_table_indexes=True, # type: Optional[bool]
): # noqa=D107
# type: (...) -> None
# Workaround pending resolution of attrs/mypy interaction.
# https://github.com/python/mypy/issues/2088
# https://github.com/python-attrs/attrs/issues/215
if attribute_actions is None:
attribute_actions = AttributeActions()
self._table = table
self._materials_provider = materials_provider
self._table_info = table_info
self._attribute_actions = attribute_actions
self._auto_refresh_table_indexes = auto_refresh_table_indexes
attr.validate(self)
self.__attrs_post_init__()
示例8: __init__
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def __init__(
self,
client, # type: botocore.client.BaseClient
materials_provider, # type: CryptographicMaterialsProvider
attribute_actions=None, # type: Optional[AttributeActions]
auto_refresh_table_indexes=True, # type: Optional[bool]
expect_standard_dictionaries=False, # type: Optional[bool]
): # noqa=D107
# type: (...) -> None
# Workaround pending resolution of attrs/mypy interaction.
# https://github.com/python/mypy/issues/2088
# https://github.com/python-attrs/attrs/issues/215
if attribute_actions is None:
attribute_actions = AttributeActions()
self._client = client
self._materials_provider = materials_provider
self._attribute_actions = attribute_actions
self._auto_refresh_table_indexes = auto_refresh_table_indexes
self._expect_standard_dictionaries = expect_standard_dictionaries
attr.validate(self)
self.__attrs_post_init__()
示例9: __init__
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def __init__(
self,
collection, # type: CollectionManager
materials_provider, # type: CryptographicMaterialsProvider
attribute_actions, # type: AttributeActions
table_info_cache, # type: TableInfoCache
): # noqa=D107
# type: (...) -> None
# Workaround pending resolution of attrs/mypy interaction.
# https://github.com/python/mypy/issues/2088
# https://github.com/python-attrs/attrs/issues/215
self._collection = collection
self._materials_provider = materials_provider
self._attribute_actions = attribute_actions
self._table_info_cache = table_info_cache
attr.validate(self)
self.__attrs_post_init__()
示例10: validate
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def validate(self, p_names=None):
"""Run the variable validators of all or some of the processes
in the model.
Parameters
----------
p_names : list, optional
Names of the processes to validate. If None is given (default),
validators are run for all processes.
"""
if p_names is None:
processes = self._processes.values()
else:
processes = [self._processes[pn] for pn in p_names]
for p_obj in processes:
attr.validate(p_obj)
示例11: __init__
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def __init__(self, encrypt, decrypt, key_id): # noqa=D107
# type: (bool, bool, str) -> None
# Workaround pending resolution of attrs/mypy interaction.
# https://github.com/python/mypy/issues/2088
# https://github.com/python-attrs/attrs/issues/215
self.encrypt = encrypt
self.decrypt = decrypt
self.key_id = key_id
attr.validate(self)
示例12: __call__
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def __call__(self, output_file=None):
# type: (Optional[str]) -> MetadataWriter
"""Set the output file target and validate init and call arguments.
.. note::
Separated from ``__init__`` to make use as an argparse type simpler.
:param str output_file: Path to file to write to, or "-" for stdout (optional)
"""
self.output_file = output_file
if self.suppress_output:
return self
if self.output_file is None:
raise TypeError("output_file cannot be None when suppress_output is False")
if self.output_file == "-":
self._output_mode = "w"
return self
if not os.path.isdir(os.path.dirname(os.path.realpath(self.output_file))):
raise BadUserArgumentError("Parent directory for requested metdata file does not exist.")
self._output_mode = "ab"
self.output_file = os.path.abspath(self.output_file)
attr.validate(self)
return self
示例13: test_real_types
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def test_real_types(type_, good_value, bad_value):
@attr.s(auto_attribs=True)
class Something:
value: type_ = attr.ib(validator=type_validator())
with pytest.raises(ValueError):
Something(bad_value)
x = Something(good_value)
with pytest.raises(ValueError):
x.value = bad_value
attr.validate(x)
示例14: test_reassign_evaluate
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def test_reassign_evaluate():
@attr.s
class Something(object):
number = attr.ib(validator=type_validator(), type=str)
x = Something(number="foo")
with pytest.raises(ValueError) as error:
x.number = 5
attr.validate(x)
assert repr(
error.value
) == "<number must be {} (got 5 that is a {})>".format(str, int)
示例15: _validate_attribute_values_are_ddb_items
# 需要导入模块: import attr [as 别名]
# 或者: from attr import validate [as 别名]
def _validate_attribute_values_are_ddb_items(instance, attribute, value): # pylint: disable=unused-argument
"""Validate that dictionary values in ``value`` match the structure of DynamoDB JSON
items.
.. note::
We are not trying to validate the full structure of the item with this validator.
This is just meant to verify that the values roughly match the correct format.
"""
for data in value.values():
if len(list(data.values())) != 1:
raise TypeError('"{}" values do not look like DynamoDB items'.format(attribute.name))