예제 #1
0
 def test_find_ids_range(self):
     def f():
         a = 0 # ID: myline
         return a
     #
     start_lineno = f.func_code.co_firstlineno
     code = disassembler.dis(f)
     ids = find_ids_range(code)
     assert len(ids) == 1
     myline_range = ids['myline']
     assert list(myline_range) == range(start_lineno+1, start_lineno+2)
예제 #2
0
 def test_find_ids_range(self):
     def f():
         a = 0 # ID: myline
         return a
     #
     start_lineno = f.func_code.co_firstlineno
     code = disassembler.dis(f)
     ids = find_ids_range(code)
     assert len(ids) == 1
     myline_range = ids['myline']
     assert list(myline_range) == range(start_lineno+1, start_lineno+2)
예제 #3
0
 def test_find_ids(self):
     def f():
         i = 0
         x = 0
         z = x + 3 # ID: myline
         return z
     #
     code = disassembler.dis(f)
     ids = find_ids(code)
     assert len(ids) == 1
     myline = ids['myline']
     opcodes_names = [opcode.__class__.__name__ for opcode in myline]
     assert opcodes_names == ['LOAD_FAST', 'LOAD_CONST', 'BINARY_ADD', 'STORE_FAST']
예제 #4
0
 def test_find_ids(self):
     def f():
         i = 0
         x = 0
         z = x + 3 # ID: myline
         return z
     #
     code = disassembler.dis(f)
     ids = find_ids(code)
     assert len(ids) == 1
     myline = ids['myline']
     opcodes_names = [opcode.__class__.__name__ for opcode in myline]
     assert opcodes_names == ['LOAD_FAST', 'LOAD_CONST', 'BINARY_ADD', 'STORE_FAST']
예제 #5
0
파일: storage.py 프로젝트: Debug-Orz/Sypy
 def disassemble_code(self, fname, startlineno, name):
     try:
         if py.path.local(fname).check(file=False):
             return None # cannot find source file
     except py.error.EACCES:
         return None # cannot open the file
     key = (fname, startlineno, name)
     try:
         return self.disassembled_codes[key]
     except KeyError:
         codeobjs = self.load_code(fname)
         if (startlineno, name) not in codeobjs:
             # cannot find the code obj at this line: this can happen for
             # various reasons, e.g. because the .py files changed since
             # the log was produced, or because the co_firstlineno
             # attribute of the code object is wrong (e.g., code objects
             # produced by gateway.applevel(), such as the ones found in
             # nanos.py)
             return None
         code = codeobjs[(startlineno, name)]
         res = dis(code)
         self.disassembled_codes[key] = res
         return res
예제 #6
0
 def disassemble_code(self, fname, startlineno, name):
     try:
         if py.path.local(fname).check(file=False):
             return None  # cannot find source file
     except py.error.EACCES:
         return None  # cannot open the file
     key = (fname, startlineno, name)
     try:
         return self.disassembled_codes[key]
     except KeyError:
         codeobjs = self.load_code(fname)
         if (startlineno, name) not in codeobjs:
             # cannot find the code obj at this line: this can happen for
             # various reasons, e.g. because the .py files changed since
             # the log was produced, or because the co_firstlineno
             # attribute of the code object is wrong (e.g., code objects
             # produced by gateway.applevel(), such as the ones found in
             # nanos.py)
             return None
         code = codeobjs[(startlineno, name)]
         res = dis(code)
         self.disassembled_codes[key] = res
         return res