#NEWLINE# def lookup( key , val , item ) : #NEWLINE# #INDENT# "Checks if key-val pair exists in item using various lookup types\n\n    The lookup types are derived from the `key` and then used to check\n    if the lookup holds true for the item::\n\n        >>> lookup('request__url__exact', 'http://example.com', item)\n\n    The above will return True if item['request']['url'] ==\n    'http://example.com' else False\n\n    :param key  : (str) that represents the field name to find\n    :param val  : (mixed) object to match the value in the item against\n    :param item : (dict)\n    :rtype      : (boolean) True if field-val exists else False\n\n    " #NEWLINE# ( init , last ) = dunder_partition ( key ) #NEWLINE# if ( last == 'exact' ) : #NEWLINE# #INDENT# return ( dunder_get ( item , init ) == val ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'neq' ) : #NEWLINE# #INDENT# return ( dunder_get ( item , init ) != val ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'contains' ) : #NEWLINE# #INDENT# val = guard_str ( val ) #NEWLINE# return iff_not_none ( dunder_get ( item , init ) , ( lambda y : ( val in y ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'icontains' ) : #NEWLINE# #INDENT# val = guard_str ( val ) #NEWLINE# return iff_not_none ( dunder_get ( item , init ) , ( lambda y : ( val . lower ( ) in y . lower ( ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'in' ) : #NEWLINE# #INDENT# val = guard_iter ( val ) #NEWLINE# return ( dunder_get ( item , init ) in val ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'startswith' ) : #NEWLINE# #INDENT# val = guard_str ( val ) #NEWLINE# return iff_not_none ( dunder_get ( item , init ) , ( lambda y : y . startswith ( val ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'istartswith' ) : #NEWLINE# #INDENT# val = guard_str ( val ) #NEWLINE# return iff_not_none ( dunder_get ( item , init ) , ( lambda y : y . lower ( ) . startswith ( val . lower ( ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'endswith' ) : #NEWLINE# #INDENT# val = guard_str ( val ) #NEWLINE# return iff_not_none ( dunder_get ( item , init ) , ( lambda y : y . endswith ( val ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'iendswith' ) : #NEWLINE# #INDENT# val = guard_str ( val ) #NEWLINE# return iff_not_none ( dunder_get ( item , init ) , ( lambda y : y . lower ( ) . endswith ( val . lower ( ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'gt' ) : #NEWLINE# #INDENT# return iff_not_none ( dunder_get ( item , init ) , ( lambda y : ( y > val ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'gte' ) : #NEWLINE# #INDENT# return iff_not_none ( dunder_get ( item , init ) , ( lambda y : ( y >= val ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'lt' ) : #NEWLINE# #INDENT# return iff_not_none ( dunder_get ( item , init ) , ( lambda y : ( y < val ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'lte' ) : #NEWLINE# #INDENT# return iff_not_none ( dunder_get ( val , init ) , ( lambda y : ( y <= val ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'regex' ) : #NEWLINE# #INDENT# return iff_not_none ( dunder_get ( item , init ) , ( lambda y : ( re . search ( val , y ) is not None ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( last == 'filter' ) : #NEWLINE# #INDENT# val = guard_Q ( val ) #NEWLINE# result = guard_list ( dunder_get ( item , init ) ) #NEWLINE# return ( len ( list ( filter_items ( result , val ) ) ) > 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( dunder_get ( item , key ) == val )