[PATCH 3 of 3 STABLE] py3: fix handling of ctrl keys in crecord (issue6213)

Denis Laxalde denis at laxalde.org
Wed Nov 6 11:23:29 EST 2019


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1573055674 -3600
#      Wed Nov 06 16:54:34 2019 +0100
# Branch stable
# Node ID f4415c4f24f879845f5dc631d592440e88d2afee
# Parent  5802765e3828e3b3f1396b92ed7ef18a1eca6456
py3: fix handling of ctrl keys in crecord (issue6213)

The "keypressed" value in handlekeypressed() is a key name obtained by
curses's getkey(); this can be a multibyte string for special keys
like CTRL keys. Calling curses.unctrl() with such a value fails on
Python 3 with a TypeError as described in issue6213. (On Python 2, this
does not crash, but I'm not sure the result is correct, though it does
no matter here.)

So instead of calling unctrl(), we compare "keypressed" with the
expected "^L" obtained by curses.ascii.ctrl("L").

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -59,6 +59,7 @@ patchhelptext = _(
 
 try:
     import curses
+    import curses.ascii
 
     curses.error
 except ImportError:
@@ -1938,7 +1939,7 @@ are you sure you want to review/edit and
             self.helpwindow()
             self.stdscr.clear()
             self.stdscr.refresh()
-        elif curses.unctrl(keypressed) in ["^L"]:
+        elif keypressed in [curses.ascii.ctrl("L")]:
             # scroll the current line to the top of the screen, and redraw
             # everything
             self.scrolllines(self.selecteditemstartline)


More information about the Mercurial-devel mailing list