Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/python27/lib64/python2....
File: atexit.py
"""
[0] Fix | Delete
atexit.py - allow programmer to define multiple exit functions to be executed
[1] Fix | Delete
upon normal program termination.
[2] Fix | Delete
[3] Fix | Delete
One public function, register, is defined.
[4] Fix | Delete
"""
[5] Fix | Delete
[6] Fix | Delete
__all__ = ["register"]
[7] Fix | Delete
[8] Fix | Delete
import sys
[9] Fix | Delete
[10] Fix | Delete
_exithandlers = []
[11] Fix | Delete
def _run_exitfuncs():
[12] Fix | Delete
"""run any registered exit functions
[13] Fix | Delete
[14] Fix | Delete
_exithandlers is traversed in reverse order so functions are executed
[15] Fix | Delete
last in, first out.
[16] Fix | Delete
"""
[17] Fix | Delete
[18] Fix | Delete
exc_info = None
[19] Fix | Delete
while _exithandlers:
[20] Fix | Delete
func, targs, kargs = _exithandlers.pop()
[21] Fix | Delete
try:
[22] Fix | Delete
func(*targs, **kargs)
[23] Fix | Delete
except SystemExit:
[24] Fix | Delete
exc_info = sys.exc_info()
[25] Fix | Delete
except:
[26] Fix | Delete
import traceback
[27] Fix | Delete
print >> sys.stderr, "Error in atexit._run_exitfuncs:"
[28] Fix | Delete
traceback.print_exc()
[29] Fix | Delete
exc_info = sys.exc_info()
[30] Fix | Delete
[31] Fix | Delete
if exc_info is not None:
[32] Fix | Delete
raise exc_info[0], exc_info[1], exc_info[2]
[33] Fix | Delete
[34] Fix | Delete
[35] Fix | Delete
def register(func, *targs, **kargs):
[36] Fix | Delete
"""register a function to be executed upon normal program termination
[37] Fix | Delete
[38] Fix | Delete
func - function to be called at exit
[39] Fix | Delete
targs - optional arguments to pass to func
[40] Fix | Delete
kargs - optional keyword arguments to pass to func
[41] Fix | Delete
[42] Fix | Delete
func is returned to facilitate usage as a decorator.
[43] Fix | Delete
"""
[44] Fix | Delete
_exithandlers.append((func, targs, kargs))
[45] Fix | Delete
return func
[46] Fix | Delete
[47] Fix | Delete
if hasattr(sys, "exitfunc"):
[48] Fix | Delete
# Assume it's another registered exit function - append it to our list
[49] Fix | Delete
register(sys.exitfunc)
[50] Fix | Delete
sys.exitfunc = _run_exitfuncs
[51] Fix | Delete
[52] Fix | Delete
if __name__ == "__main__":
[53] Fix | Delete
def x1():
[54] Fix | Delete
print "running x1"
[55] Fix | Delete
def x2(n):
[56] Fix | Delete
print "running x2(%r)" % (n,)
[57] Fix | Delete
def x3(n, kwd=None):
[58] Fix | Delete
print "running x3(%r, kwd=%r)" % (n, kwd)
[59] Fix | Delete
[60] Fix | Delete
register(x1)
[61] Fix | Delete
register(x2, 12)
[62] Fix | Delete
register(x3, 5, "bar")
[63] Fix | Delete
register(x3, "no kwd args")
[64] Fix | Delete
[65] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function