This is patch

[ 1005008 ] curses.wrapper should also forward keyword args

Plus my rewrite to use finally as opposed to painfully doing the
equivalent by hand.
This commit is contained in:
Michael W. Hudson 2004-08-07 15:18:07 +00:00
parent 6f937b1c30
commit 09ad235f99
1 changed files with 4 additions and 17 deletions

View File

@ -9,7 +9,7 @@
import sys, curses import sys, curses
def wrapper(func, *rest): def wrapper(func, *args, **kwds):
"""Wrapper function that initializes curses and calls another function, """Wrapper function that initializes curses and calls another function,
restoring normal keyboard/screen behavior on error. restoring normal keyboard/screen behavior on error.
The callable object 'func' is then passed the main window 'stdscr' The callable object 'func' is then passed the main window 'stdscr'
@ -41,23 +41,10 @@ def wrapper(func, *rest):
except: except:
pass pass
res = func(stdscr, *rest) return func(stdscr, *rest)
except: finally:
# In the event of an error, restore the terminal
# to a sane state.
stdscr.keypad(0)
curses.echo()
curses.nocbreak()
curses.endwin()
# Pass the exception upwards
(exc_type, exc_value, exc_traceback) = sys.exc_info()
raise exc_type, exc_value, exc_traceback
else:
# Set everything back to normal # Set everything back to normal
stdscr.keypad(0) stdscr.keypad(0)
curses.echo() curses.echo()
curses.nocbreak() curses.nocbreak()
curses.endwin() # Terminate curses curses.endwin()
return res