Skip to content

Commit

Permalink
Use newer uncompyle6 api
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Mar 13, 2018
1 parent f155e66 commit f87e599
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
13 changes: 5 additions & 8 deletions trepan/lib/deparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@
from StringIO import StringIO
from hashlib import sha1
from uncompyle6.semantics.linemap import deparse_code_with_map
from xdis.magics import sysinfo2float
from xdis import IS_PYPY
import pyficache
# FIXME remap filename to a short name.

def deparse_and_cache(co, errmsg_fn):
# co = proc_obj.curframe.f_code
# co = proc_obj.curframe.f_code
out = StringIO()
try:
float_version = sysinfo2float()
deparsed = deparse_code_with_map(co, out)
except:
errmsg_fn(str(sys.exc_info()[0]))
errmsg_fn("error in deparsing code")
errmsg_fn(str(sys.exc_info()))
errmsg_fn("error in deparsing code: %s" % co.co_filename)
return None, None

text = out.getvalue()
deparsed = deparse_code_with_map(float_version, co, is_pypy=IS_PYPY)
linemap = [(line_no, deparsed.source_linemap[line_no])
for line_no in
sorted(deparsed.source_linemap.keys())]
Expand Down Expand Up @@ -54,5 +51,5 @@ def errmsg(msg_str):

curframe = inspect.currentframe()
# line_no = curframe.f_lineno
mapped_name, name_for_code = deparse_and_cache(curframe.f_code, errmsg)
mapped_name, name_for_code = deparse_and_cache(curframe.f_code, errmsg)
print(pyficache.getline(mapped_name, 7))
6 changes: 3 additions & 3 deletions trepan/processor/command/deparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os, sys
from getopt import getopt, GetoptError
from uncompyle6.semantics.fragments import (
deparse_code, deparse_code_around_offset)
code_deparse, deparse_code_around_offset)
from uncompyle6.semantics.fragments import deparsed_find
from trepan.lib.deparse import deparse_and_cache
from pyficache import highlight_string, getlines
Expand Down Expand Up @@ -126,7 +126,7 @@ def run(self, args):
self.print_text(''.join(getlines(temp_filename)))
return
elif show_offsets:
deparsed = deparse_code(float_version, co, is_pypy=IS_PYPY)
deparsed = code_deparse(co)
self.section("Offsets known:")
m = self.columnize_commands(list(sorted(deparsed.offsets.keys(),
key=lambda x: str(x[0]))))
Expand All @@ -143,7 +143,7 @@ def run(self, args):
if last_i == -1: last_i = 0

try:
deparsed = deparse_code(float_version, co, is_pypy=IS_PYPY)
deparsed = code_deparse(co)
nodeInfo = deparsed_find((name, last_i), deparsed, co)
if not nodeInfo:
self.errmsg("Can't find exact offset %d; giving inexact results" % last_i)
Expand Down
2 changes: 0 additions & 2 deletions trepan/processor/command/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
# Our local modules
from trepan.processor.command import base_cmd as Mbase_cmd
from trepan.processor.cmdlist import parse_list_cmd
from trepan.processor import cmdproc as Mcmdproc
from trepan.lib.deparse import deparse_and_cache
from pyficache import pyc2py # , unmap_file_line


class ListCommand(Mbase_cmd.DebuggerCommand):
Expand Down

0 comments on commit f87e599

Please sign in to comment.