1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-10 17:45:35 +00:00
Files
vcrpy/vcr/serializers/jsonserializer.py
Kevin McCarthy e50f917cf4 Make Serializers Dumber
Let's have the serializer just worry about serializing the dict
that we hand it, and move the unicode stuff up to a serialize module.

This should hopefully let us move toward using a version string in
cassettes.
2014-05-10 11:52:35 -10:00

21 lines
537 B
Python

try:
import simplejson as json
except ImportError:
import json
def deserialize(cassette_string):
return json.loads(cassette_string)
def serialize(cassette_dict):
try:
return json.dumps(cassette_dict, indent=4)
except UnicodeDecodeError:
raise UnicodeDecodeError(
"Error serializing cassette to JSON. ",
"Does this HTTP interaction contain binary data? ",
"If so, use a different serializer (like the yaml serializer) for ",
"this request"
)