Decision evaluation

class bast3st.decisions.Criterion[source]

Bases: DecisionEntity[Features]

__init__(*, failure_explaination)[source]
Parameters:

failure_explaination (IntoTextValue[Features] | None)

Return type:

None

catch(error: err, *, fallback: Criterion[Features2], only_if: Criterion[Features3] | None = None) → Criterion[Features | Features2 | Features3][source]
catch(error: err, *, action: Action[Features2], only_if: Criterion[Features3] | None = None) → Criterion[Features | Features2 | Features3]
catch(error: err, *, only_if: Criterion[Features2] | None = None, fallback: Criterion[Features3] | None, action: Action[Features4] | None) → Criterion[Features | Features2 | Features3 | Features4]
Parameters:
Return type:

Criterion[Features | Features2 | Features3 | Features4]

negate(*, failure_explaination=None)[source]

Create criterion with the success condition negated

Parameters:

failure_explaination (IntoTextValue[Features2] | None)

Return type:

Criterion[Features | Features2]

with_failure_explaination(val)[source]
Parameters:

val (IntoTextValue[Features2])

Return type:

Criterion[Features | Features2]

property negated: Criterion[Features]

Criterion with the success condition negated

class bast3st.decisions.DecisionEntity[source]

Bases: Generic[Features], ABC

class bast3st.decisions.FutureArray[source]

Bases: Protocol[Features]

A FutureArray represents a specific source of multiple values that are available – somewhere in the future – during the evaluation of a submission.

Examples are:
  • INPUT: access the input a submission got in the current test

  • OUTPUT: access the output a submission produced

  • LIST(name): access the list with the provided name

This type can be used similarily to a list of Selector’s:

>>> first_input = INPUT.first # or INPUT[0]
>>> first_input
INPUT[0]
>>> last_output = OUTPUT.last # or OUTPUT[-1]
>>> last_output
OUTPUT[-1]
>>> mylist = LIST("mylist")
>>> second_item = mylist[1] # or mylist.index1(2)
>>> second_item
LIST("mylist")[1]
>>> length_of_mylist = mylist.length # don't use len(mylist)
>>> length_of_mylist
LIST("mylist").length

Attention

The values you receive are special instances of Selector and can be understood as placeholders. For more see Placeholders live in the future.

(This type should not be instantiated directly)

__init__(*args, **kwargs)
from_end1(onebased_n)[source]
Parameters:

onebased_n (int)

Return type:

Value[Features]

from_start1(onebased_n)[source]
Parameters:

onebased_n (int)

Return type:

Value[Features]

index1(onebased_n)[source]
Parameters:

onebased_n (int)

Return type:

Value[Features]

sum()[source]

Sum all values of the mapping, texts and collections count as zeros

Return type:

Value[Features]

property first: Value[Features]
property last: Value[Features]
property length: Value[Features]
class bast3st.decisions.FutureMapItem[source]

Bases: Selector[Features | Features2], FutureMapping[Features | Features2]

__init__(mapping, key)[source]
Parameters:
Return type:

None

class bast3st.decisions.FutureMapping[source]

Bases: DecisionEntity[Features]

This is a key-value-mapping that lives in the future. (See FutureArray)

__init__(kind, *args, **kwargs)[source]
Parameters:

kind (MapScopeT)

Return type:

None

from_end1(onebased_n)[source]
Parameters:

onebased_n (int)

Return type:

Value[Features]

from_start1(onebased_n)[source]
Parameters:

onebased_n (int)

Return type:

Value[Features]

index1(onebased_n)[source]
Parameters:

onebased_n (int)

Return type:

Value[Features]

keys()[source]

Array of all keys of the mapping (indexed by numbers), in their sorting order

Return type:

FutureArray[Features]

sum()[source]

Sum all values of the mapping, texts and collections count as zeros

Return type:

Value[Features]

values()[source]

Array of all values of the mapping (indexed by numbers), in the order of the sorted keys

Return type:

FutureArray[Features]

property first: Value[Features]

On arrays this will return the first element (index 0), but on mappings this will be the element with the smallest key (sort order)

property kind: MapScopeT
property last: Value[Features]

On arrays this will return the last element (length-1), but on mappings this will be the element with the biggest key (sort order)

property length: Value[Features]

The number of items in the mapping

class bast3st.decisions.NetworkRequest[source]

Bases: FutureMapping[Features | Features2 | Features3]

A network request to a specific server. The server’s domain has to be a static string and must be explicitly whitelisted by the server administrator

Parameters:
  • server (str) – The server to contact

  • route (str) – The part after the first slash that specifies the route on the server

  • method – The HTTP Method to use for the request. Only GET and POST are supported

  • json – A dict of values that should be sent as json to the specified url. The json attribute is not available for GET requests.

  • allowed_status – The HTTP status codes of the response that are considered normal behaviour of the API. This can be a single number or a tuple of status codes. If the server responds with a code that isn’t listed here, it will be considered one of the Catchable errors, but only if a map item is used that is expected to require a successful response.

Catchable errors

__init__(*, server: str, route: IntoTextValue[Features], method: Literal['GET'], allowed_status: int | tuple[int, ...] = 200) → None[source]
__init__(*, server: str, route: IntoTextValue[Features], method: Literal['POST'], json: dict[str, IntoValue[Features3]] | list[tuple[IntoValue[Features2], IntoValue[Features3]]] | None = None, allowed_status: int | tuple[int, ...] = 200) → None
Parameters:
Return type:

None

class bast3st.decisions.Selector[source]

Bases: Value[Features]

__init__(opcode, *args)[source]
Parameters:

opcode (SelectorOpcodeT)

Return type:

None

class bast3st.decisions.SerAct[source]

Bases: Action[Features]

__init__(opcode, *args, **kwargs)[source]
Parameters:

opcode (str)

Return type:

None

class bast3st.decisions.TransformSingleNoParam[source]

Bases: Transformation[Features]

__init__(opcode)[source]
Parameters:

opcode (str)

Return type:

None

on(value)[source]
Parameters:

value (IntoValue[Features2])

Return type:

Value[Features | Features2]

class bast3st.decisions.Transformation[source]

Bases: DecisionEntity[Features], ABC

__init__()[source]
Return type:

None

abstractmethod on(value)[source]
Parameters:

value (IntoValue[Features2])

Return type:

Value[Features | Features2]

class bast3st.decisions.Value[source]

Bases: DecisionEntity[Features], ABC

classmethod of(val: IntoValue[Features]) → Value[Features][source]
classmethod of(val: IntoValue[Features] | None) → Value[Features] | None

Exactly like ofStrict but returns None if input is None

classmethod ofStrict(val)[source]

Converts a set of supported types into sub-classes of Value

Raises:

TypeError – If the input is of a not-supported type

Parameters:

val (IntoValue[Features])

Return type:

Value[Features]

catch(error: err, *, default_value: IntoValue[Features2], only_if: Criterion[Features3] | None = None) → Value[Features | Features2 | Features3][source]
catch(error: err, *, action: Action[Features2], only_if: Criterion[Features3] | None = None) → Value[Features | Features2 | Features3]
catch(error: err, *, only_if: Criterion[Features2] | None = None, default_value: IntoValue[Features3] | None, action: Action[Features4] | None) → Value[Features | Features2 | Features3 | Features4]
Parameters:
Return type:

Value[Features | Features2 | Features3 | Features4]

contains_only_this_number(val, *, failure_explaination=None)[source]
Parameters:
Return type:

Criterion[Features | Features2 | Features3]

contains_text(val, *, failure_explaination=None)[source]
Parameters:
Return type:

Criterion[Features | Features2 | Features3]

contains_this_number(val, *, failure_explaination=None)[source]
Parameters:
Return type:

Criterion[Features | Features2 | Features3]

contains_with_gaps(*val, failure_explaination=None)[source]

If this contains a specific sequence of fragments, with arbitraty gaps inbetween

Parameters:
Return type:

Criterion[Features | Features2 | Features3]

first_capture(pattern)[source]

Tries to match a Rust regex regular expression and returns a mapping of the first match that allows accessing the captured parts.

Warning

As Placeholders live in the future the pattern will be evaluated not by the Python re regular expression library, but by the one that is used by the server implementation. The required syntax can be found in the regex crate

Parameters:

pattern (IntoTextValue[Features2])

Return type:

FutureMapping[Features | Features2]

matches(pattern, failure_explaination=None)[source]

If this matches a Rust regex regular expression.

Warning

As Placeholders live in the future the pattern will be evaluated not by the Python re regular expression library, but by the one that is used by the server implementation. The required syntax can be found in the regex crate

Parameters:
Return type:

Criterion[Features | Features2 | Features3]

pipe(*operations)[source]

Execute a sequence of transformations in order on this value and return the final result. The value itself is the input to the first Transformation and every further Transformation gets the output of the last as input. The last Transformation’s output will be returned.

Parameters:

operations (Transformation[Features2])

Return type:

Value[Features | Features2]

text_is_contained_in(val, *, failure_explaination=None)[source]
Parameters:
Return type:

Criterion[Features | Features2 | Features3]

to_lower()[source]
Return type:

Value[Features]

to_upper()[source]
Return type:

Value[Features]

trim()[source]
Return type:

Value[Features]

trim_end()[source]
Return type:

Value[Features]

trim_start()[source]
Return type:

Value[Features]

class bast3st.decisions.all_of[source]

Bases: SerCrit[Features | Features2]

__init__(*clauses, failure_explaination=None)[source]
Parameters:
Return type:

None

class bast3st.decisions.any_of[source]

Bases: SerCrit[Features | Features2]

__init__(*clauses, failure_explaination=None)[source]
Parameters:
Return type:

None

class bast3st.decisions.compare[source]

Bases: SerCrit[Features | Features2 | Features3]

classmethod eq(left, right)[source]
Parameters:
Return type:

compare

classmethod ge(left, right)[source]
Parameters:
Return type:

compare

classmethod gt(left, right)[source]
Parameters:
Return type:

compare

classmethod le(left, right)[source]
Parameters:
Return type:

compare

classmethod lt(left, right)[source]
Parameters:
Return type:

compare

classmethod neq(left, right)[source]
Parameters:
Return type:

compare

__init__(left, relation, right, *, failure_explaination=None)[source]

Compare two future values with a given relation

Parameters:
  • left (Value) – first future value

  • relation (RelationT) – the comparison relation to use

  • right (Value) – second future value

  • failure_explaination (IntoTextValue[Features3] | None)

Return type:

None

property left: Value[Features]
property relation
property right: Value[Features2]
bast3st.decisions.LIST(name)[source]
Parameters:

name (str)

Return type:

FutureArray[Literal[‘f-read-rundata’]]

bast3st.decisions.VAR(name)[source]
Parameters:

name (str)

Return type:

Value[Literal[‘f-read-rundata’]]

bast3st.decisions.concat(*clauses)[source]
Parameters:

clauses (IntoValue[Features])

Return type:

Value[Features]

bast3st.decisions.if_then_else(if_: Criterion[Features], then_: Criterion[Features2], else_: Criterion[Features3]) → Criterion[Features | Features2 | Features3][source]
bast3st.decisions.if_then_else(if_: Criterion[Features], then_: IntoValue[Features2], else_: IntoValue[Features3]) → Value[Features | Features2 | Features3]
bast3st.decisions.if_then_else(if_: Criterion[Features], then_: Action[Features2], else_: Action[Features3]) → Action[Features | Features2 | Features3]
bast3st.decisions.negated(criterion, *, failure_explaination=None)[source]

Negate a criterion so that it accepts exactly when the original one didn’t accept

Parameters:
Return type:

Criterion[Features | Features2]

bast3st.decisions.ALWAYS_FULFILLED: Criterion = ALWAYS_FULFILLED

a special criterion that is always fulfilled

bast3st.decisions.FLAGS: FutureMapping = FLAGS

FutureMapping that allows reading arbitraty flags, see Setting and reading flags for details

bast3st.decisions.INPUT: FutureArray[Literal['f-read-rundata']] = INPUT

FutureArray that represents the output a submission got during the current test

bast3st.decisions.NEVER_FULFILLED: Criterion = NEVER_FULFILLED

a special criterion that is never fulfilled

bast3st.decisions.OUTPUT: FutureArray[Literal['f-read-rundata']] = OUTPUT

FutureArray that represents the output a submission produced during the current test

bast3st.decisions.PARAM = PARAM

FutureMapping that allows reading set parameters, see Parameters for details

bast3st.decisions.RANDOMS: FutureArray[Literal['f-read-rundata']] = RANDOMS

FutureArray that represents the random numbers a submission requested and got during the current test

bast3st.decisions.to_lower = <bast3st.decisions.TransformSingleNoParam object>

Transformation converting a value to lowercase

Parameters:

value (IntoValue[Features2])

Return type:

Value[Features | Features2]

bast3st.decisions.to_upper = <bast3st.decisions.TransformSingleNoParam object>

Transformation converting a value to uppercase

Parameters:

value (IntoValue[Features2])

Return type:

Value[Features | Features2]

bast3st.decisions.trim = <bast3st.decisions.TransformSingleNoParam object>

Transformation removing all whitespace from start and end of the stringified value

Parameters:

value (IntoValue[Features2])

Return type:

Value[Features | Features2]

bast3st.decisions.trim_end = <bast3st.decisions.TransformSingleNoParam object>

Transformation removing all whitespace from the end of the stringified value

Parameters:

value (IntoValue[Features2])

Return type:

Value[Features | Features2]

bast3st.decisions.trim_start = <bast3st.decisions.TransformSingleNoParam object>

Transformation removing all whitespace from the start of the stringified value

Parameters:

value (IntoValue[Features2])

Return type:

Value[Features | Features2]

type bast3st.decisions.ArrayScopeT = Literal['arrayview'] | StdArrayScopeT
type bast3st.decisions.ContainOpcodeT = Literal['contain-onlynum', 'contain-num', 'contain-text']
type bast3st.decisions.IntoTextValue = str | Template | Value

Any type that can be converted into a Value and is likely a text

type bast3st.decisions.IntoValue = IntoTextValue | float | int | bool

Any type that can be converted into a Value

type bast3st.decisions.MapScopeT = Literal['network', 'first-capture', 'read-input', 'read-output', 'read-lists', 'read-randoms', 'read-variables', 'read-param', 'read-flags', 'mapitem', 'view']
type bast3st.decisions.RelationT = Literal['==', '!=', '<=', '>=', '<', '>']

A comparison operator string to specify the desired relation

type bast3st.decisions.SelectorOpcodeT = Literal['var', 'arrayitem', 'arrayprop', 'mapitem', 'mapprop']
type bast3st.decisions.StdArrayScopeT = Literal['ior', 'list']