示例#1
0
def test_simple_code_to_bytecode_repr_unicode():
    def method4():
        return 'áéíóú'

    new_repr = code_to_bytecode_representation(method4.__code__,
                                               use_func_first_line=True)
    assert repr('áéíóú') in new_repr
示例#2
0
def test_simple_code_to_bytecode_repr_attr():
    def method4():
        call(a.b.c)

    new_repr = code_to_bytecode_representation(method4.__code__,
                                               use_func_first_line=True)
    assert 'call(a.b.c)' in new_repr
示例#3
0
def test_build_tuple():
    def method4():
        return call(1, (call2(), 2))

    new_repr = code_to_bytecode_representation(method4.__code__,
                                               use_func_first_line=True)
    assert 'return call(1, (call2(), 2))' in new_repr
示例#4
0
def test_simple_code_to_bytecode_repr_return_tuple_with_call():
    def method4():
        return (1, 2, 3, a())

    new_repr = code_to_bytecode_representation(method4.__code__,
                                               use_func_first_line=True)
    assert 'return (1, 2, 3, a())' in new_repr
示例#5
0
def test_simple_code_to_bytecode_cls_method():
    def method4():
        class B:
            def method(self):
                self.a.b.c

    new_repr = code_to_bytecode_representation(method4.__code__,
                                               use_func_first_line=True)
    assert 'self.a.b.c' in new_repr
示例#6
0
def test_simple_code_to_bytecode_repr_assign():
    def method4():
        a = call()
        return call()

    new_repr = code_to_bytecode_representation(method4.__code__,
                                               use_func_first_line=True)
    assert 'a = call()' in new_repr
    assert 'return call()' in new_repr
示例#7
0
def test_simple_code_to_bytecode_repr():

    def method4():
        return (1,
                2,
                3,
                call('tnh %s' % 1))

    assert code_to_bytecode_representation(method4.__code__, use_func_first_line=True).count('\n') == 4
示例#8
0
def test_simple_code_to_bytecode_repr_simple_method_calls():
    def method4():
        call()
        a = 10
        call(1, 2, 3, a, b, "x")

    new_repr = code_to_bytecode_representation(method4.__code__,
                                               use_func_first_line=True)
    assert 'call()' in new_repr
    assert 'call(1, 2, 3, a, b, \'x\')' in new_repr
示例#9
0
def test_simple_code_to_bytecode_repr2():
    def method():
        print(10)

        def method4(a, b):
            return (1, 2, 3, call('somestr %s' % 1))

        print(20)

    s = code_to_bytecode_representation(method.__code__,
                                        use_func_first_line=True)
    assert s.count('\n') == 9, 'Expected 9 lines. Found: %s in:>>\n%s\n<<' % (
        s.count('\n'), s)
    assert 'somestr' in s  # i.e.: the contents of the inner code have been added too
示例#10
0
def test_simple_code_to_bytecode_repr_many():
    def method4():
        a = call()
        if a == 20:
            [x for x in call()]

        def method2():
            for x in y:
                yield x
            raise AssertionError

        return (1, 2, 3, call('tnh 1' % 1))

    new_repr = code_to_bytecode_representation(method4.__code__,
                                               use_func_first_line=True)
示例#11
0
    def get_decompiled_source_from_frame_id(self, py_db, frame_id):
        '''
        :param py_db:
        :param frame_id:
        :throws Exception:
            If unable to get the frame in the currently paused frames or if some error happened
            when decompiling.
        '''
        variable = py_db.suspended_frames_manager.get_variable(int(frame_id))
        frame = variable.value

        # Check if it's in the linecache first.
        lines = (linecache.getline(frame.f_code.co_filename, i) for i in itertools.count(1))
        lines = itertools.takewhile(bool, lines)  # empty lines are '\n', EOF is ''

        source = ''.join(lines)
        if not source:
            source = code_to_bytecode_representation(frame.f_code)

        return source