def improve_keys(data, metaquery=False):
 if (not isinstance(data, dict)):
  return data
 if metaquery:
  for key in six.iterkeys(data):
   if ('.$' in key):
    key_list = []
    for k in quote_key(key):
     key_list.append(k)
    new_key = '.'.join(key_list)
    data[new_key] = data.pop(key)
 else:
  for (key, value) in data.items():
   if isinstance(value, dict):
    improve_keys(value)
   if ('.' in key):
    new_dict = {}
    for k in quote_key(key, reverse=True):
     new = {}
     new[k] = (new_dict if new_dict else data.pop(key))
     new_dict = new
    data.update(new_dict)
   elif key.startswith('$'):
    new_key = parse.quote(key)
    data[new_key] = data.pop(key)
 return data

def improve_keys ( data , metaquery = False ) : if ( not isinstance ( data , dict ) ) : return data if metaquery : for key in six . iterkeys ( data ) : if ( '.$' in key ) : key_list = [ ] for k in quote_key ( key ) : key_list . append ( k ) new_key = '.' . join ( key_list ) data [ new_key ] = data . pop ( key ) else : for ( key , value ) in data . items ( ) : if isinstance ( value , dict ) : improve_keys ( value ) if ( '.' in key ) : new_dict = { } for k in quote_key ( key , reverse = True ) : new = { } new [ k ] = ( new_dict if new_dict else data . pop ( key ) ) new_dict = new data . update ( new_dict ) elif key . startswith ( '$' ) : new_key = parse . quote ( key ) data [ new_key ] = data . pop ( key ) return data
improves keys in dict if they contained .