in cassette/cassette_library.py [0:0]
def load_file(self):
"""Load MockedResponses from YAML file."""
data = {}
filename = self.filename
if not os.path.exists(filename):
log.info("File '{f}' does not exist.".format(f=filename))
return data
# Open and read in the file
with open(filename) as f:
encoded_str = f.read()
encoded_hash = _hash(encoded_str)
# If the contents are cached, return them
cached_result = CassetteLibrary.cache.get(filename, None)
if cached_result and cached_result['hash'] == encoded_hash:
return cached_result['data']
# Otherwise, parse the contents
content = self.encoder.load(encoded_str)
if content:
for k, v in content.items():
mock_response_class = MockedHTTPResponse
data[k] = mock_response_class.from_dict(v)
# Cache the file for later
self.save_to_cache(file_hash=encoded_hash, data=data)
return data