def _enhook(klass, name):
    "(private) causes a certain method name to be hooked on a class"
    if hasattr(klass, ORIG(klass, name)):
        return

    def newfunc(*args, **kw):
        for preMethod in getattr(klass, PRE(klass, name)):
            preMethod(*args, **kw)
        try:
            return getattr(klass, ORIG(klass, name))(*args, **kw)
        finally:
            for postMethod in getattr(klass, POST(klass, name)):
                postMethod(*args, **kw)
    try:
        newfunc.func_name = name
    except __HOLE__:
        # Older python's don't let you do this
        pass

    oldfunc = getattr(klass, name).im_func
    setattr(klass, ORIG(klass, name), oldfunc)
    setattr(klass, PRE(klass, name), [])
    setattr(klass, POST(klass, name), [])
    setattr(klass, name, newfunc)
dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/python/hook.py/_enhook