How to use the gabbi.utils.extract_content_type 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
full_url = self._parse_url(base_url)

        # Replace variables in headers with variable values. This includes both
        # in the header key and the header value.
        test['request_headers'] = self._replace_headers_template(
            test['name'], test['request_headers'])
        test['response_headers'] = self._replace_headers_template(
            test['name'], test['response_headers'])

        method = test['method'].upper()
        headers = test['request_headers']

        if test['data'] != '':
            body = self._test_data_to_string(
                test['data'],
                utils.extract_content_type(headers, default='')[0])
        else:
            body = ''

        # ensure body is bytes, encoding as UTF-8 because that's
        # what we do here
        if isinstance(body, six.text_type):
            body = body.encode('UTF-8')

        if test['poll']:
            count = int(float(self.replace_template(
                test['poll'].get('count', 1))))
            delay = float(self.replace_template(test['poll'].get('delay', 1)))
            failure = None
            while count:
                try:
                    self._run_request(full_url, method, headers, body,