Coverage for certbot/error_handler.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Registers functions to be called if an exception or signal occurs."""
# pylint: disable=unused-import, no-name-in-module # pylint: enable=unused-import, no-name-in-module
# _SIGNALS stores the signals that will be handled by the ErrorHandler. These # signals were chosen as their default handler terminates the process and could # potentially occur from inside Python. Signals such as SIGILL were not # included as they could be a sign of something devious and we should terminate # immediately. signal.SIGXCPU, signal.SIGXFSZ]: # Adding only those signals that their default action is not Ignore. # This is platform-dependent, so we check it dynamically.
"""Context manager for running code that must be cleaned up on failure.
The context manager allows you to register functions that will be called when an exception (excluding SystemExit) or signal is encountered. Usage::
handler = ErrorHandler(cleanup1_func, *cleanup1_args, **cleanup1_kwargs) handler.register(cleanup2_func, *cleanup2_args, **cleanup2_kwargs)
with handler: do_something()
Or for one cleanup function::
with ErrorHandler(func, args, kwargs): do_something()
If an exception is raised out of do_something, the cleanup functions will be called in last in first out order. Then the exception is raised. Similarly, if a signal is encountered, the cleanup functions are called followed by the previously received signal handler.
Each registered cleanup function is called exactly once. If a registered function raises an exception, it is logged and the next function is called. Signals received while the registered functions are executing are deferred until they finish.
"""
# SystemExit is ignored to properly handle forks that don't exec else: traceback.format_exception(exec_type, exec_value, trace)))
# type: (Callable, *Any, **Any) -> None """Sets func to be run with the given arguments during cleanup.
:param function func: function to be called in case of an error
"""
"""Calls all registered functions"""
"""Sets signal handlers for signals in _SIGNALS.""" # If prev_handler is None, the handler was set outside of Python
"""Resets signal handlers for signals in _SIGNALS."""
"""Replacement function for handling received signals.
Store the received signal. If we are executing the code block in the body of the context manager, stop by raising signal exit.
:param int signum: number of current signal
"""
"""Finally call the deferred signals."""
"""Context manager for running code that must be cleaned up.
Subclass of ErrorHandler, with the same usage and parameters. In addition to cleaning up on all signals, also cleans up on regular exit. """
|