Skip to content

Commit f9b8f87

Browse files
committed
Merge branch 'master' of github.com:rocky/python3-trepan
2 parents efc37e6 + 9a32f4f commit f9b8f87

13 files changed

Lines changed: 118 additions & 207 deletions

File tree

__pkginfo__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"Programming Language :: Python :: 3.6 ",
5555
"Programming Language :: Python :: 3.7 ",
5656
"Programming Language :: Python :: 3.8 ",
57+
"Programming Language :: Python :: 3.9 ",
5758
]
5859

5960
# The rest in alphabetic order
@@ -76,6 +77,7 @@
7677
"pygments %s" % pygments_version,
7778
"spark_parser >= 1.8.9, <1.9.0",
7879
"tracer >= 0.3.2",
80+
"term-background >= 1.0.1",
7981
"uncompyle6 >= 3.7.4",
8082
]
8183
license = "GPL3"

test/unit/test-lib-eval.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
'Unit test for trepan.lib.eval'
2+
"Unit test for trepan.lib.eval"
33
import unittest
44

55
from trepan.lib import eval as Meval
@@ -8,18 +8,23 @@
88
class TestExtractExpression(unittest.TestCase):
99
def test_extract_expression(self):
1010
for fragment, expect in (
11-
('if condition(x):', 'condition(x)'),
12-
('elif is_magic(name):', 'is_magic(name)'),
13-
('while expression:', 'expression'),
14-
('for i in range(3):', 'range(3)'),
15-
('abc = 123', '123'),
16-
('assert True', 'True'),
17-
('return return_value', 'return_value'),
18-
('nothing_to_be.done', 'nothing_to_be.done'), ):
19-
self.assertEqual(expect , Meval.extract_expression(fragment))
11+
("if condition(x):", "condition(x)"),
12+
("elif is_magic(name):", "is_magic(name)"),
13+
("while expression:", "expression"),
14+
("for i in range(3):", "range(3)"),
15+
("and x > 3", "x > 3"),
16+
("or y < 3", "y < 3"),
17+
("abc = 123", "123"),
18+
("assert True", "True"),
19+
("return return_value", "return_value"),
20+
("nothing_to_be.done", "nothing_to_be.done"),
21+
):
22+
self.assertEqual(expect, Meval.extract_expression(fragment))
2023
pass
2124
pass
25+
2226
pass
2327

24-
if __name__ == '__main__':
28+
29+
if __name__ == "__main__":
2530
unittest.main()

trepan/inout/output.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def __init__(self, out=None, opts=None):
3030
self.flush_after_write = False
3131
self.output = out or sys.stdout
3232
self.open(self.output, opts)
33+
if hasattr(self.output, "isatty"):
34+
self.isatty = self.output.isatty
3335
return
3436

3537
def flush(self):

trepan/interfaces/user.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Copyright (C) 2009-2010, 2013-2015,
3-
# 2017-2018 Rocky Bernstein <rocky@gnu.org>
3+
# 2017-2018, 2020 Rocky Bernstein <rocky@gnu.org>
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -89,7 +89,7 @@ def close(self):
8989
return
9090

9191
def confirm(self, prompt, default):
92-
""" Called when a dangerous action is about to be done, to make
92+
"""Called when a dangerous action is about to be done, to make
9393
sure it's okay. Expect a yes/no answer to `prompt' which is printed,
9494
suffixed with a question mark and the default value. The user
9595
response converted to a boolean is returned."""
@@ -114,9 +114,20 @@ def confirm(self, prompt, default):
114114
pass
115115
return default
116116

117-
def errmsg(self, msg, prefix="** "):
118-
"""Common routine for reporting debugger error messages.
117+
def msg(self, msg):
118+
"""used to write to a debugger that is connected to this
119+
server; `str' written will have a newline added to it
119120
"""
121+
super().msg(msg)
122+
# from pydoc import ttypager
123+
# if hasattr(self.output, "isatty"):
124+
# ttypager(msg)
125+
# super().msg("")
126+
# else:
127+
# super().msg(msg)
128+
129+
def errmsg(self, msg, prefix="** "):
130+
"""Common routine for reporting debugger error messages."""
120131
return self.msg("%s%s" % (prefix, msg))
121132

122133
def finalize(self, last_wishes=None):

trepan/lib/core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import os.path as osp
2828

2929
# External packages
30+
import pyficache
3031
import tracer
3132

3233
# Our local modules
@@ -174,6 +175,8 @@ def canonic(self, filename):
174175
pass
175176
canonic = osp.realpath(osp.normcase(canonic))
176177
self.filename_cache[filename] = canonic
178+
canonic = pyficache.unmap_file(canonic)
179+
177180
return canonic
178181

179182
def canonic_filename(self, frame):

trepan/lib/default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import os, tracer
2020
from columnize import computed_displaywidth
2121

22-
from trepan.lib.term_background import is_dark_background
22+
from term_background import is_dark_background
2323

2424
width = computed_displaywidth()
2525

trepan/lib/eval.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,56 @@
1313
#
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
'''Things related to eval/exec'''
16+
"""Things related to eval/exec"""
1717

1818
# extract the "expression" part of a line of source code.
1919
#
2020
import re
2121

2222

2323
def extract_expression(text):
24-
if re.search('^\s*(?:if|elif)\s+', text):
25-
text = re.sub('^\s*(?:if|elif)\s+', '', text)
26-
text = re.sub(':(?:\s+.*$|$)', '', text)
27-
elif re.search('^\s*assert\s+.*', text):
24+
if re.search("^\s*(?:if|elif)\s+", text):
25+
text = re.sub("^\s*(?:if|elif)\s+", "", text)
26+
text = re.sub(":(?:\s+.*$|$)", "", text)
27+
elif re.search("^\s*assert\s+.*", text):
2828
# EXPR in : assert EXPRESSION:
29-
text = re.sub('^\s*assert\s+', '', text)
30-
elif re.search('^\s*(?:while)\s+', text):
31-
text = re.sub('^\s*(?:while)\s+', '', text)
32-
text = re.sub(':(?:\s+.*$|$)', '', text)
33-
elif re.search('^\s*return\s+', text):
29+
text = re.sub("^\s*assert\s+", "", text)
30+
elif re.search("^\s*(?:while)\s+", text):
31+
text = re.sub("^\s*(?:while)\s+", "", text)
32+
text = re.sub(":(?:\s+.*$|$)", "", text)
33+
elif re.search("^\s*return\s+", text):
3434
# EXPRESION in: return EXPRESSION
35-
text = re.sub('^\s*return\s+', '', text)
36-
elif re.search('^\s*for\s+.+\s+in\s+.*:', text):
35+
text = re.sub("^\s*return\s+", "", text)
36+
elif re.search("^\s*for\s+.+\s+in\s+.*:", text):
3737
# EXPRESION in: for VAR in EXPRESSION:
38-
text = re.sub('^\s*for\s+.+\s+in\s+', '', text)
39-
text = re.sub(':.*$', '', text)
40-
elif re.search('\s*[A-Za-z_][A-Za-z0-9_\[\]]*\s*=[^=>]', text):
38+
text = re.sub("^\s*for\s+.+\s+in\s+", "", text)
39+
text = re.sub(":.*$", "", text)
40+
elif re.search("^\s*and\s+.*", text):
41+
# EXPRESION in: and EXPRESSION
42+
text = re.sub("^\s*and\s+", "", text)
43+
elif re.search("^\s*or\s+.*", text):
44+
# EXPRESION in: and EXPRESSION
45+
text = re.sub("^\s*or\s+", "", text)
46+
elif re.search("\s*[A-Za-z_][A-Za-z0-9_\[\]]*\s*=[^=>]", text):
4147
# RHS of an assignment statement.
42-
text = re.sub('^\s*[A-Za-z_][A-Za-z0-9_\[\]]*\s*=\s*', '', text)
48+
text = re.sub("^\s*[A-Za-z_][A-Za-z0-9_\[\]]*\s*=\s*", "", text)
4349
pass
4450
return text
4551

4652

4753
# Demo it
48-
if __name__=='__main__':
54+
if __name__ == "__main__":
4955
for stmt in (
50-
'if condition(x):',
51-
'elif _is_magic(name):',
52-
'while expression:',
53-
'for i in range(3):',
54-
'abc = 123',
55-
'return return_value',
56-
'nothing_to_be.done'):
56+
"if condition(x):",
57+
"elif _is_magic(name):",
58+
"while expression:",
59+
"for i in range(3):",
60+
"and x > 3",
61+
"or y < 3",
62+
"abc = 123",
63+
"return return_value",
64+
"nothing_to_be.done",
65+
):
5766
print(extract_expression(stmt))
5867
pass
5968
pass

trepan/lib/stack.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,12 @@ def check_path_with_frame(frame, path):
229229
if bc_size and bc_size != my_size:
230230
return False, "bytecode and local files mismatch"
231231
if fs_size and fs_size != my_size:
232-
return False, (
233-
"frame file size, %d bytes, and local file size, %d bytes, on file %s mismatch"
234-
% (fs_size, my_size, path)
232+
return (
233+
False,
234+
(
235+
"frame file size, %d bytes, and local file size, %d bytes, on file %s mismatch"
236+
% (fs_size, my_size, path)
237+
),
235238
)
236239
return True, None
237240

trepan/lib/term_background.py

Lines changed: 0 additions & 134 deletions
This file was deleted.

trepan/processor/cmdproc.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ def print_location(proc_obj):
229229
remapped_file = None
230230
pass
231231
pass
232+
elif pyficache.main.remap_re_hash:
233+
remapped_file = pyficache.remap_file_pat(filename, pyficache.main.remap_re_hash)
232234
elif m and m.group(1) in sys.modules:
233235
remapped_file = m.group(1)
234236
pyficache.remap_file(filename, remapped_file)
@@ -390,6 +392,7 @@ def __init__(self, core_obj, opts=None):
390392

391393
self.preloop_hooks = []
392394
self.postcmd_hooks = []
395+
self.remap_file_re = None
393396

394397
self._populate_cmd_lists()
395398

@@ -443,6 +446,13 @@ def add_preloop_hook(self, hook, position=-1, nodups=True):
443446
self.preloop_hooks.insert(position, hook)
444447
return True
445448

449+
def add_remap_pat(self, pat, replace, clear_remap=True):
450+
self.remap_re_hash[re.compile(pat)] = (pat, replace)
451+
pyficache.main.add_remap_pat(pat, replace, clear_remap)
452+
if clear_remap:
453+
self.file2file_remap = {}
454+
pyficache.file2file_remap = {}
455+
446456
# To be overridden in derived debuggers
447457
def defaultFile(self):
448458
"""Produce a reasonable default."""

0 commit comments

Comments
 (0)