mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-10 17:45:35 +00:00
Merge pull request #16 from dlecocq/master
Use the libYAML version of yaml if it's available
This commit is contained in:
10
vcr/files.py
10
vcr/files.py
@@ -2,10 +2,16 @@ import os
|
|||||||
import yaml
|
import yaml
|
||||||
from .cassette import Cassette
|
from .cassette import Cassette
|
||||||
|
|
||||||
|
# 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):
|
def load_cassette(cassette_path):
|
||||||
try:
|
try:
|
||||||
pc = yaml.load(open(cassette_path))
|
pc = yaml.load(open(cassette_path), Loader=Loader)
|
||||||
cassette = Cassette(pc)
|
cassette = Cassette(pc)
|
||||||
return cassette
|
return cassette
|
||||||
except IOError:
|
except IOError:
|
||||||
@@ -17,4 +23,4 @@ def save_cassette(cassette_path, cassette):
|
|||||||
if not os.path.exists(dirname):
|
if not os.path.exists(dirname):
|
||||||
os.makedirs(dirname)
|
os.makedirs(dirname)
|
||||||
with open(cassette_path, 'a') as cassette_file:
|
with open(cassette_path, 'a') as cassette_file:
|
||||||
cassette_file.write(yaml.dump(cassette.serialize()))
|
cassette_file.write(yaml.dump(cassette.serialize(), Dumper=Dumper))
|
||||||
|
|||||||
Reference in New Issue
Block a user