Modernize code a bit: use isinstance instead of type(); return True/False

This commit is contained in:
Andrew M. Kuchling 2003-09-02 11:52:06 +00:00
parent 0ec5288d09
commit f19f8610fa
1 changed files with 7 additions and 4 deletions

View File

@ -160,17 +160,20 @@ _capability_names = {
} }
def has_key(ch): def has_key(ch):
if type(ch) == type( '' ): ch = ord(ch) if isinstance(ch, str):
ch = ord(ch)
# Figure out the correct capability name for the keycode. # Figure out the correct capability name for the keycode.
capability_name = _capability_names.get(ch) capability_name = _capability_names.get(ch)
if capability_name is None: if capability_name is None:
return 0 return False
#Check the current terminal description for that capability; #Check the current terminal description for that capability;
#if present, return true, else return false. #if present, return true, else return false.
if _curses.tigetstr( capability_name ): return 1 if _curses.tigetstr( capability_name ):
else: return 0 return True
else:
return False
if __name__ == '__main__': if __name__ == '__main__':
# Compare the output of this implementation and the ncurses has_key, # Compare the output of this implementation and the ncurses has_key,