get request and response info from Response() object.
353287
def get_req_resp_record(self, resp_obj):
        
        def log_print(req_resp_dict, r_type):
            msg = "\n================== {} details ==================\n".format(r_type)
            for key, value in req_resp_dict[r_type].items():
                msg += "{:<16} : {}\n".format(key, repr(value))
            logger.log_debug(msg)

        req_resp_dict = {
            "request": {},
            "response": {}
        }

        # record actual request info
        req_resp_dict["request"]["url"] = resp_obj.request.url
        req_resp_dict["request"]["method"] = resp_obj.request.method
        req_resp_dict["request"]["headers"] = dict(resp_obj.request.headers)

        request_body = resp_obj.request.body
        if request_body:
            request_content_type = lower_dict_keys(
                req_resp_dict["request"]["headers"]
            ).get("content-type")
            if request_content_type and "multipart/form-data" in request_content_type:
                # upload file type
                req_resp_dict["request"]["body"] = "upload file stream (OMITTED)"
            else:
                req_resp_dict["request"]["body"] = request_body

        # log request details in debug mode
        log_print(req_resp_dict, "request")

        # record response info
        req_resp_dict["response"]["ok"] = resp_obj.ok
        req_resp_dict["response"]["url"] = resp_obj.url
        req_resp_dict["response"]["status_code"] = resp_obj.status_code
        req_resp_dict["response"]["reason"] = resp_obj.reason
        req_resp_dict["response"]["cookies"] = resp_obj.cookies or {}
        req_resp_dict["response"]["encoding"] = resp_obj.encoding
        resp_headers = dict(resp_obj.headers)
        req_resp_dict["response"]["headers"] = resp_headers

        lower_resp_headers = lower_dict_keys(resp_headers)
        content_type = lower_resp_headers.get("content-type", "")
        req_resp_dict["response"]["content_type"] = content_type

        if "image" in content_type:
            # response is image type, record bytes content only
            req_resp_dict["response"]["content"] = resp_obj.content
        else:
            try:
                # try to record json data
                req_resp_dict["response"]["json"] = resp_obj.json()
            except ValueError:
                # only record at most 512 text charactors
                resp_text = resp_obj.text
                req_resp_dict["response"]["text"] = omit_long_data(resp_text)

        # log response details in debug mode
        log_print(req_resp_dict, "response")

        return req_resp_dict
143168
def response_doc(self):
        """"""
        try:
            return self.__dict__['response_doc']
        except KeyError:
            self.__dict__['response_doc'] = ElementTree.fromstring(
                self.response_xml
            )
            return self.__dict__['response_doc']
1318423
def _process_response(self, request, response):
        """"""
        log_format = self._get_log_format(request)
        if not log_format:
            return response

        params = self._get_parameters_from_request(request)
        # log a message displayed to user
        messages = django_messages.get_messages(request)
        result_message = None
        if messages:
            result_message = ', '.join('%s: %s' % (message.tags, message)
                                       for message in messages)
        elif 'action' in request.POST:
            result_message = request.POST['action']
        params['message'] = result_message
        params['http_status'] = response.status_code

        self.OPERATION_LOG.info(log_format, params)

        return response
274079
def extract_data_from_response(self, response, data_key=None):
        """"""
        response_json_data = response.json()
        # Seems to be two types of response, a dict with keys and then lists of data or a flat list data with no key.
        if type(response_json_data) == list:
            # Return the data
            return response_json_data
        elif type(response_json_data) == dict:
            if data_key is None:
                return response_json_data
            else:
                return response_json_data[data_key]
        else:
            raise CanvasAPIError(response)
320899
def make_response(obj):
    """"""
    if obj is None:
        raise TypeError("Handler return value cannot be None.")
    if isinstance(obj, Response):
        return obj
    return Response(200, body=obj)
1203828
def from_response(response, body):
    
    if isinstance(response, dict):
        status = response.get("status_code")
    else:
        status = response.status_code
    cls = _code_map.get(int(status), ClientException)

#    import pyrax
#    pyrax.utils.trace()

    request_id = response.headers.get("x-compute-request-id")
    if body:
        message = "n/a"
        details = "n/a"
        if isinstance(body, dict):
            message = body.get("message")
            details = body.get("details")
            if message is details is None:
                error = body[next(iter(body))]
                if isinstance(error, dict):
                    message = error.get("message", None)
                    details = error.get("details", None)
                else:
                    message = error
                    details = None
        else:
            message = body
        return cls(code=status, message=message, details=details,
                   request_id=request_id)
    else:
        return cls(code=status, request_id=request_id)
1149372
def get_dict_from_response(response):
    """"""
    if getattr(response, '_resp') and response._resp.code > 400:
        raise OAuthResponseError(
                'Application mis-configuration in Globus', None, response
            )

    return response.data
624764
def info(self, req) -> ResponseInfo:
        
        r = ResponseInfo()
        r.version = "1.0"
        r.last_block_height = 0
        r.last_block_app_hash = b''
        return r
796994
def process_request(self, request_object):
        """"""

        # Retrieve the object by its identifier
        entity = request_object.entity_cls.get(request_object.identifier)

        # Update the object and return the updated data
        resource = entity.update(request_object.data)
        return ResponseSuccess(Status.SUCCESS, resource)
219043
def info():
    '''
    
    '''
    response = salt.utils.http.query(
        "{0}/v2/info".format(_base_url()),
        decode_type='json',
        decode=True,
    )
    return response['dict']
1212970
def parse(self, response):
        """"""
        info = response.get('info')
        res = self._regex.search(info)

        self._processed += int(res.group(1))
        self._failed += int(res.group(2))
        self._total += int(res.group(3))
        self._time += Decimal(res.group(4))
        self._chunk += 1
629698
def do_response(self, response_args=None, request=None, **kwargs):
        

        links = [Link(href=h, rel=OIC_ISSUER) for h in kwargs['hrefs']]

        _response = JRD(subject=kwargs['subject'], links=links)

        info = {
            'response': _response.to_json(),
            'http_headers': [('Content-type', 'application/json')]
        }

        return info
544475
def _get_response(self, endpoint, query, is_post=False):
        """"""
        timeout_secs = self._settings.get('timeout', 10)
        headers = self._settings.get('request_headers', {})
        try:
            if is_post:
                response = requests.post(
                    endpoint, data=query, headers=headers, timeout=timeout_secs)
            else:
                response = requests.get(
                    endpoint, params=query, headers=headers, timeout=timeout_secs)
        except requests.exceptions.Timeout as e:
            raise Exception(
                'API request timed out after %s seconds.' % timeout_secs)
        except Exception as e:
            raise e

        if response.status_code != 200:
            raise Exception('Received status code %s from %s. Content is:\n%s'
                            % (response.status_code,
                               self.get_service_name(),
                               response.text))
        return response
490862
def check_response(self, resp):
        """"""
        if resp.status_code == 400:
            raise ApiException(json.loads(resp.content).get('message'))
        return resp
494127
def info(self):
        
        if self._session_url is None:
            return None

        resp = self.get(self._session_url)
        resp.raise_for_status()
        return response_to_json_dict(resp)
1279513
def _get(url, params=None):
        """"""
        try:
            response = requests.get(url, params=params)
            response.raise_for_status()
            # If JSON fails, return raw data
            # (e.g. when downloading CSV job logs).
            try:
                return response.json()
            except ValueError:
                return response.text
        except NameError:
            url = '{0}?{1}'.format(url, urllib.urlencode(params))
            return json.loads(urllib2.urlopen(url).read().decode(ENCODING))
346673
def _get_response(self, params):
        
        return self._session.get(
            self._api_url, params=params, timeout=self._timeout
        ).json(encoding="utf8")