Exemple #1
0
 def test_op_at_frame(self):
     frame = inspect.currentframe()
     IS_PYPY = '__pypy__' in sys.builtin_module_names
     if IS_PYPY:
         self.assertEqual('CALL_METHOD', Mcode.op_at_frame(frame))
     else:
         self.assertEqual('CALL_FUNCTION', Mcode.op_at_frame(frame))
     return
Exemple #2
0
    def test_op_at_frame(self):
        frame = inspect.currentframe()
        if IS_PYPY or PYTHON_VERSION_TRIPLE >= (3, 7):
            call_opcode = 'CALL_METHOD'
        else:
            call_opcode = 'CALL_FUNCTION'

        self.assertEqual(call_opcode, Mcode.op_at_frame(frame))
        return
Exemple #3
0
def get_call_function_name(frame):
    """If f_back is looking at a call function, return
    the name for it. Otherwise return None"""
    f_back = frame.f_back
    if not f_back:
        return None
    if "CALL_FUNCTION" != Mbytecode.op_at_frame(f_back):
        return None

    co = f_back.f_code
    code = co.co_code
    # labels     = dis.findlabels(code)
    linestarts = dict(dis.findlinestarts(co))
    offset = f_back.f_lasti
    while offset >= 0:
        if offset in linestarts:
            op = code[offset]
            offset += 1
            arg = code[offset]
            # FIXME: put this code in xdis
            extended_arg = 0
            while True:
                if PYTHON_VERSION_TRIPLE >= (3, 6):
                    if op == opc.EXTENDED_ARG:
                        extended_arg += arg << 8
                        continue
                    arg = code[offset] + extended_arg
                    # FIXME: Python 3.6.0a1 is 2, for 3.6.a3 we have 1
                else:
                    if op == opc.EXTENDED_ARG:
                        extended_arg += arg << 256
                        continue
                    arg = code[offset] + code[offset + 1] * 256 + extended_arg
                break

            if arg < len(co.co_names):
                return co.co_names[arg]
            else:
                return None
        offset -= 1
        pass
    return None
Exemple #4
0
def get_call_function_name(frame):
    """If f_back is looking at a call function, return
    the name for it. Otherwise return None"""
    f_back = frame.f_back
    if not f_back: return None
    if 'CALL_FUNCTION' != Mbytecode.op_at_frame(f_back): return None

    co = f_back.f_code
    code = co.co_code
    # labels     = dis.findlabels(code)
    linestarts = dict(dis.findlinestarts(co))
    inst = f_back.f_lasti
    while inst >= 0:
        # c = code[inst]
        # op = ord(c)
        if inst in linestarts:
            inst += 1
            oparg = ord(code[inst]) + (ord(code[inst + 1]) << 8)
            return co.co_names[oparg]
        inst -= 1
        pass
    return None
def get_call_function_name(frame, color='plain'):
    """If f_back is looking at a call function, return
    the name for it. Otherwise return None"""
    f_back = frame.f_back
    if not f_back: return None
    if 'CALL_FUNCTION' != Mbytecode.op_at_frame(f_back): return None

    co         = f_back.f_code
    code       = co.co_code
    # labels     = dis.findlabels(code)
    linestarts = dict(dis.findlinestarts(co))
    inst       = f_back.f_lasti
    while inst >= 0:
        # c = code[inst]
        # op = ord(c)
        if inst in linestarts:
            inst += 1
            oparg = ord(code[inst]) + (ord(code[inst+1]) << 8)
            return format_token(Mformat.Function, co.co_names[oparg],
                                highlight=color)
        inst -= 1
        pass
    return None
 def test_op_at_frame(self):
     frame = inspect.currentframe()
     self.assertEqual('CALL_FUNCTION', Mcode.op_at_frame(frame))
     return
def is_exec_stmt(frame):
    """Return True if we are looking at an exec statement"""
    return hasattr(frame, 'f_back') and frame.f_back is not None and \
        Mbytecode.op_at_frame(frame.f_back)=='EXEC_STMT'
Exemple #8
0
def is_exec_stmt(frame):
    """Return True if we are looking at an exec statement"""
    return hasattr(frame, 'f_back') and frame.f_back is not None and \
        Mbytecode.op_at_frame(frame.f_back)=='EXEC_STMT'
 def test_op_at_frame(self):
     frame = inspect.currentframe()
     self.assertEqual('CALL_FUNCTION', Mcode.op_at_frame(frame))
     return