[Jython-checkins] jython: Fix readline.read_history_file, write_history_file functions

jim.baker jython-checkins at python.org
Sat Feb 7 04:21:20 CET 2015


https://hg.python.org/jython/rev/65f96010b35c
changeset:   7576:65f96010b35c
user:        Jim Baker <jim.baker at rackspace.com>
date:        Fri Feb 06 20:21:15 2015 -0700
summary:
  Fix readline.read_history_file, write_history_file functions

These functions had not been updated with the upgrade to JLine2.
Fixes http://bugs.jython.org/issue2266

files:
  Lib/readline.py |  26 ++------------------------
  1 files changed, 2 insertions(+), 24 deletions(-)


diff --git a/Lib/readline.py b/Lib/readline.py
--- a/Lib/readline.py
+++ b/Lib/readline.py
@@ -39,22 +39,6 @@
     """Security manager prevents access to private field"""
 
 
-def _setup_history():
-    # This is obviously not desirable, but avoids O(n) workarounds to
-    # modify the history (ipython uses the function
-    # remove_history_item to mutate the history relatively frequently)
-    global _history_list
-
-    history = _reader.history
-    try:
-        history_list_field = history.class.getDeclaredField("history")
-        history_list_field.setAccessible(True)
-        _history_list = history_list_field.get(history)
-    except:
-        pass
-
-_setup_history()
-
 def parse_and_bind(string):
     pass
 
@@ -68,21 +52,15 @@
     warn("read_init_file: %s" % (filename,), NotImplementedWarning, "module", 2)
 
 def read_history_file(filename="~/.history"):
-    print "Reading history:", filename
     expanded = os.path.expanduser(filename)
-    new_history = _reader.getHistory().getClass()()
-    # new_history.clear()
     with open(expanded) as f:
-        for line in f:
-            new_history.addToHistory(line.rstrip())
-    _reader.history = new_history
-    _setup_history()
+        _reader.history.load(f)
 
 def write_history_file(filename="~/.history"):
     expanded = os.path.expanduser(filename)
     with open(expanded, 'w') as f:
         for line in _reader.history.entries():
-            f.write(line)
+            f.write(line.value().encode("utf-8"))
             f.write("\n")
 
 def clear_history():

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list