python奇技淫巧

阅读更多

http://wiki.python.org/moin/ByteplayDoc
-----------------------

wget http://byteplay.googlecode.com/svn/trunk/byteplay.py
-----------------------

from types import FunctionType
from byteplay import Code, opmap


def _transmute(opcode, arg):
    if ((opcode == opmap['LOAD_GLOBAL']) and
        (arg == 'request')):
        return opmap['LOAD_FAST'], arg
    return opcode, arg


def requestless(function):
    code = Code.from_code(function.func_code)
    code.args = tuple(['request'] + list(code.args))
    code.code = [_transmute(op, arg) for op, arg in code.code]
    function.func_code = code.to_code()
    return function


@requestless
def test():
    print request


test(123)

你可能感兴趣的:(Python,SVN)