]> granicus.if.org Git - python/commitdiff
Issue #16182: Merge readline locale fix from 3.5
authorMartin Panter <vadmium+py@gmail.com>
Tue, 14 Jun 2016 02:47:56 +0000 (02:47 +0000)
committerMartin Panter <vadmium+py@gmail.com>
Tue, 14 Jun 2016 02:47:56 +0000 (02:47 +0000)
1  2 
Lib/test/test_readline.py
Misc/NEWS
Modules/readline.c

index c1864efaab1dace2b7d48f018d788cc03f7e5449,34a55b25ee22c31a0a003cba4c7213eb61601259..20b2b67069077db2827a344fdb65b96839ed3d77
@@@ -101,21 -116,69 +116,84 @@@ class TestReadline(unittest.TestCase)
                                                TERM='xterm-256color')
          self.assertEqual(stdout, b'')
  
 +    auto_history_script = """\
 +import readline
 +readline.set_auto_history({})
 +input()
 +print("History length:", readline.get_current_history_length())
 +"""
 +
 +    def test_auto_history_enabled(self):
 +        output = run_pty(self.auto_history_script.format(True))
 +        self.assertIn(b"History length: 1\r\n", output)
 +
 +    def test_auto_history_disabled(self):
 +        output = run_pty(self.auto_history_script.format(False))
 +        self.assertIn(b"History length: 0\r\n", output)
 +
+     def test_nonascii(self):
+         try:
+             readline.add_history("\xEB\xEF")
+         except UnicodeEncodeError as err:
+             self.skipTest("Locale cannot encode test data: " + format(err))
+         script = r"""import readline
+ if readline.__doc__ and "libedit" in readline.__doc__:
+     readline.parse_and_bind(r'bind ^B ed-prev-char')
+     readline.parse_and_bind(r'bind "\t" rl_complete')
+     readline.parse_and_bind('bind -s ^A "|t\xEB[after]"')
+ else:
+     readline.parse_and_bind(r'Control-b: backward-char')
+     readline.parse_and_bind(r'"\t": complete')
+     readline.parse_and_bind(r'set disable-completion off')
+     readline.parse_and_bind(r'set show-all-if-ambiguous off')
+     readline.parse_and_bind(r'set show-all-if-unmodified off')
+     readline.parse_and_bind('Control-a: "|t\xEB[after]"')
+ def pre_input_hook():
+     readline.insert_text("[\xEFnserted]")
+     readline.redisplay()
+ readline.set_pre_input_hook(pre_input_hook)
+ def completer(text, state):
+     if text == "t\xEB":
+         if state == 0:
+             print("text", ascii(text))
+             print("line", ascii(readline.get_line_buffer()))
+             print("indexes", readline.get_begidx(), readline.get_endidx())
+             return "t\xEBnt"
+         if state == 1:
+             return "t\xEBxt"
+     if text == "t\xEBx" and state == 0:
+         return "t\xEBxt"
+     return None
+ readline.set_completer(completer)
+ def display(substitution, matches, longest_match_length):
+     print("substitution", ascii(substitution))
+     print("matches", ascii(matches))
+ readline.set_completion_display_matches_hook(display)
+ print("result", ascii(input()))
+ print("history", ascii(readline.get_history_item(1)))
+ """
+         input = b"\x01"  # Ctrl-A, expands to "|t\xEB[after]"
+         input += b"\x02" * len("[after]")  # Move cursor back
+         input += b"\t\t"  # Display possible completions
+         input += b"x\t"  # Complete "t\xEBx" -> "t\xEBxt"
+         input += b"\r"
+         output = run_pty(script, input)
+         self.assertIn(b"text 't\\xeb'\r\n", output)
+         self.assertIn(b"line '[\\xefnserted]|t\\xeb[after]'\r\n", output)
+         self.assertIn(b"indexes 11 13\r\n", output)
+         self.assertIn(b"substitution 't\\xeb'\r\n", output)
+         self.assertIn(b"matches ['t\\xebnt', 't\\xebxt']\r\n", output)
+         expected = br"'[\xefnserted]|t\xebxt[after]'"
+         self.assertIn(b"result " + expected + b"\r\n", output)
+         self.assertIn(b"history " + expected + b"\r\n", output)
  
  def run_pty(script, input=b"dummy input\r"):
      pty = import_module('pty')
diff --cc Misc/NEWS
index 69667a2c734ab7d1f46f269419c47a9c4b5574c9,3398a860d8b2a6e3665e2b3db374ac1921af7836..c59b3adf01b7a030a2f64e4d53ec25baa8a55e1b
+++ b/Misc/NEWS
@@@ -2,21 -2,38 +2,28 @@@
  Python News
  +++++++++++
  
 -What's New in Python 3.5.3 release candidate 1?
 -===============================================
 -
 -Release date: TBA
 +What's New in Python 3.6.0 alpha 3
 +==================================
  
 -Core and Builtins
 ------------------
 +*Release date: XXXX-XX-XX*
  
 --------
+ Library
+++++++++
+ - Issue #16182: Fix various functions in the "readline" module to use the
+   locale encoding, and fix get_begidx() and get_endidx() to return code point
+   indexes.
 +IDLE
 +++++
  
 -What's New in Python 3.5.2 final?
 -=================================
 -
 -Release date: 2016-06-26
 -
 -Core and Builtins
 ------------------
 -
 -Library
 --------
 +- Issue #27310: Fix IDLE.app failure to launch on OS X due to vestigial import.
  
  
 -What's New in Python 3.5.2 release candidate 1?
 -===============================================
 +What's New in Python 3.6.0 alpha 2
 +==================================
  
 -Release date: 2016-06-12
 +*Release date: XXXX-XX-XX*
  
  Core and Builtins
  -----------------
index 47f1b13c9e8e3a35bd92d26f0344a9edb2feab4a,91f7cca73e3d556cb1901732b24e651b4661bd6c..f8876e0560e293b21bd1594b5a970926529da94d
@@@ -808,9 -821,8 +837,9 @@@ static struct PyMethodDef readline_meth
      {"get_endidx", get_endidx, METH_NOARGS, doc_get_endidx},
  
      {"set_completer_delims", set_completer_delims,
-      METH_VARARGS, doc_set_completer_delims},
+      METH_O, doc_set_completer_delims},
 +    {"set_auto_history", py_set_auto_history, METH_VARARGS, doc_set_auto_history},
-     {"add_history", py_add_history, METH_VARARGS, doc_add_history},
+     {"add_history", py_add_history, METH_O, doc_add_history},
      {"remove_history_item", py_remove_history, METH_VARARGS, doc_remove_history},
      {"replace_history_item", py_replace_history, METH_VARARGS, doc_replace_history},
      {"get_completer_delims", get_completer_delims,