templates.random_sources.file_source module
Object that provides randomness from a file.
- class templates.random_sources.file_source.FileSource(path: Path, delimiter: str = ..., queue_size: int = ..., queue: Queue[RR] | None = ..., retry_attempts: int = ..., retry_wait_s: float | None = ..., debug: bool = ..., *, deserializer: Callable[[str], RR])[source]
- class templates.random_sources.file_source.FileSource(path: Path, delimiter: str = ..., queue_size: int = ..., queue: Queue[RR] | None = ..., retry_attempts: int = ..., retry_wait_s: float | None = ..., debug: bool = ...)
Bases:
RandomnessSource
[RR
]Object for providing randomness from a file.
Implements tno.mpc.encryption_schemes.templates._randomness_manager.RandomnessSource.
- __init__(path, delimiter=',', queue_size=1000, queue=None, retry_attempts=3, retry_wait_s=1, debug=False, *, deserializer=None)[source]
Object that reads randomness from files.
- Parameters:
path (
Path
) – Path to file containing randomness.delimiter (
str
) – Separator between random numbers in the file.queue_size (
int
) – Maximum number of elements that can be put in the queue. Ignored if argument queue is also provided.queue (
Optional
[Queue
[TypeVar
(RR
)]]) – Queue to use for storing randomness from files.retry_attempts (
int
) – Number of attempts to get random value from the queue.retry_wait_s (
Optional
[float
]) – Number of seconds to wait between attempts to get random value from the queue. If None, wait until a value is yielded (e.g. wait=infinity).debug (
bool
) – Flag to determine whether debug information should be displayed.deserializer (
Optional
[Callable
[[str
],TypeVar
(RR
)]]) – Function for converting string from provided file into randomness object. Defaults to built-in “int” function.
- Raises:
TypeError – Argument to path is of incorrect type.
- get_one()[source]
Get one random value.
- Raises:
StopIteration – Randomness queue is empty and no active file thread remain.
TimeoutError – Randomness queue is empty and active file thread does not put new values into it.
ValueError – No threads instantiated for reading file.
- Return type:
TypeVar
(RR
)- Returns:
One random value.
- property nr_yielded: int
Number of random elements yielded.
- Returns:
Number of random elements yielded.
- property path: Path
Path to file that is read for randomness.
- Returns:
Path to file.