<s> from . import string_score <EOL> import re <EOL> def filter_commands ( marks , search_string ) : <EOL> '''<STR_LIT>''' <EOL> def sort_marks ( marks , search_string ) : <EOL> return sorted ( <EOL> marks , <EOL> key = lambda m : ( string_score . score ( m . cmd , search_string ) * <NUM_LIT:2> + string_score . score ( m . alias , search_string ) ) , <EOL> reverse = True <EOL> ) <EOL> def contained ( candidate , container ) : <EOL> tmp = container [ : ] <EOL> try : <EOL> for i , word in enumerate ( candidate ) : <EOL> if i == len ( candidate ) - <NUM_LIT:1> : <EOL> if any ( word in c for c in tmp ) : <EOL> return True <EOL> else : <EOL> return False <EOL> else : <EOL> tmp . remove ( word ) <EOL> except ValueError : <EOL> return False <EOL> search_string = search_string . lstrip ( ) <EOL> if not search_string : <EOL> return sort_marks ( marks , "<STR_LIT>" ) <EOL> filtered_bookmarks = [ ] <EOL> words_re = re . compile ( '<STR_LIT>' ) <EOL> search_words = words_re . findall ( search_string . lower ( ) ) <EOL> for mark in marks : <EOL> mark_splitted = words_re . findall ( mark . cmd . lower ( ) ) + words_re . findall ( mark . alias . lower ( ) ) <EOL> if contained ( search_words , mark_splitted ) : <EOL> filtered_bookmarks . append ( mark ) <EOL> return sort_marks ( filtered_bookmarks , search_string ) </s>
