pyecsca.ec.context module

Provides classes for tracing the execution of operations.

The operations include key generation, scalar multiplication, formula execution and individual operation evaluation. These operations are traced in Context classes using Actions. Different contexts trace actions differently.

A DefaultContext traces actions into a tree as they are executed (a scalar multiplication actions has as its children an ordered list of the individual formula executions it has done).

A PathContext works like a DefaultContext that only traces an action on a particular path in the tree.

class pyecsca.ec.context.Action[source]

Bases: object

An Action.

inside: bool
class pyecsca.ec.context.ResultAction[source]

Bases: Action

An action that has a result.

property result: Any
exit(result)[source]
inside: bool
class pyecsca.ec.context.Tree[source]

Bases: OrderedDict

A recursively-implemented tree.

get_by_key(path)[source]

Get the value in the tree at a position given by the path.

Parameters:

path (List) – The path to get.

Return type:

Any

Returns:

The value in the tree.

get_by_index(path)[source]

Get the key and value in the tree at a position given by the path of indices.

The nodes inside a level of a tree are ordered by insertion order.

Parameters:

path (List[int]) – The path to get.

Return type:

Tuple[Any, Any]

Returns:

The key and value.

repr(depth=0)[source]

Construct a textual representation of the tree. Useful for visualization and debugging.

Parameters:

depth (int) –

Return type:

str

Returns:

The resulting textual representation.

walk(callback)[source]

Walk the tree, depth-first, with the callback.

Parameters:

callback (Callable[[Any], None]) – The callback to call for all values in the tree.

Return type:

None

clear() None.  Remove all items from od.
copy() a shallow copy of od
fromkeys(value=None)

Create a new ordered dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
move_to_end(key, last=True)

Move an existing element to the end (or beginning if last is false).

Raise KeyError if the element does not exist.

pop(key[, default]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(last=True)

Remove and return a (key, value) pair from the dictionary.

Pairs are returned in LIFO order if last is true or FIFO order if false.

setdefault(key, default=None)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values
class pyecsca.ec.context.Context[source]

Bases: ABC

Context is an object that traces actions which happen.

There is always one context active, see functions getcontext(), setcontext() and resetcontext().

abstract enter_action(action)[source]

Enter into an action (i.e. start executing it).

Parameters:

action (Action) – The action.

Return type:

None

abstract exit_action(action)[source]

Exit from an action (i.e. stop executing it).

Parameters:

action (Action) – The action.

Return type:

None

class pyecsca.ec.context.DefaultContext[source]

Bases: Context

Context that traces executions of actions in a tree.

actions: Tree
current: List[Action]
enter_action(action)[source]

Enter into an action (i.e. start executing it).

Parameters:

action (Action) – The action.

Return type:

None

exit_action(action)[source]

Exit from an action (i.e. stop executing it).

Parameters:

action (Action) – The action.

Return type:

None

class pyecsca.ec.context.PathContext(path)[source]

Bases: Context

Context that traces targeted actions.

Create a PathContext.

Parameters:

path (Sequence[int]) – The path of an action in the execution tree that will be captured.

path: List[int]
current: List[int]
current_depth: int
value: Any
enter_action(action)[source]

Enter into an action (i.e. start executing it).

Parameters:

action (Action) – The action.

Return type:

None

exit_action(action)[source]

Exit from an action (i.e. stop executing it).

Parameters:

action (Action) – The action.

Return type:

None

pyecsca.ec.context.local(ctx=None)[source]

Use a local context.

Parameters:

ctx (Optional[Context]) – If none, current context is copied.

Return type:

ContextManager

Returns:

A context manager.