From fcb82c635ed472a0df480142c0446ee4057d31ae Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 24 Sep 2009 22:47:09 +0000 Subject: Show an appropriate error message in _create_pty_or_pipe() if openpty() fails inside _test_pty_eof(). svn path=/main/trunk/; revision=14417 --- pym/portage/__init__.py | 21 +++++++++++---------- pym/portage/tests/ebuild/test_pty_eof.py | 10 +++++----- 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'pym') diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 159515776..9adab4baf 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -3743,8 +3743,7 @@ def _test_pty_eof(): """ Returns True if this issues is fixed for the currently running version of python: http://bugs.python.org/issue5380 - Returns None if openpty fails, and False if the above issue - is not fixed. + Raises an EnvironmentError from openpty() if it fails. """ import array, pty, termios @@ -3752,12 +3751,8 @@ def _test_pty_eof(): test_string = _unicode_decode(test_string, encoding='utf_8', errors='strict') - try: - master_fd, slave_fd = pty.openpty() - except EnvironmentError: - global _disable_openpty - _disable_openpty = True - return None + # may raise EnvironmentError + master_fd, slave_fd = pty.openpty() master_file = os.fdopen(master_fd, 'rb') slave_file = os.fdopen(slave_fd, 'wb') @@ -3820,9 +3815,15 @@ def _create_pty_or_pipe(copy_term_size=None): got_pty = False global _disable_openpty, _tested_pty - if not _tested_pty: - if not _test_pty_eof(): + if not (_tested_pty or _disable_openpty): + try: + if not _test_pty_eof(): + _disable_openpty = True + except EnvironmentError as e: _disable_openpty = True + writemsg("openpty failed: '%s'\n" % str(e), + noiselevel=-1) + del e _tested_pty = True if _disable_openpty: diff --git a/pym/portage/tests/ebuild/test_pty_eof.py b/pym/portage/tests/ebuild/test_pty_eof.py index 3216eec19..8723372b1 100644 --- a/pym/portage/tests/ebuild/test_pty_eof.py +++ b/pym/portage/tests/ebuild/test_pty_eof.py @@ -15,8 +15,8 @@ class PtyEofTestCase(TestCase): # http://bugs.python.org/issue5380 # Since it might not be fixed, mark as todo. self.todo = True - result = portage._test_pty_eof() - # The result is only valid if openpty works (result is - # True or False, not None). - if result is not None: - self.assertEqual(result, True) + # The result is only valid if openpty does not raise EnvironmentError. + try: + self.assertEqual(portage._test_pty_eof(), True) + except EnvironmentError: + pass -- cgit v1.2.3-1-g7c22