11import linecache
22
3+
34class BPythonLinecache (dict ):
45 """Replaces the cache dict in the standard-library linecache module,
56 to also remember (in an unerasable way) bpython console input."""
@@ -29,7 +30,7 @@ def remember_bpython_input(self, source):
2930 a fake filename to use to retrieve it later."""
3031 filename = '<bpython-input-%s>' % len (self .bpython_history )
3132 self .bpython_history .append ((len (source ), None ,
32- source .splitlines (True ), filename ))
33+ source .splitlines (True ), filename ))
3334 return filename
3435
3536 def __getitem__ (self , key ):
@@ -50,6 +51,7 @@ def __delitem__(self, key):
5051 if not self .is_bpython_filename (key ):
5152 return super (BPythonLinecache , self ).__delitem__ (key )
5253
54+
5355def _bpython_clear_linecache ():
5456 try :
5557 bpython_history = linecache .cache .bpython_history
@@ -58,11 +60,13 @@ def _bpython_clear_linecache():
5860 linecache .cache = BPythonLinecache ()
5961 linecache .cache .bpython_history = bpython_history
6062
63+
6164# Monkey-patch the linecache module so that we're able
6265# to hold our command history there and have it persist
6366linecache .cache = BPythonLinecache (linecache .cache )
6467linecache .clearcache = _bpython_clear_linecache
6568
69+
6670def filename_for_console_input (code_string ):
6771 """Remembers a string of source code, and returns
6872 a fake filename to use to retrieve it later."""
0 commit comments