def search_by_attributes(service, **kwargs):
 if ('search' in inspect.getargspec(service.list)[0]):
  res = service.list(search=' and '.join(('{}={}'.format(k, v) for (k, v) in kwargs.items())))
 else:
  res = [e for e in service.list() if (len([k for (k, v) in kwargs.items() if (getattr(e, k, None) == v)]) == len(kwargs))]
 res = (res or [None])
 return res[0]

def search_by_attributes ( service , ** kwargs ) : if ( 'search' in inspect . getargspec ( service . list ) [ 0 ] ) : res = service . list ( search = ' and ' . join ( ( '{}={}' . format ( k , v ) for ( k , v ) in kwargs . items ( ) ) ) ) else : res = [ e for e in service . list ( ) if ( len ( [ k for ( k , v ) in kwargs . items ( ) if ( getattr ( e , k , None ) == v ) ] ) == len ( kwargs ) ) ] res = ( res or [ None ] ) return res [ 0 ]
search for the entity by attributes .