#NEWLINE# def choose_multiple_from_map( somemap , chosen = None , prompt = 'choose multiple' , input = raw_input , error = default_error ) : #NEWLINE# #INDENT# 'Choose multiple items from a mapping.\n    Returns a mapping of items chosen. Type in the key to select the values.\n    ' #NEWLINE# somemap = somemap . copy ( ) #NEWLINE# if ( chosen is None ) : #NEWLINE# #INDENT# chosen = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# while 1 : #NEWLINE# #INDENT# print ( 'Choose from list. Enter to end, negative index removes from chosen.' ) #NEWLINE# if somemap : #NEWLINE# #INDENT# first = print_menu_map ( somemap ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( '(You have selected all possible choices.)' ) #NEWLINE# first = 0 #NEWLINE# #UNINDENT# if chosen : #NEWLINE# #INDENT# print ( 'You have: ' ) #NEWLINE# print_menu_map ( chosen ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ri = get_input ( prompt , None , input ) #NEWLINE# #UNINDENT# except EOFError : #NEWLINE# #INDENT# return chosen #NEWLINE# #UNINDENT# if ( not ri ) : #NEWLINE# #INDENT# return chosen #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# idx = type ( first ) ( ri ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# error ( 'Bad selection. Please try again.' ) #NEWLINE# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( idx < 0 ) : #NEWLINE# #INDENT# idx = ( - idx ) #NEWLINE# try : #NEWLINE# #INDENT# somemap [ idx ] = chosen [ idx ] #NEWLINE# del chosen [ idx ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# error ( 'Selection out of range.' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# chosen [ idx ] = somemap [ idx ] #NEWLINE# del somemap [ idx ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# error ( 'Selection out of range.' )