def quote_key(key, reverse=False):
 r = ((-1) if reverse else 1)
 for k in key.split('.')[::r]:
  if k.startswith('$'):
   k = parse.quote(k)
  (yield k)

def quote_key ( key , reverse = False ) : r = ( ( - 1 ) if reverse else 1 ) for k in key . split ( '.' ) [ : : r ] : if k . startswith ( '$' ) : k = parse . quote ( k ) ( yield k )
prepare key for storage data in mongodb .