From patchwork Wed Dec 16 00:06:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1,of,5,stable] crecord: use try/except for import of curses From: Sean Farley X-Patchwork-Id: 12063 Message-Id: <7ceba88969e51bb82574.1450224372@laptop.office.atlassian.com> To: mercurial-devel@selenic.com Date: Tue, 15 Dec 2015 16:06:12 -0800 # HG changeset patch # User Sean Farley # Date 1450223509 28800 # Tue Dec 15 15:51:49 2015 -0800 # Branch stable # Node ID 7ceba88969e51bb825748f69b45e4677e0a02815 # Parent 59d5f619e69ec43f1957eddd85d4e1deddd64925 crecord: use try/except for import of curses Not only does this improve fragility with 'if os.name == ...' it will help future patches enable the behavior to fallback to use plain record when curses is unavailable (e.g. python compiled without curses support). diff --git a/mercurial/crecord.py b/mercurial/crecord.py --- a/mercurial/crecord.py +++ b/mercurial/crecord.py @@ -28,16 +28,15 @@ from . import ( # This is required for ncurses to display non-ASCII characters in default user # locale encoding correctly. --immerrr locale.setlocale(locale.LC_ALL, '') -# os.name is one of: 'posix', 'nt', 'dos', 'os2', 'mac', or 'ce' -if os.name == 'posix': +try: import curses import fcntl import termios -else: +except ImportError: # I have no idea if wcurses works with crecord... try: import wcurses as curses except ImportError: # wcurses is not shipped on Windows by default