plainbox.impl.secure.qualifiers – Job Qualifiers

Qualifiers are callable objects that can be used to ‘match’ a job definition to some set of rules.

class plainbox.impl.secure.qualifiers.CompositeQualifier(*args, **kwargs)[source]

Bases: plainbox.impl.pod.POD

A JobQualifier that has qualifies jobs matching any inclusive qualifiers while not matching all of the exclusive qualifiers

as_dict() → dict

Return the data in this POD as a dictionary.

Note

UNSET values are not added to the dictionary.

as_tuple() → tuple

Return the data in this POD as a tuple.

Order of elements in the tuple corresponds to the order of field declarations.

designates(job)[source]
field_list = [<Field name:'qualifier_list'>]
get_primitive_qualifiers()[source]
get_vote(job)[source]

Get one of the VOTE_IGNORE, VOTE_INCLUDE, VOTE_EXCLUDE votes that this qualifier associated with the specified job.

Parameters:job – A IJobDefinition instance that is to be visited
Returns:
  • VOTE_INCLUDE if the job matches at least one qualifier voted to select it and no qualifiers voted to deselect it.
  • VOTE_EXCLUDE if at least one qualifier voted to deselect it
  • VOTE_IGNORE otherwise or if the list of qualifiers is empty.
is_primitive
namedtuple_cls

alias of CompositeQualifier

origin
qualifier_list
class plainbox.impl.secure.qualifiers.FieldQualifier(field, matcher, origin, inclusive=True)[source]

Bases: plainbox.impl.secure.qualifiers.SimpleQualifier

A SimpleQualifer that uses matchers to compare particular fields

VOTE_EXCLUDE = 0
VOTE_IGNORE = 2
VOTE_INCLUDE = 1
designates(job)
field

Name of the field to match

get_primitive_qualifiers()

Return a list of primitives that constitute this qualifier.

Returns:A list of IJobQualifier objects that each is the smallest, indivisible entity. Here it just returns a list of one element, itself.
get_simple_match(job)[source]

Check if the given job matches this qualifier.

This method should not be called directly, it is an implementation detail of SimpleQualifier class.

get_vote(job)

Get one of the VOTE_IGNORE, VOTE_INCLUDE, VOTE_EXCLUDE votes that this qualifier associated with the specified job.

Parameters:job – A IJobDefinition instance that is to be visited
Returns:
  • VOTE_INCLUDE if the job matches the simple qualifier concept embedded into this qualifier and this qualifier is inclusive.
  • VOTE_EXCLUDE if the job matches the simple qualifier concept embedded into this qualifier and this qualifier is not inclusive.
  • VOTE_IGNORE otherwise.
inclusive
is_primitive
matcher

The IMatcher-implementing object to use to check for the match

origin

Origin of this qualifier

This property can be used to trace the origin of a qualifier back to its definition point.

class plainbox.impl.secure.qualifiers.IMatcher[source]

Bases: object

Interface for objects that perform some kind of comparison on a value

match(value)[source]

Match (or not) specified value

Parameters:value – value to match
Returns:True if it matched, False otherwise
class plainbox.impl.secure.qualifiers.JobIdQualifier(id, origin, inclusive=True)[source]

Bases: plainbox.impl.secure.qualifiers.SimpleQualifier

A JobQualifier that designates a single job with a particular id

VOTE_EXCLUDE = 0
VOTE_IGNORE = 2
VOTE_INCLUDE = 1
designates(job)
get_primitive_qualifiers()

Return a list of primitives that constitute this qualifier.

Returns:A list of IJobQualifier objects that each is the smallest, indivisible entity. Here it just returns a list of one element, itself.
get_simple_match(job)[source]

Check if the given job matches this qualifier.

This method should not be called directly, it is an implementation detail of SimpleQualifier class.

get_vote(job)

Get one of the VOTE_IGNORE, VOTE_INCLUDE, VOTE_EXCLUDE votes that this qualifier associated with the specified job.

Parameters:job – A IJobDefinition instance that is to be visited
Returns:
  • VOTE_INCLUDE if the job matches the simple qualifier concept embedded into this qualifier and this qualifier is inclusive.
  • VOTE_EXCLUDE if the job matches the simple qualifier concept embedded into this qualifier and this qualifier is not inclusive.
  • VOTE_IGNORE otherwise.
id

identifier to match

inclusive
is_primitive
origin

Origin of this qualifier

This property can be used to trace the origin of a qualifier back to its definition point.

exception plainbox.impl.secure.qualifiers.NonPrimitiveQualifierOrigin[source]

Bases: Exception

Exception raised when IJobQualifier.origin is meaningless as it is being requested on a non-primitive qualifier such as the CompositeQualifier

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class plainbox.impl.secure.qualifiers.OperatorMatcher(op, value)[source]

Bases: plainbox.impl.secure.qualifiers.IMatcher

A matcher that applies a binary operator to the value

match(value)[source]
op

the operator to use

The operator is typically one of the functions from the operator module. For example. operator.eq corresponds to the == python operator.

value

The right-hand-side value to apply to the operator

The left-hand-side is the value that is passed to match()

class plainbox.impl.secure.qualifiers.PatternMatcher(pattern)[source]

Bases: plainbox.impl.secure.qualifiers.IMatcher

A matcher that compares values by regular expression pattern

match(value)[source]
pattern_text
class plainbox.impl.secure.qualifiers.RegExpJobQualifier(pattern, origin, inclusive=True)[source]

Bases: plainbox.impl.secure.qualifiers.SimpleQualifier

A JobQualifier that designates jobs by matching their id to a regular expression

VOTE_EXCLUDE = 0
VOTE_IGNORE = 2
VOTE_INCLUDE = 1
designates(job)
get_primitive_qualifiers()

Return a list of primitives that constitute this qualifier.

Returns:A list of IJobQualifier objects that each is the smallest, indivisible entity. Here it just returns a list of one element, itself.
get_simple_match(job)[source]

Check if the given job matches this qualifier.

This method should not be called directly, it is an implementation detail of SimpleQualifier class.

get_vote(job)

Get one of the VOTE_IGNORE, VOTE_INCLUDE, VOTE_EXCLUDE votes that this qualifier associated with the specified job.

Parameters:job – A IJobDefinition instance that is to be visited
Returns:
  • VOTE_INCLUDE if the job matches the simple qualifier concept embedded into this qualifier and this qualifier is inclusive.
  • VOTE_EXCLUDE if the job matches the simple qualifier concept embedded into this qualifier and this qualifier is not inclusive.
  • VOTE_IGNORE otherwise.
inclusive
is_primitive
origin

Origin of this qualifier

This property can be used to trace the origin of a qualifier back to its definition point.

pattern_text

text of the regular expression embedded in this qualifier

re_cache = {}
class plainbox.impl.secure.qualifiers.SimpleQualifier(origin, inclusive=True)[source]

Bases: plainbox.abc.IJobQualifier

Abstract base class that implements common features of simple (non composite) qualifiers. This allows two concrete subclasses below to have share some code.

VOTE_EXCLUDE = 0
VOTE_IGNORE = 2
VOTE_INCLUDE = 1
designates(job)[source]
get_primitive_qualifiers()[source]

Return a list of primitives that constitute this qualifier.

Returns:A list of IJobQualifier objects that each is the smallest, indivisible entity. Here it just returns a list of one element, itself.
get_simple_match(job)[source]

Get a simple yes-or-no boolean answer if the given job matches the simple aspect of this qualifier. This method should be overridden by concrete subclasses.

get_vote(job)[source]

Get one of the VOTE_IGNORE, VOTE_INCLUDE, VOTE_EXCLUDE votes that this qualifier associated with the specified job.

Parameters:job – A IJobDefinition instance that is to be visited
Returns:
  • VOTE_INCLUDE if the job matches the simple qualifier concept embedded into this qualifier and this qualifier is inclusive.
  • VOTE_EXCLUDE if the job matches the simple qualifier concept embedded into this qualifier and this qualifier is not inclusive.
  • VOTE_IGNORE otherwise.
inclusive
is_primitive
origin

Origin of this qualifier

This property can be used to trace the origin of a qualifier back to its definition point.

plainbox.impl.secure.qualifiers.get_flat_primitive_qualifier_list(qualifier_list)[source]
plainbox.impl.secure.qualifiers.select_jobs(job_list, qualifier_list)[source]

Select desired jobs.

Parameters:
  • job_list – A list of JobDefinition objects
  • qualifier_list – A list of IJobQualifier objects.
Returns:

A sub-list of JobDefinition objects, selected from job_list.

comments powered by Disqus