1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-10 09:35:34 +00:00

bring back the files module, but do serialization in cassette

This commit is contained in:
Kevin McCarthy
2013-08-05 21:27:15 -10:00
parent 6cbd84c15f
commit 77f0ef5c33
2 changed files with 34 additions and 20 deletions

19
vcr/files.py Normal file
View File

@@ -0,0 +1,19 @@
import os
import yaml
# Use the libYAML versions if possible
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
def load_cassette(cassette_path):
return yaml.load(open(cassette_path), Loader=Loader)
def save_cassette(cassette_path, data):
#TODO: safe overwrite using tmpfile
dirname, filename = os.path.split(cassette_path)
if not os.path.exists(dirname):
os.makedirs(dirname)
with open(cassette_path, 'a') as cassette_file:
cassette_file.write(yaml.dump(data, Dumper=Dumper))