How to use the gabbi.utils.decode_response_content function in gabbi

To help you get started, we’ve selected a few gabbi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cdent / gabbi / gabbi / httpclient.py View on Github external
def _print_body(self, headers, content):
        """Output body if not binary."""
        content_type = utils.extract_content_type(headers)[0]
        if self._show_body and utils.not_binary(content_type):
            content = utils.decode_response_content(headers, content)
            # TODO(cdent): Using the JSONHandler here instead of
            # just the json module to make it clear that eventually
            # we could pretty print any printable output by using a
            # handler's loads() and dumps(). Not doing that now
            # because it would be pointless (no other interesting
            # handlers) and this approach may be entirely wrong.
            if content and jsonhandler.JSONHandler.accepts(content_type):
                data = jsonhandler.JSONHandler.loads(content)
                content = jsonhandler.JSONHandler.dumps(data, pretty=True)
            self._verbose_output('')
            self._verbose_output(content)
github cdent / gabbi / gabbi / case.py View on Github external
headers=headers,
                body=body,
                redirect=redirect
            )
        except wsgi_intercept.WSGIAppError as exc:
            # Extract and re-raise the wrapped exception.
            six.reraise(exc.exception_type, exc.exception_value,
                        exc.traceback)

        # Set headers and location attributes for follow on requests
        self.response = response
        if 'location' in response:
            self.location = response['location']

        # Decode and store response
        decoded_output = utils.decode_response_content(response, content)
        self.content_type = response.get('content-type', '').lower()
        loader_class = self.get_content_handler(self.content_type)
        if decoded_output and loader_class:
            # save structured response data
            self.response_data = loader_class.loads(decoded_output)
        else:
            self.response_data = None
        self.output = decoded_output