def _to_ansi(obj, regexable=False):
 if isinstance(obj, basestring):
  obj = _ANSI_ESCAPE.sub('||||', obj)
 if isinstance(obj, dict):
  return dict(((key, _to_ansi(value, regexable=regexable)) for (key, value) in obj.items()))
 elif hasattr(obj, '__iter__'):
  return [_to_ansi(o) for o in obj]
 else:
  return ANSIString(to_unicode(obj), regexable=regexable)

def _to_ansi ( obj , regexable = False ) : if isinstance ( obj , basestring ) : obj = _ANSI_ESCAPE . sub ( '||||' , obj ) if isinstance ( obj , dict ) : return dict ( ( ( key , _to_ansi ( value , regexable = regexable ) ) for ( key , value ) in obj . items ( ) ) ) elif hasattr ( obj , '__iter__' ) : return [ _to_ansi ( o ) for o in obj ] else : return ANSIString ( to_unicode ( obj ) , regexable = regexable )
convert to ansistring .