Constraint
- class jwst.associations.lib.constraint.Constraint(init=None, reduce=None, name=None, reprocess_on_match=False, reprocess_on_fail=False, work_over=ListCategory.BOTH, reprocess_rules=None)[source]
Bases:
object
Constraint that is made up of SimpleConstraints.
- constraints
List of
Constraint
orSimpleConstraint
that make this constraint.- Type:
[Constraint[,…]]
- matched
Result of the last
check_and_set
- Type:
- reduce
A reduction function with signature
x(iterable)
whereiterable
is thecomponents
list. Returns boolean indicating state of the components. Predefined functions are: -all
: True if all components return True -any
: True if any component returns True- Type:
function
Notes
Named constraints can be accessed directly through indexing:
>>> c = Constraint(SimpleConstraint(name="simple", value="a_value")) >>> c["simple"] SimpleConstraint({'sources': <function SimpleConstraint.__init__.<locals>.<lambda>, 'force_unique': True, 'test': <bound method SimpleConstraint.eq of SimpleConstraint({...})>, 'reprocess_on_match': False, 'reprocess_on_fail': False, 'work_over': 1, 'reprocess_rules': None, 'value': 'a_value', 'name': 'simple', 'matched': False})
Initialize a new Constraint.
- Parameters:
init (object or [object[,...]]) – A single object or list of objects where the objects are as follows. - SimpleConstraint or subclass - Constraint
reduce (function) – A reduction function with signature
x(iterable)
whereiterable
is thecomponents
list. Returns boolean indicating state of the components. Default value isConstraint.all
name (str or None) – Optional name for constraint.
reprocess_on_match (bool) – Reprocess the item if the constraint is satisfied.
reprocess_on_fail (bool) – Reprocess the item if the constraint is not satisfied.
work_over (ListCategory.[BOTH, EXISTING, RULES]) – The condition on which this constraint should operate.
reprocess_rules ([rule[,..]] or None) – List of rules to be applied to. If None, calling function will determine the ruleset. If empty, [], all rules will be used.
Attributes Summary
Return dictionary of constraints with duplicate names.
Return identifier for the constraint.
Methods Summary
all
(item, constraints)Return positive only if all results are positive.
any
(item, constraints)Return the first successful constraint.
append
(constraint)Append a new constraint.
check_and_set
(item[, work_over])Check and set the constraint.
copy
()Copy ourselves.
get_all_attr
(attribute[, name])Return the specified attribute for specified constraints.
notall
(item, constraints)Check if not all of the constraints match; true if not all do.
notany
(item, constraints)Check if none of the constraints match; true if none do.
preserve
()Preserve all constraint states.
restore
()Restore all constraint states.
Attributes Documentation
- dup_names
Return dictionary of constraints with duplicate names.
This method is meant to be overridden by classes that need to traverse a list of constraints.
- Returns:
dups – Returns a mapping between the duplicated name and all the constraints that define that name.
- Return type:
{str: [constraint[,…]][,…]}
Methods Documentation
- static all(item, constraints)[source]
Return positive only if all results are positive.
- Parameters:
item (ACID) – The candidate.
constraints (list[Constraint, ...]) – The list of constraints to check.
- Returns:
True if all constraints positive, with empty list. If no constraints, False and empty list. Otherwise False with list of constraints to reprocess.
- Return type:
bool, list(Constraint, …) or None
- static any(item, constraints)[source]
Return the first successful constraint.
- Parameters:
item (ACID) – The candidate.
constraints (list[Constraint, ...]) – The list of constraints to check.
- Returns:
False, [] if no match or constraints to reprocess. True, list(Constraints) if match found, and any constraints to reprocess listed.
- Return type:
bool, list(Constraint, …) or None
- check_and_set(item, work_over=ListCategory.BOTH)[source]
Check and set the constraint.
- Returns:
success, reprocess –
Returns 2-tuple of
success : True if check is successful.
List of
ProcessList
.
- Return type:
bool, [ProcessList[,…]]
- get_all_attr(attribute, name=None)[source]
Return the specified attribute for specified constraints.
- Parameters:
- Returns:
result – The list of values of the attribute in a tuple. If there is no attribute, an empty tuple is returned.
- Return type:
[(SimpleConstraint or Constraint, object)[,…]]
- Raises:
AttributeError – If the attribute is not found.
- static notall(item, constraints)[source]
Check if not all of the constraints match; true if not all do.
- Parameters:
item (ACID) – The candidate.
constraints (list[Constraint, ...]) – The list of constraints to check.
- Returns:
True if not all constraints match.
- Return type:
- static notany(item, constraints)[source]
Check if none of the constraints match; true if none do.
- Parameters:
item (ACID) – The candidate.
constraints (list[Constraint, ...]) – The list of constraints to check.
- Returns:
True if none of the constraints match.
- Return type: