ClassAd Class

class classad2.ClassAd(input=None)

A ClassAd is a collections.abc.MutableMapping with class:string keys that represents a “record expression” in the ClassAd language, more usually called “a ClassAd”.

Values in a ClassAd have types, and those types are represented as built-in Python types –

– with the following exceptions:

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

Expressions are always evaluated lazily, so setting a value to ExprTree 2 + 2 will not result in the value being the int 4; this also applies when constructing or parsing ClassAds or ExprTrees.

Parameters:

input (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) List[str]

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

Parameters:

expr (ExprTree) – The expression.

flatten(expr) ExprTree

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.

formatJson() str

Serialize this ClassAd in the JSON format.

formatOld() str

Serialize this ClassAd in the “old” format.

internalRefs(expr) List[str]

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

Parameters:

expr (ExprTree) – The expression.

lookup(attr) ExprTree

Return the ExprTree named by attr.

Parameters:

attr (str) – The attribute to look up.

matches(ad) bool

Evaluate the requirements attribute of the given ad in the context of this one, converting int and float results to bool.

Parameters:

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

Returns:

The evaluated or converted boolean, or False.

Return type:

bool

printJson() str

Serialize this ClassAd in the JSON format.

printOld() str

Serialize this ClassAd in the “old” format.

symmetricMatch(ad) bool

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

Parameters:

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