@classmethod
    @contextlib.contextmanager
    def record(cls, filename, indentation=4, encoding='utf-8'):
        try:
            import urllib3
        except __HOLE__:
            msg = (
                'HTTPretty requires urllib3 installed '
                'for recording actual requests.'
            )
            raise RuntimeError(msg)

        http = urllib3.PoolManager()

        cls.enable()
        calls = []

        def record_request(request, uri, headers):
            cls.disable()

            response = http.request(request.method, uri)
            calls.append({
                'request': {
                    'uri': uri,
                    'method': request.method,
                    'headers': dict(request.headers),
                    'body': decode_utf8(request.body),
                    'querystring': request.querystring
                },
                'response': {
                    'status': response.status,
                    'body': decode_utf8(response.data),
                    'headers': dict(response.headers)
                }
            })
            cls.enable()
            return response.status, response.headers, response.data

        for method in cls.METHODS:
            cls.register_uri(method, MULTILINE_ANY_REGEX, body=record_request)

        yield
        cls.disable()
        with codecs.open(filename, 'w', encoding) as f:
            f.write(json.dumps(calls, indent=indentation))
dataset/ETHPy150Open gabrielfalcao/HTTPretty/httpretty/core.py/httpretty.record