in cassette/cassette_library.py [0:0]
def _load_request_from_file(self, cassette_name):
"""Return the mocked response object from the encoded file.
If the cassette file is in the cache, then use it. Otherwise, read
from the disk to fetch the particular request.
"""
filename = self.generate_path_from_cassette_name(cassette_name)
with open(filename) as f:
encoded_str = f.read()
self.log_cassette_used(self.generate_filename(cassette_name))
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:
mock_response_class = MockedHTTPResponse
req = mock_response_class.from_dict(content)
# Cache the file for later
self.save_to_cache(file_hash=encoded_hash, data=req)
return req