#NEWLINE# def sanitize_choices( choices , choices_all ) : #NEWLINE# #INDENT# "Clean up a stringlist configuration attribute: keep only choices\n    elements present in choices_all, remove duplicate elements, expand '*'\n    wildcard while keeping original stringlist order.\n    " #NEWLINE# seen = set ( ) #NEWLINE# others = [ x for x in choices_all if ( x not in choices ) ] #NEWLINE# res = [ ] #NEWLINE# for s in choices : #NEWLINE# #INDENT# if ( s in ( list ( choices_all ) + [ '*' ] ) ) : #NEWLINE# #INDENT# if ( not ( ( s in seen ) or seen . add ( s ) ) ) : #NEWLINE# #INDENT# res . extend ( ( list ( others ) if ( s == '*' ) else [ s ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return res