def _recursive_escape(value, esc=conditional_escape):
 if isinstance(value, dict):
  return type(value)(((esc(k), _recursive_escape(v)) for (k, v) in value.iteritems()))
 elif isinstance(value, (list, tuple)):
  return type(value)((_recursive_escape(v) for v in value))
 elif isinstance(value, basestring):
  return esc(value)
 elif (isinstance(value, (int, long, float)) or (value in (True, False, None))):
  return value
 return esc(DjangoJSONEncoder().default(value))

def _recursive_escape ( value , esc = conditional_escape ) : if isinstance ( value , dict ) : return type ( value ) ( ( ( esc ( k ) , _recursive_escape ( v ) ) for ( k , v ) in value . iteritems ( ) ) ) elif isinstance ( value , ( list , tuple ) ) : return type ( value ) ( ( _recursive_escape ( v ) for v in value ) ) elif isinstance ( value , basestring ) : return esc ( value ) elif ( isinstance ( value , ( int , long , float ) ) or ( value in ( True , False , None ) ) ) : return value return esc ( DjangoJSONEncoder ( ) . default ( value ) )
recursively escapes strings in an object .