def _to_serializables(obj):
 if isinstance(obj, PRecord):
  result = dict(obj)
  result[_CLASS_MARKER] = obj.__class__.__name__
  return result
 elif isinstance(obj, PClass):
  result = obj._to_dict()
  result[_CLASS_MARKER] = obj.__class__.__name__
  return result
 elif isinstance(obj, PMap):
  return {_CLASS_MARKER: u'PMap', u'values': dict(obj).items()}
 elif isinstance(obj, (PSet, PVector, set)):
  return list(obj)
 elif isinstance(obj, FilePath):
  return {_CLASS_MARKER: u'FilePath', u'path': obj.path.decode('utf-8')}
 elif isinstance(obj, UUID):
  return {_CLASS_MARKER: u'UUID', 'hex': unicode(obj)}
 elif isinstance(obj, datetime):
  if (obj.tzinfo is None):
   raise ValueError('Datetime without a timezone: {}'.format(obj))
  return {_CLASS_MARKER: u'datetime', 'seconds': timegm(obj.utctimetuple())}
 return obj

def _to_serializables ( obj ) : if isinstance ( obj , PRecord ) : result = dict ( obj ) result [ _CLASS_MARKER ] = obj . __class__ . __name__ return result elif isinstance ( obj , PClass ) : result = obj . _to_dict ( ) result [ _CLASS_MARKER ] = obj . __class__ . __name__ return result elif isinstance ( obj , PMap ) : return { _CLASS_MARKER : u'PMap' , u'values' : dict ( obj ) . items ( ) } elif isinstance ( obj , ( PSet , PVector , set ) ) : return list ( obj ) elif isinstance ( obj , FilePath ) : return { _CLASS_MARKER : u'FilePath' , u'path' : obj . path . decode ( 'utf-8' ) } elif isinstance ( obj , UUID ) : return { _CLASS_MARKER : u'UUID' , 'hex' : unicode ( obj ) } elif isinstance ( obj , datetime ) : if ( obj . tzinfo is None ) : raise ValueError ( 'Datetime without a timezone: {}' . format ( obj ) ) return { _CLASS_MARKER : u'datetime' , 'seconds' : timegm ( obj . utctimetuple ( ) ) } return obj
this function turns assorted types into serializable objects .