Socon utils
This document covers all modules in socon.utils. Most of the
modules in socon.utils are designed for internal use but we believe
that it can be useful as well for your framework.
socon.utils.func
- get_object_attr()
Return a value from any object attribute. This function allows you to pass a default value if not found or raise a ValueError.
socon.utils.reshape
- class FileReshape
Base class to modify the content of a file.
Read-only attributes
- FileReshape.content
The content of the file given at the instance creation.
Methods
- FileReshape.__init__(filepath: Union[str, PathLike])
When you create
FileReshapeinstance, you need to give the path to the file you want to work with. The file is then read and the content is saved inFileReshape.content.
- FileReshape.revert_modif()
Revert the modification applied to the content of the file. Really useful when you have modified the content of a file for a moment but you want to get back to the original quickly after.
- FileReshape.write(content: str = None, dest: Union[str, Path] = None, **kwargs)
Write content to the current file or to a another file using the
destparameter. Also, this method will allow to pass any parameters to the open function. If you don’t pass any content to the method,FileReshapewill use theFileReshape.contentof the current instance.
- FileReshape.replace(pattern: str, replace: str, **kwargs)
Replace any string that match the pattern in the file. The method use
re.subfor replacing the string. You can pass any argument to this function using thekwargsargument.
- FileReshape.read_file()
Read the content of the file.
- FileReshape.render(context: dict)
Render a specific template with tags like {{ name }}. This works like
jinja. You can pass a dictionary of name and value to render a template that contain{{ name }}tags.
socon.utils.module_loading
Functions for working with Python modules.
- import_string(dotted_path: str)
Imports a dotted module path and returns the attribute/class designated by the last name in the path. Raises
ImportErrorif the import failed. For example:from socon.utils.module_loading import import_string ImproperlyConfigured = import_string('socon.core.exceptions.ImproperlyConfigured')
is equivalent to:
from socon.core.exceptions import ImproperlyConfigured