mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 03:41:53 +02:00
Move SignalExit to errors.py
This commit is contained in:
@@ -5,6 +5,7 @@ import os
|
|||||||
import signal
|
import signal
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from certbot import errors
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -19,14 +20,6 @@ _SIGNALS = ([signal.SIGTERM] if os.name == "nt" else
|
|||||||
signal.SIGXCPU, signal.SIGXFSZ])
|
signal.SIGXCPU, signal.SIGXFSZ])
|
||||||
|
|
||||||
|
|
||||||
class SignalExit(Exception):
|
|
||||||
"""This exception is used stop of execution of the code in the body of the
|
|
||||||
ErrorHandler context manager.
|
|
||||||
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ErrorHandler(object):
|
class ErrorHandler(object):
|
||||||
"""Registers functions to be called if an exception or signal occurs.
|
"""Registers functions to be called if an exception or signal occurs.
|
||||||
|
|
||||||
@@ -62,7 +55,7 @@ class ErrorHandler(object):
|
|||||||
def __exit__(self, exec_type, exec_value, trace):
|
def __exit__(self, exec_type, exec_value, trace):
|
||||||
self.body_executed = True
|
self.body_executed = True
|
||||||
retval = False
|
retval = False
|
||||||
if exec_type is SignalExit:
|
if exec_type is errors.SignalExit:
|
||||||
logger.debug("Encountered signals: %s", self.received_signals)
|
logger.debug("Encountered signals: %s", self.received_signals)
|
||||||
self.call_registered()
|
self.call_registered()
|
||||||
for signum in self.received_signals:
|
for signum in self.received_signals:
|
||||||
@@ -120,7 +113,7 @@ class ErrorHandler(object):
|
|||||||
"""
|
"""
|
||||||
self.received_signals.append(signum)
|
self.received_signals.append(signum)
|
||||||
if not self.body_executed:
|
if not self.body_executed:
|
||||||
raise SignalExit
|
raise errors.SignalExit
|
||||||
|
|
||||||
def call_signal(self, signum):
|
def call_signal(self, signum):
|
||||||
"""Calls the signal given by signum.
|
"""Calls the signal given by signum.
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ class HookCommandNotFound(Error):
|
|||||||
"""Failed to find a hook command in the PATH."""
|
"""Failed to find a hook command in the PATH."""
|
||||||
|
|
||||||
|
|
||||||
|
class SignalExit(Error):
|
||||||
|
"""A Unix signal was recieved while in the ErrorHandler context manager."""
|
||||||
|
|
||||||
|
|
||||||
# Auth Handler Errors
|
# Auth Handler Errors
|
||||||
class AuthorizationError(Error):
|
class AuthorizationError(Error):
|
||||||
"""Authorization error."""
|
"""Authorization error."""
|
||||||
|
|||||||
Reference in New Issue
Block a user