foca.utils package
Submodules
foca.utils.db module
Utility functions for interacting with a MongoDB database collection.
- foca.utils.db.find_id_latest(collection: <module 'pymongo.collection' from '/home/docs/checkouts/readthedocs.org/user_builds/foca/envs/latest/lib/python3.10/site-packages/pymongo/collection.py'>) ObjectId | None
Return ObjectId of newest document.
- Parameters:
collection – MongoDB collection from which ObjectId is to be retrieved.
- Returns:
ObjectId of newest document or
None
, if no document exists.
- foca.utils.db.find_one_latest(collection: <module 'pymongo.collection' from '/home/docs/checkouts/readthedocs.org/user_builds/foca/envs/latest/lib/python3.10/site-packages/pymongo/collection.py'>) Mapping[Any, Any] | None
Return newest document, stripped of ObjectId.
- Parameters:
collection – MongoDB collection from which the document is to be retrieved.
- Returns:
Newest document or
None
, if no document exists.
foca.utils.logging module
Utility functions for logging.
- foca.utils.logging.log_traffic(_fn: Callable | None = None, log_request: bool = True, log_response: bool = True, log_level: int = 20) Callable
Decorator for logging service requests and responses.
- Parameters:
log_request – Whether or not the request should be logged.
log_response – Whether or not the response should be logged.
log_level – Logging level, cf. https://docs.python.org/3/library/logging.html#logging-levels
- Returns:
The decorated function.
foca.utils.misc module
Miscellaneous utility functions.
- foca.utils.misc.generate_id(charset: str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', length: int = 6) str
Generate random string composed of specified character set.
- Parameters:
charset – A string of allowed characters or an expression evaluating to a string of allowed characters.
length – Length of returned string.
- Returns:
Random string of specified length and composed of specified character set.
- Raises:
TypeError – Raised if charset cannot be evaluated to a string or if length is not a positive integer.