Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python2..../unittest
File: signals.py
import signal
[0] Fix | Delete
import weakref
[1] Fix | Delete
[2] Fix | Delete
from functools import wraps
[3] Fix | Delete
[4] Fix | Delete
__unittest = True
[5] Fix | Delete
[6] Fix | Delete
[7] Fix | Delete
class _InterruptHandler(object):
[8] Fix | Delete
def __init__(self, default_handler):
[9] Fix | Delete
self.called = False
[10] Fix | Delete
self.original_handler = default_handler
[11] Fix | Delete
if isinstance(default_handler, (int, long)):
[12] Fix | Delete
if default_handler == signal.SIG_DFL:
[13] Fix | Delete
# Pretend it's signal.default_int_handler instead.
[14] Fix | Delete
default_handler = signal.default_int_handler
[15] Fix | Delete
elif default_handler == signal.SIG_IGN:
[16] Fix | Delete
# Not quite the same thing as SIG_IGN, but the closest we
[17] Fix | Delete
# can make it: do nothing.
[18] Fix | Delete
def default_handler(unused_signum, unused_frame):
[19] Fix | Delete
pass
[20] Fix | Delete
else:
[21] Fix | Delete
raise TypeError("expected SIGINT signal handler to be "
[22] Fix | Delete
"signal.SIG_IGN, signal.SIG_DFL, or a "
[23] Fix | Delete
"callable object")
[24] Fix | Delete
self.default_handler = default_handler
[25] Fix | Delete
[26] Fix | Delete
def __call__(self, signum, frame):
[27] Fix | Delete
installed_handler = signal.getsignal(signal.SIGINT)
[28] Fix | Delete
if installed_handler is not self:
[29] Fix | Delete
# if we aren't the installed handler, then delegate immediately
[30] Fix | Delete
# to the default handler
[31] Fix | Delete
self.default_handler(signum, frame)
[32] Fix | Delete
[33] Fix | Delete
if self.called:
[34] Fix | Delete
self.default_handler(signum, frame)
[35] Fix | Delete
self.called = True
[36] Fix | Delete
for result in _results.keys():
[37] Fix | Delete
result.stop()
[38] Fix | Delete
[39] Fix | Delete
_results = weakref.WeakKeyDictionary()
[40] Fix | Delete
def registerResult(result):
[41] Fix | Delete
_results[result] = 1
[42] Fix | Delete
[43] Fix | Delete
def removeResult(result):
[44] Fix | Delete
return bool(_results.pop(result, None))
[45] Fix | Delete
[46] Fix | Delete
_interrupt_handler = None
[47] Fix | Delete
def installHandler():
[48] Fix | Delete
global _interrupt_handler
[49] Fix | Delete
if _interrupt_handler is None:
[50] Fix | Delete
default_handler = signal.getsignal(signal.SIGINT)
[51] Fix | Delete
_interrupt_handler = _InterruptHandler(default_handler)
[52] Fix | Delete
signal.signal(signal.SIGINT, _interrupt_handler)
[53] Fix | Delete
[54] Fix | Delete
[55] Fix | Delete
def removeHandler(method=None):
[56] Fix | Delete
if method is not None:
[57] Fix | Delete
@wraps(method)
[58] Fix | Delete
def inner(*args, **kwargs):
[59] Fix | Delete
initial = signal.getsignal(signal.SIGINT)
[60] Fix | Delete
removeHandler()
[61] Fix | Delete
try:
[62] Fix | Delete
return method(*args, **kwargs)
[63] Fix | Delete
finally:
[64] Fix | Delete
signal.signal(signal.SIGINT, initial)
[65] Fix | Delete
return inner
[66] Fix | Delete
[67] Fix | Delete
global _interrupt_handler
[68] Fix | Delete
if _interrupt_handler is not None:
[69] Fix | Delete
signal.signal(signal.SIGINT, _interrupt_handler.original_handler)
[70] Fix | Delete
[71] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function