ClassAd Class

class classad2.ClassAd(input=None)

The ClassAd language defines a ClassAd as a mapping from attribute names to expressions. A ClassAd is a collections.abc.MutableMapping from string keys to ExprTree values. Expressions are always evaluated before being returned, and unless you call lookup(), converted into the corresponding Python type.

A ClassAd expression may evaluate to (but is returned by ClassAd as):

When setting a value, the reverse is true. Additionally, None is converted to classad2.Value.Undefined and dicts are converted to ClassAds.

Parameters

input (Union[str, dict, None]) –

  • If None, create an empty ClassAd.

  • If a str, parse the ParserType.New format string and create the corresponding ClassAd.

  • If a dict, convert the dictionary to a ClassAd.

eval(attr)

Evaluate the attribute named by attr in the context of this ClassAd.

Parameters

attr (str) – The attribute to evaluate.

externalRefs(expr)

Returns the list of attributes referenced by the expression expr which are not defined by this ClassAd.

Parameters

expr (ExprTree) – The expression.

Return type

List[str]

flatten(expr)

Partially evaluate the expression in the context of this ad. Attributes referenced by the expression which are not defined by this ClassAd are not evaluated, but other attributes and subexpressions are. Thus, RequestMemory * 1024 * 1024 will evaluate to the amount of requested memory in bytes if this ClassAd defines the RequestMemory attribute, and to RequestMemory * 1048576 otherwise.

Parameters

expr (ExprTree) – The expression.

Return type

ExprTree

internalRefs(expr)

Returns the list of attributes referenced by the expression expr which are defined by this ClassAd.

Parameters

expr (ExprTree) – The expression.

Return type

List[str]

lookup(attr)

Return the ExprTree named by attr.

Parameters

attr (str) – The attribute to look up.

Return type

ExprTree

matches(ad)

Evaluate the requirements attribute of the given ad in the context of this one.

Parameters

ad (ClassAd) – The ClassAd to test for matching.

Return type

bool

Returns

True if and only if the evaluation returned True.

printJson()

Serialize this ClassAd in the JSON format.

Return type

str

printOld()

Serialize this ClassAd in the “old” format.

Return type

str

symmetricMatch(ad)

Equivalent to self.matches(ad) and ad.matches(self).

Parameters

ad (ClassAd) – The ClassAd to match for and against.

Return type

bool