1
1
import linecache
2
2
3
+
3
4
class BPythonLinecache (dict ):
4
5
"""Replaces the cache dict in the standard-library linecache module,
5
6
to also remember (in an unerasable way) bpython console input."""
@@ -29,7 +30,7 @@ def remember_bpython_input(self, source):
29
30
a fake filename to use to retrieve it later."""
30
31
filename = '<bpython-input-%s>' % len (self .bpython_history )
31
32
self .bpython_history .append ((len (source ), None ,
32
- source .splitlines (True ), filename ))
33
+ source .splitlines (True ), filename ))
33
34
return filename
34
35
35
36
def __getitem__ (self , key ):
@@ -50,6 +51,7 @@ def __delitem__(self, key):
50
51
if not self .is_bpython_filename (key ):
51
52
return super (BPythonLinecache , self ).__delitem__ (key )
52
53
54
+
53
55
def _bpython_clear_linecache ():
54
56
try :
55
57
bpython_history = linecache .cache .bpython_history
@@ -58,11 +60,13 @@ def _bpython_clear_linecache():
58
60
linecache .cache = BPythonLinecache ()
59
61
linecache .cache .bpython_history = bpython_history
60
62
63
+
61
64
# Monkey-patch the linecache module so that we're able
62
65
# to hold our command history there and have it persist
63
66
linecache .cache = BPythonLinecache (linecache .cache )
64
67
linecache .clearcache = _bpython_clear_linecache
65
68
69
+
66
70
def filename_for_console_input (code_string ):
67
71
"""Remembers a string of source code, and returns
68
72
a fake filename to use to retrieve it later."""
0 commit comments