aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/misc
diff options
context:
space:
mode:
authorJ08nY2021-01-20 20:24:11 +0100
committerJ08nY2021-01-20 20:24:11 +0100
commit9ec68bdb56882777e5b3670380bf1e1ad7d0a7a3 (patch)
treebb695e485808e4d0517d84053019e2f7ddb03679 /pyecsca/misc
parentadc3cd52147f35e0a7cc9008ac96619dd89cda48 (diff)
downloadpyecsca-9ec68bdb56882777e5b3670380bf1e1ad7d0a7a3.tar.gz
pyecsca-9ec68bdb56882777e5b3670380bf1e1ad7d0a7a3.tar.zst
pyecsca-9ec68bdb56882777e5b3670380bf1e1ad7d0a7a3.zip
The big documentation patch.
Diffstat (limited to 'pyecsca/misc')
-rw-r--r--pyecsca/misc/__init__.py2
-rw-r--r--pyecsca/misc/cfg.py32
2 files changed, 32 insertions, 2 deletions
diff --git a/pyecsca/misc/__init__.py b/pyecsca/misc/__init__.py
index 46334eb..f093677 100644
--- a/pyecsca/misc/__init__.py
+++ b/pyecsca/misc/__init__.py
@@ -1 +1 @@
-"""Miscellaneous things."""
+"""package for miscellaneous things."""
diff --git a/pyecsca/misc/cfg.py b/pyecsca/misc/cfg.py
index 1c1d214..df3cce1 100644
--- a/pyecsca/misc/cfg.py
+++ b/pyecsca/misc/cfg.py
@@ -1,3 +1,7 @@
+"""
+This module provides functions for runtime configuration of the toolkit, such as how errors are handled, or which
+:py:class:`Mod` implementation is used.
+"""
from copy import deepcopy
from contextvars import ContextVar, Token
@@ -119,21 +123,47 @@ _config: ContextVar[Config] = ContextVar("config", default=Config())
@public
def getconfig() -> Config:
+ """
+ Get the current config.
+
+ :return: The current config.
+ """
return _config.get()
@public
def setconfig(cfg: Config) -> Token:
+ """
+ Set the current config.
+
+ :param cfg: The config to set.
+ :return: A token that can be used to reset the config to the previous one.
+ """
return _config.set(cfg)
@public
-def resetconfig(token: Token):
+def resetconfig(token: Token) -> None:
+ """
+ Reset the config to the previous one.
+
+ :param token: A token from :py:func:`setconfig()`.
+ """
_config.reset(token)
@public
class TemporaryConfig(object):
+ """
+ A temporary config context manager, can be entered as follows:
+
+ .. code-block:: python
+
+ with TemporaryConfig() as cfg:
+ cfg.some_property = some_value
+ ...
+ """
+
def __init__(self):
self.new_config = deepcopy(getconfig())