
from __future__ import absolute_import

from twisted.internet import reactor

import signal

signal_names = {}
for signame in dir(signal):
    if signame.startswith("SIG"):
        signum = getattr(signal, signame)
        if isinstance(signum, int):
            signal_names[signum] = signame

def install_shutdown_handlers(function, override_sigint=True):
    """Install the given function as a signal handler for all common shutdown
    signals (such as SIGINT, SIGTERM, etc). If override_sigint is ``False`` the
    SIGINT handler won't be install if there is already a handler in place
    (e.g.  Pdb)
    """
    reactor._handleSignals()
    signal.signal(signal.SIGTERM, function)
    if signal.getsignal(signal.SIGINT) == signal.default_int_handler or \
            override_sigint:
        signal.signal(signal.SIGINT, function)
    # Catch Ctrl-Break in windows
    if hasattr(signal, "SIGBREAK"):
        signal.signal(signal.SIGBREAK, function)

@@ -32,16 +32,30 @@
 e_import
+%0Aimport signal
 %0A%0Afrom t
@@ -86,30 +86,16 @@
 eactor%0A%0A
-import signal%0A
 %0Asignal_
@@ -163,13 +163,48 @@
 ith(
-%22SIG%22
+'SIG') and not signame.startswith('SIG_'
 ):%0A 
@@ -280,16 +280,16 @@
 , int):%0A
-
         
@@ -324,16 +324,17 @@
 igname%0A%0A
+%0A
 def inst
@@ -929,17 +929,17 @@
 al, 
-%22
+'
 SIGBREAK
 %22):%0A
@@ -934,17 +934,17 @@
 SIGBREAK
-%22
+'
 ):%0A     

Fix OS signal names