Python attr.validate() Examples

The following are 30 code examples of attr.validate(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module attr , or try the search function .
Example #1
Source File: resource.py    From aws-dynamodb-encryption-python with Apache License 2.0 6 votes vote down vote up
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__() 
Example #2
Source File: models.py    From pycoalaip with Apache License 2.0 6 votes vote down vote up
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) 
Example #3
Source File: structures.py    From aws-dynamodb-encryption-python with Apache License 2.0 6 votes vote down vote up
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) 
Example #4
Source File: table.py    From aws-dynamodb-encryption-python with Apache License 2.0 6 votes vote down vote up
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__() 
Example #5
Source File: wrapped.py    From aws-dynamodb-encryption-python with Apache License 2.0 6 votes vote down vote up
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__() 
Example #6
Source File: raw.py    From aws-dynamodb-encryption-python with Apache License 2.0 6 votes vote down vote up
def __init__(
        self,
        verification_key,  # type: DelegatedKey
        decryption_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._verification_key = verification_key
        self._decryption_key = decryption_key
        self._material_description = material_description
        attr.validate(self)
        self.__attrs_post_init__() 
Example #7
Source File: raw.py    From aws-dynamodb-encryption-python with Apache License 2.0 6 votes vote down vote up
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__() 
Example #8
Source File: client.py    From aws-dynamodb-encryption-python with Apache License 2.0 6 votes vote down vote up
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__() 
Example #9
Source File: model.py    From xarray-simlab with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #10
Source File: io_handling.py    From aws-encryption-sdk-cli with Apache License 2.0 6 votes vote down vote up
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) 
Example #11
Source File: decrypt.py    From aws-encryption-sdk-python with Apache License 2.0 6 votes vote down vote up
def __init__(
        self,
        keys_uri,  # type: str
        keys,  # type: KeysManifest
        test_scenarios=None,  # type: Optional[Dict[str, MessageDecryptionTestScenario]]
        version=CURRENT_VERSION,  # type: Optional[int]
        client_name=CLIENT_NAME,  # type: Optional[str]
        client_version=aws_encryption_sdk.__version__,  # 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.keys_uri = keys_uri
        self.keys = keys
        self.test_scenarios = test_scenarios
        self.version = version
        self.client_name = client_name
        self.client_version = client_version
        attr.validate(self) 
Example #12
Source File: decrypt.py    From aws-encryption-sdk-python with Apache License 2.0 6 votes vote down vote up
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) 
Example #13
Source File: aws_kms.py    From aws-dynamodb-encryption-python with Apache License 2.0 5 votes vote down vote up
def __init__(self, description, algorithm, length):
        # type: (Text, Text, int) -> None
        # Workaround pending resolution of attrs/mypy interaction.
        # https://github.com/python/mypy/issues/2088
        # https://github.com/python-attrs/attrs/issues/215
        self.description = description
        self.algorithm = algorithm
        self.length = length
        attr.validate(self) 
Example #14
Source File: aws_kms.py    From aws-dynamodb-encryption-python with Apache License 2.0 5 votes vote down vote up
def __init__(
        self,
        key_id,  # type: Text
        botocore_session=None,  # type: Optional[botocore.session.Session]
        grant_tokens=None,  # type: Optional[Tuple[Text]]
        material_description=None,  # type: Optional[Dict[Text, Text]]
        regional_clients=None,  # type: Optional[Dict[Text, botocore.client.BaseClient]]
    ):  # 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 botocore_session is None:
            botocore_session = botocore.session.Session()
        if grant_tokens is None:
            # reassignment confuses mypy
            grant_tokens = ()  # type: ignore
        if material_description is None:
            material_description = {}
        if regional_clients is None:
            regional_clients = {}

        self._key_id = key_id
        self._botocore_session = botocore_session
        self._grant_tokens = grant_tokens
        self._material_description = material_description
        self._regional_clients = regional_clients
        attr.validate(self)
        self.__attrs_post_init__() 
Example #15
Source File: test_cas.py    From dkpro-cassis with Apache License 2.0 5 votes vote down vote up
def test_get_view_finds_existing_view():
    cas = Cas()
    cas.create_view("testView")
    cas.sofa_string = "Initial"

    view = cas.get_view("testView")
    view.sofa_string = "testView42"

    sofa = view.get_sofa()
    attr.validate(sofa)
    assert sofa.sofaID == "testView"
    assert cas.sofa_string == "Initial"
    assert view.sofa_string == "testView42" 
Example #16
Source File: aws_kms.py    From aws-dynamodb-encryption-python with Apache License 2.0 5 votes vote down vote up
def _validate_key_id(self, key_id, encryption_context):
        # type: (Text, EncryptionContext) -> None
        # pylint: disable=unused-argument,no-self-use
        """Validate the selected key id.

        .. note::

            Default behavior is to do nothing, but this method provides an extension point
            for a CMP that overrides ``_select_key_id`` or otherwise wants to validate a
            key id before it is used.

        :param EncryptionContext encryption_context: Encryption context providing information about request
        """ 
Example #17
Source File: most_recent.py    From aws-dynamodb-encryption-python with Apache License 2.0 5 votes vote down vote up
def __init__(self, capacity):  # noqa=D107
        # type: (int) -> None
        # Workaround pending resolution of attrs/mypy interaction.
        # https://github.com/python/mypy/issues/2088
        # https://github.com/python-attrs/attrs/issues/215
        self.capacity = capacity
        attr.validate(self)
        self.__attrs_post_init__() 
Example #18
Source File: most_recent.py    From aws-dynamodb-encryption-python with Apache License 2.0 5 votes vote down vote up
def __init__(self, provider_store, material_name, version_ttl):  # noqa=D107
        # type: (ProviderStore, Text, float) -> None
        # Workaround pending resolution of attrs/mypy interaction.
        # https://github.com/python/mypy/issues/2088
        # https://github.com/python-attrs/attrs/issues/215
        self._provider_store = provider_store
        self._material_name = material_name
        self._version_ttl = version_ttl
        attr.validate(self)
        self.__attrs_post_init__() 
Example #19
Source File: static.py    From aws-dynamodb-encryption-python with Apache License 2.0 5 votes vote down vote up
def __init__(
        self,
        decryption_materials=None,  # type: Optional[DecryptionMaterials]
        encryption_materials=None,  # type: Optional[EncryptionMaterials]
    ):  # 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._decryption_materials = decryption_materials
        self._encryption_materials = encryption_materials
        attr.validate(self) 
Example #20
Source File: meta.py    From aws-dynamodb-encryption-python with Apache License 2.0 5 votes vote down vote up
def __init__(self, table, materials_provider):  # noqa=D107
        # type: (ServiceResource, CryptographicMaterialsProvider) -> None
        # Workaround pending resolution of attrs/mypy interaction.
        # https://github.com/python/mypy/issues/2088
        # https://github.com/python-attrs/attrs/issues/215
        self._table = table
        self._materials_provider = materials_provider
        attr.validate(self)
        self.__attrs_post_init__() 
Example #21
Source File: test_cas.py    From dkpro-cassis with Apache License 2.0 5 votes vote down vote up
def test_initial_view_is_created():
    cas = Cas()

    view = cas.get_view("_InitialView")

    sofa = view.get_sofa()
    attr.validate(sofa)
    assert sofa.sofaID == "_InitialView" 
Example #22
Source File: test_cas.py    From dkpro-cassis with Apache License 2.0 5 votes vote down vote up
def test_create_view_creates_view():
    cas = Cas()

    view = cas.create_view("testView")
    sofa = view.get_sofa()

    attr.validate(sofa)
    assert sofa.sofaID == "testView" 
Example #23
Source File: authentication.py    From aws-dynamodb-encryption-python with Apache License 2.0 5 votes vote down vote up
def __init__(
        self, java_name, algorithm_type, hash_type, padding_type  # type: Text  # type: Callable  # type: Callable
    ):  # 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.java_name = java_name
        self.algorithm_type = algorithm_type
        self.hash_type = hash_type
        self.padding_type = padding_type
        attr.validate(self) 
Example #24
Source File: xmi.py    From dkpro-cassis with Apache License 2.0 5 votes vote down vote up
def _parse_view(self, elem) -> ProtoView:
        attributes = elem.attrib
        sofa = int(attributes["sofa"])
        members = [int(e) for e in attributes.get("members", "").strip().split()]
        result = ProtoView(sofa=sofa, members=members)
        attr.validate(result)
        return result 
Example #25
Source File: redis.py    From rush with MIT License 5 votes vote down vote up
def _validate_url(self, attribute, value):
        """Ensure our URL has the bare minimum we need."""
        try:
            URL_VALIDATOR.validate(value.reference)
        except rfc3986.exceptions.ValidationError as err:
            url = value.unsplit()
            raise exceptions.InvalidRedisURL(
                f"Provided URL {url} is invalid for Redis storage.",
                url=url,
                error=err,
            ) 
Example #26
Source File: redis.py    From rush with MIT License 5 votes vote down vote up
def _make_client(self):
        """Create the Redis client from the URL and config."""
        attr.validate(self)  # Force validation of self.url
        self.client_config.setdefault("decode_responses", True)
        return redis.StrictRedis.from_url(
            url=self.url.unsplit(), **self.client_config
        ) 
Example #27
Source File: registry.py    From excelcy with MIT License 5 votes vote down vote up
def validate(self):
        return attr.validate(self) 
Example #28
Source File: model.py    From xarray-simlab with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _execute_process(
        self, p_obj, stage, runtime_context, hooks, validate, state=None
    ):
        executor = p_obj.__xsimlab_executor__
        p_name = p_obj.__xsimlab_name__

        self._call_hooks(hooks, runtime_context, stage, "process", "pre")
        out_state = executor.execute(p_obj, stage, runtime_context, state=state)
        self._call_hooks(hooks, runtime_context, stage, "process", "post")

        if validate:
            self.validate(self._processes_to_validate[p_name])

        return p_name, out_state 
Example #29
Source File: utils.py    From aws-dynamodb-encryption-python with Apache License 2.0 5 votes vote down vote up
def __init__(self, client, auto_refresh_table_indexes):  # noqa=D107
        # type: (botocore.client.BaseClient, bool) -> None
        # Workaround pending resolution of attrs/mypy interaction.
        # https://github.com/python/mypy/issues/2088
        # https://github.com/python-attrs/attrs/issues/215
        self._client = client
        self._auto_refresh_table_indexes = auto_refresh_table_indexes
        attr.validate(self)
        self.__attrs_post_init__() 
Example #30
Source File: keys.py    From aws-encryption-sdk-python with Apache License 2.0 5 votes vote down vote up
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)