1# -*- coding: utf-8 -*-
2from .base import BaseMatcher
3
4from betamax import util
5
6
7class BodyMatcher(BaseMatcher):
8    # Matches based on the body of the request
9    name = 'body'
10
11    def match(self, request, recorded_request):
12        recorded_request = util.deserialize_prepared_request(recorded_request)
13
14        request_body = b''
15        if request.body:
16            request_body = util.coerce_content(request.body)
17
18        recorded_body = b''
19        if recorded_request.body:
20            recorded_body = util.coerce_content(recorded_request.body)
21
22        return recorded_body == request_body
23