pyhanko.pdf_utils.config_utils module¶
This module contains utilities for allowing dataclasses to be populated by user-provided configuration (e.g. from a Yaml file).
Note
On naming conventions: this module converts hyphens in key names to underscores as a matter of course.
-
exception
pyhanko.pdf_utils.config_utils.
ConfigurationError
¶ Bases:
ValueError
Signal configuration errors.
-
class
pyhanko.pdf_utils.config_utils.
ConfigurableMixin
¶ Bases:
object
General configuration mixin for dataclasses
-
classmethod
process_entries
(config_dict)¶ Hook method that can modify the configuration dictionary to overwrite or tweak some of their values (e.g. to convert string parameters into more complex Python objects)
Subclasses that override this method should call
super().process_entries()
, and leave keys that they do not recognise untouched.- Parameters
config_dict – A dictionary containing configuration values.
- Raises
ConfigurationError – when there is a problem processing a relevant entry.
-
classmethod
from_config
(config_dict)¶ Attempt to instantiate an object of the class on which it is called, by means of the configuration settings passed in.
First, we check that the keys supplied in the dictionary correspond to data fields on the current class. Then, the dictionary is processed using the
process_entries()
method. The resulting dictionary is passed to the initialiser of the current class as a kwargs dict.- Parameters
config_dict – A dictionary containing configuration values.
- Returns
An instance of the class on which it is called.
- Raises
ConfigurationError – when an unexpected configuration key is encountered or left unfilled, or when there is a problem processing one of the config values.
-
classmethod