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:
19
vcr/files.py
Normal file
19
vcr/files.py
Normal 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))
|
||||
Reference in New Issue
Block a user