def cast_keys(o, cast=str, encoding='utf-8'):
 if isinstance(o, (dict, Storage)):
  if isinstance(o, dict):
   newobj = dict()
  else:
   newobj = Storage()
  for (k, v) in o.items():
   if ((cast == str) and isinstance(k, unicodeT)):
    key = k.encode(encoding)
   else:
    key = cast(k)
   newobj[key] = cast_keys(v, cast=cast, encoding=encoding)
 elif isinstance(o, (tuple, set, list)):
  newobj = []
  for item in o:
   newobj.append(cast_keys(item, cast=cast, encoding=encoding))
  if isinstance(o, tuple):
   newobj = tuple(newobj)
  elif isinstance(o, set):
   newobj = set(newobj)
 else:
  newobj = o
 return newobj

def cast_keys ( o , cast = str , encoding = 'utf-8' ) : if isinstance ( o , ( dict , Storage ) ) : if isinstance ( o , dict ) : newobj = dict ( ) else : newobj = Storage ( ) for ( k , v ) in o . items ( ) : if ( ( cast == str ) and isinstance ( k , unicodeT ) ) : key = k . encode ( encoding ) else : key = cast ( k ) newobj [ key ] = cast_keys ( v , cast = cast , encoding = encoding ) elif isinstance ( o , ( tuple , set , list ) ) : newobj = [ ] for item in o : newobj . append ( cast_keys ( item , cast = cast , encoding = encoding ) ) if isinstance ( o , tuple ) : newobj = tuple ( newobj ) elif isinstance ( o , set ) : newobj = set ( newobj ) else : newobj = o return newobj
builds a new object with <cast> type keys .