Association

class jwst.associations.Association(version_id=None)[source]

Bases: MutableMapping

Association Base Class.

instance

The instance is the association data structure. See data below

Type:

dict-like

meta

Information about the association.

Type:

dict

data

The association. The format of this data structure is determined by the individual associations and, if defined, validated against their specified schema.

Type:

dict

schema_file

The name of the output schema that an association must adhere to.

Type:

str

Raises:

AssociationError – If an item doesn’t match.

Initialize an Association.

Parameters:

version_id (str or None) – Version ID to use in the name of this association. If None, nothing is added.

Attributes Summary

DEFAULT_EVALUATE

Default do not evaluate input values

DEFAULT_FORCE_UNIQUE

Default whether to force constraints to use unique values.

DEFAULT_REQUIRE_CONSTRAINT

Default require that the constraint exists or otherwise can be explicitly checked.

GLOBAL_CONSTRAINT

Global constraints

INVALID_VALUES

Attribute values that indicate the attribute is not specified.

asn_name

Suggest filename for the association.

asn_rule

Name of the rule.

ioregistry

The association IO registry

is_valid

Check if association is valid.

registry

Registry this rule has been placed in.

Methods Summary

add(item[, check_constraints])

Add the item to the association.

check_and_set_constraints(item)

Check whether the given dictionaries match parameters for this association.

create(item[, version_id])

Create association if item belongs.

dump([fmt])

Serialize the association.

finalize()

Finalize association.

is_item_member(item)

Check if item is already a member of this association.

items()

Provide items of data dictionary.

keys()

Provide keys of data dictionary.

load(serialized[, fmt, validate])

Marshal a previously serialized association.

match_constraint(item, conditions)

Match against constraints.

rule_name()

Return rule name.

validate(asn)

Validate an association against this rule.

values()

Provide values of data dictionary.

Attributes Documentation

DEFAULT_EVALUATE = False

Default do not evaluate input values

DEFAULT_FORCE_UNIQUE = False

Default whether to force constraints to use unique values.

DEFAULT_REQUIRE_CONSTRAINT = True

Default require that the constraint exists or otherwise can be explicitly checked.

GLOBAL_CONSTRAINT = None

Global constraints

INVALID_VALUES: tuple | None = None

Attribute values that indicate the attribute is not specified.

asn_name

Suggest filename for the association.

Returns:

Default asn name of ‘unnamed_association’.

Return type:

str

asn_rule

Name of the rule.

Returns:

The asn rule name.

Return type:

str

ioregistry: KeyValueRegistry = {'json': <class 'jwst.associations.association_io.json'>, 'yaml': <class 'jwst.associations.association_io.yaml'>}

The association IO registry

is_valid

Check if association is valid.

Returns:

True if association is valid.

Return type:

bool

registry = None

Registry this rule has been placed in.

Methods Documentation

add(item, check_constraints=True)[source]

Add the item to the association.

Parameters:
  • item (dict) – The item to add.

  • check_constraints (bool) – If True, see if the item should belong to this association. If False, just add it.

Returns:

2-tuple consisting of:
  • bool : True if match

  • [ProcessList[, …]]: List of items to process again.

Return type:

(match, reprocess_list)

check_and_set_constraints(item)[source]

Check whether the given dictionaries match parameters 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:
  • bool : Did constraint match?

  • [ProcessItem[, …]]: List of items to process again.

Return type:

(match, reprocess)

classmethod create(item, version_id=None)[source]

Create association if item belongs.

Parameters:
  • item (dict) – The item to initialize the association with.

  • version_id (str or None) – Version ID to use in the name of this association. If None, nothing is added.

Returns:

2-tuple consisting of:
  • association or None: The association or, if the item does not match this rule, None

  • [ProcessList[, …]]: List of items to process again.

Return type:

(association, reprocess_list)

dump(fmt=None, **kwargs)[source]

Serialize the association.

Parameters:
  • fmt (str) – The format to use to dump the association into.

  • **kwargs (dict) – List of arguments to pass to the registered routines for the current association type.

Returns:

Tuple where the first item is the suggested base name for the file. Second item is the serialization.

Return type:

(name, serialized)

Raises:
finalize()[source]

Finalize association.

Finalize or close-off this association. Perform validations, modifications, etc. to ensure that the association is complete.

Returns:

associations – List of fully-qualified associations that this association represents. None if 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

items()[source]

Provide items of data dictionary.

Returns:

The items of the data dictionary.

Return type:

dict_items

keys()[source]

Provide keys of data dictionary.

Returns:

The keys of the data dictionary.

Return type:

dict_keys

classmethod load(serialized, fmt=None, validate=True, **kwargs)[source]

Marshal a previously serialized association.

Parameters:
  • serialized (object) – The serialized form of the association.

  • fmt (str or None) – The format to force. If None, try all available.

  • validate (bool) – Validate against the class’ defined schema, if any.

  • **kwargs (dict) – Other arguments to pass to the load method

Returns:

association – The association.

Return type:

Association

Raises:

AssociationNotValidError – Cannot create or validate the association.

Notes

The serialized object can be in any format supported by the registered I/O routines. For example, for json and yaml formats, the input can be either a string or a file object containing the string.

match_constraint(item, conditions)[source]

Match against constraints.

Parameters:
  • item (dict) – The item to retrieve the values from

  • conditions (dict) – The conditions structure

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 rule_name()[source]

Return rule name.

Returns:

The name of the rule class.

Return type:

str

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 AssociationNotValidError is raised

Return 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.

values()[source]

Provide values of data dictionary.

Returns:

The values of the data dictionary.

Return type:

dict_values