def _cached_dfs_serialize(input_object):
 if (input_object is None):
  return None
 input_type = type(input_object)
 if (input_type in _BASIC_JSON_TYPES):
  return input_object
 is_pyrsistent = False
 if (input_type in _BASIC_JSON_COLLECTIONS):
  obj = input_object
 else:
  if _is_pyrsistent(input_object):
   is_pyrsistent = True
   cached_value = _cached_dfs_serialize_cache.get(input_object, _UNCACHED_SENTINEL)
   if (cached_value is not _UNCACHED_SENTINEL):
    return cached_value
  obj = _to_serializables(input_object)
 result = obj
 obj_type = type(obj)
 if (obj_type == dict):
  result = dict(((_cached_dfs_serialize(key), _cached_dfs_serialize(value)) for (key, value) in obj.iteritems()))
 elif ((obj_type == list) or (obj_type == tuple)):
  result = list((_cached_dfs_serialize(x) for x in obj))
 if is_pyrsistent:
  _cached_dfs_serialize_cache[input_object] = result
 return result

def _cached_dfs_serialize ( input_object ) : if ( input_object is None ) : return None input_type = type ( input_object ) if ( input_type in _BASIC_JSON_TYPES ) : return input_object is_pyrsistent = False if ( input_type in _BASIC_JSON_COLLECTIONS ) : obj = input_object else : if _is_pyrsistent ( input_object ) : is_pyrsistent = True cached_value = _cached_dfs_serialize_cache . get ( input_object , _UNCACHED_SENTINEL ) if ( cached_value is not _UNCACHED_SENTINEL ) : return cached_value obj = _to_serializables ( input_object ) result = obj obj_type = type ( obj ) if ( obj_type == dict ) : result = dict ( ( ( _cached_dfs_serialize ( key ) , _cached_dfs_serialize ( value ) ) for ( key , value ) in obj . iteritems ( ) ) ) elif ( ( obj_type == list ) or ( obj_type == tuple ) ) : result = list ( ( _cached_dfs_serialize ( x ) for x in obj ) ) if is_pyrsistent : _cached_dfs_serialize_cache [ input_object ] = result return result
this serializes an input object into something that can be serialized by the python json encoder .