def _serialize(obj, **options): if options: log.warning('options are currently unusued') try: return msgpack.dumps(obj) except Exception as error: raise SerializationError(error)
def serialize(obj, **options): """ Serialize Python data to JSON. :param obj: the data structure to serialize :param options: options given to lower json/simplejson module. """ try: if 'fp' in options: return json.dump(obj, **options) else: return json.dumps(obj, **options) except Exception as error: raise SerializationError(error)
def serialize(obj, **options): """ Serialize Python data to YAML. :param obj: the data structure to serialize :param options: options given to lower yaml module. """ options.setdefault('Dumper', BaseDumper) try: response = yaml.dump(obj, **options) if response.endswith('\n...\n'): return response[:-5] if response.endswith('\n'): return response[:-1] return response except Exception as error: raise SerializationError(error)