Association¶
-
class
jwst.associations.Association(version_id=None)[source]¶ Bases:
collections.abc.MutableMappingAssociation Base Class
Parameters: version_id (str or None) – Version_Id to use in the name of this association. If None, nothing is added. Raises: AssociationError– If a item doesn’t match any of the registered associations.-
data¶ The association. The format of this data structure is determined by the individual assocations and, if defined, valided against their specified schema.
Type: dict
-
registry¶ The registry this association came from.
Type: AssociationRegistry
Attributes Summary
DEFAULT_EVALUATEDEFAULT_FORCE_UNIQUEDEFAULT_REQUIRE_CONSTRAINTGLOBAL_CONSTRAINTINVALID_VALUESasn_nameasn_ruleioregistryis_validCheck if association is valid registryMethods Summary
add(item[, check_constraints])Add the item to the association check_and_set_constraints(item)Check whether the given dictionaries match parameters for for this association create(item[, version_id])Create association if item belongs dump([format])Serialize the association finalize()Finalize assocation is_item_member(item)Check if item is already a member of this association items()keys()load(serialized[, format, validate])Marshall a previously serialized association match_constraint(item, constraint, conditions)Generic constraint checking validate(asn)Validate an association against this rule values()Attributes Documentation
-
DEFAULT_EVALUATE= False¶
-
DEFAULT_FORCE_UNIQUE= False¶
-
DEFAULT_REQUIRE_CONSTRAINT= True¶
-
GLOBAL_CONSTRAINT= None¶
-
INVALID_VALUES= None¶
-
asn_name
-
asn_rule
-
ioregistry= {'json': <class 'jwst.associations.association_io.json'>, 'yaml': <class 'jwst.associations.association_io.yaml'>}¶
-
is_valid¶ Check if association is valid
-
registry= None
Methods Documentation
-
add(item, check_constraints=True)[source]¶ Add the item to the association
Parameters: Returns: 2-tuple consisting of: - bool: True if match - [ProcessList[, …]]: List of items to process again.
Return type: (matching_constraint, reprocess_list)
-
check_and_set_constraints(item)[source]¶ Check whether the given dictionaries match parameters for for this association
Parameters: item (dict) – The parameters to check/set for this association. This can be a list of dictionaries. Returns: 2-tuple consisting of: - Constraint or False: The successfully matching constraint or False if not matching.- [ProcessItem[, …]]: List of items to process again.
Return type: (match, reprocess)
-
classmethod
create(item, version_id=None)[source]¶ Create association if item belongs
Parameters: Returns: 2-tuple consisting of: - association: The association or, if the item does not
this rule, None
- [ProcessList[, …]]: List of items to process again.
Return type: (association, reprocess_list)
-
dump(format='json', **kwargs)[source]¶ Serialize the association
Parameters: Returns: Tuple where the first item is the suggested base name for the file. Second item is the serialization.
Return type: (name, serialized)
Raises: AssociationError– If the operation cannot be doneAssociationNotValidError– If the given association does not validate.
-
finalize()[source]¶ Finalize assocation
Finalize or close-off this association. Peform validations, modifications, etc. to ensure that the association is complete.
Returns: associations – List of fully-qualified associations that this association represents. Noneif a complete association cannot be produced.Return type: [association[, ..]] or None
-
is_item_member(item)[source]¶ Check if item is already a member of this association
Parameters: item (dict) – The item to add. Returns: is_item_member – True if item is a member. Return type: bool
-
classmethod
load(serialized, format=None, validate=True, **kwargs)[source]¶ Marshall a previously serialized association
Parameters: Returns: Return type: The Association object
Raises: AssociationNotValidError– Cannot create or validate the association.Notes
The
serializedobject can be in any format supported by the registered I/O routines. For example, forjsonandyamlformats, the input can be either a string or a file object containing the string.
-
match_constraint(item, constraint, conditions)[source]¶ Generic constraint checking
Parameters: Returns: 2-tuple consisting of: - bool: True if the all constraints are satisfied - [ProcessList[, …]]: List of items to process again.
Return type: (matches, reprocess_list)
-
classmethod
validate(asn)[source]¶ Validate an association against this rule
Parameters: asn (Association or association-like) – The association structure to examine Returns: valid – True if valid. Otherwise the AssociationNotValidErroris raisedReturn type: bool Raises: AssociationNotValidError– If there is some reason validation failed.Notes
The base method checks against the rule class’ schema If the rule class does not define a schema, a warning is issued but the routine will return True.
-