mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Format with line length 110 to match flake8 make black part of linting check Update travis spec for updated black requirements Add diff output for black on failure update changelog
26 lines
801 B
Python
26 lines
801 B
Python
# .. _persister_example:
|
|
|
|
import os
|
|
from ..serialize import serialize, deserialize
|
|
|
|
|
|
class FilesystemPersister(object):
|
|
@classmethod
|
|
def load_cassette(cls, cassette_path, serializer):
|
|
try:
|
|
with open(cassette_path) as f:
|
|
cassette_content = f.read()
|
|
except IOError:
|
|
raise ValueError("Cassette not found.")
|
|
cassette = deserialize(cassette_content, serializer)
|
|
return cassette
|
|
|
|
@staticmethod
|
|
def save_cassette(cassette_path, cassette_dict, serializer):
|
|
data = serialize(cassette_dict, serializer)
|
|
dirname, filename = os.path.split(cassette_path)
|
|
if dirname and not os.path.exists(dirname):
|
|
os.makedirs(dirname)
|
|
with open(cassette_path, "w") as f:
|
|
f.write(data)
|