Attempt to deserialize resource from response.

        :param requests.Response response: latest REST call response.
329059
def _deserialize(self, response):
        
        # Hacking response with initial status_code
        previous_status = response.status_code
        response.status_code = self.initial_status_code
        resource = self.get_outputs(response)
        response.status_code = previous_status

        # Hack for Storage or SQL, to workaround the bug in the Python generator
        if resource is None:
            previous_status = response.status_code
            for status_code_to_test in [200, 201]:
                try:
                    response.status_code = status_code_to_test
                    resource = self.get_outputs(response)
                except ClientException:
                    pass
                else:
                    return resource
                finally:
                    response.status_code = previous_status
        return resource
1094997
def _finalize_response(self, response):
        

        res = HttpResponse(content=response.content,
                           content_type=self._get_content_type())
        # status_code is set separately to allow zero
        res.status_code = response.code
        return res
470590
def parse_response(self, response):
        
        status = response.status_code
        if response.ok:
            data = response.json()
            return HttpResponse(ok=response.ok, status=status, errors=None, data=data)
        else:
            try:
                errors = response.json()
            except ValueError:
                errors = response.content
            return HttpResponse(ok=response.ok, status=status, errors=errors, data=None)
1199308
def _response_item_to_object(self, resp_item):
        
        item_cls = resources.get_model_class(self.resource_type)
        properties_dict = resp_item[self.resource_type]
        new_dict = helpers.remove_properties_containing_None(properties_dict)
        # raises exception if something goes wrong
        obj = item_cls(new_dict)
        return obj
75494
def decode_response(status: int, headers: MutableMapping, body: bytes) -> dict:
    
    data = decode_body(headers, body)
    raise_for_status(status, headers, data)
    raise_for_api_error(headers, data)

    return data
261042
def _from_json_list(cls, response_raw, wrapper=None):
        

        json = response_raw.body_bytes.decode()
        obj = converter.json_to_class(dict, json)
        array = obj[cls._FIELD_RESPONSE]
        array_deserialized = []

        for item in array:
            item_unwrapped = item if wrapper is None else item[wrapper]
            item_deserialized = converter.deserialize(cls, item_unwrapped)
            array_deserialized.append(item_deserialized)

        pagination = converter.deserialize(client.Pagination,
                                           obj[cls._FIELD_PAGINATION])

        return client.BunqResponse(array_deserialized, response_raw.headers,
                                   pagination)
1215715
def _process_for_id(cls, response_raw):
        

        json = response_raw.body_bytes.decode()
        obj = converter.json_to_class(dict, json)
        id_ = converter.deserialize(
            Id,
            cls._unwrap_response_single(obj, cls._FIELD_ID)
        )

        return client.BunqResponse(id_.id_, response_raw.headers)
1336735
def decode_response(self, raw_response):
        
        # Transform response into a dict
        import json
        data = json.loads(raw_response)
        # Retrieve the response id
        self.response_id = data[self.RESPONSE_ID]
        # Check if the response id match the command id
        self.check_id()
        # Get response data
        if self.RESPONSE_RESULT in data:
            self.result = data[self.RESPONSE_RESULT]
        elif self.RESPONSE_ERROR in data:
            # If the response is an error raise YeelightError Exception
            message = data[self.RESPONSE_ERROR][self.ERROR_MESSAGE]
            code = data[self.RESPONSE_ERROR][self.ERROR_CODE]
            raise YeelightError(message, code, self.command)
481471
def _make_request(self, request):
        
        # TODO: I'm sure all kinds of error checking needs to go here
        try:
            response_raw = urllib2.urlopen(request)
        except urllib2.HTTPError, e:
            print e.read()
            raise

        response_str = response_raw.read()
        response = json.loads(response_str)

        self._last_request = request
        self._last_response = response_raw
        self._last_response_str = response_str
        return response
817133
def _request_process_json(self, response):
        
        data = []
        try:
            if self._api_branch == 'bulk':
                response_data = self._request_bulk(response)
            else:
                response_data = response.json()

            if self._request_entity is None:
                data = response_data
                status = 'Success'
            elif self._api_branch == 'bulk':
                data, status = self._request_process_json_bulk(response_data)
            elif response_data.get('data') is None:
                data, status = self._request_process_json_status(response_data)
            elif response_data.get('status') == 'Success':
                data, status = self._request_process_json_standard(response_data)

                # setup pagination
                if self._result_count is None:
                    self._result_count = response_data.get('data', {}).get('resultCount')
            else:
                self.tcex.log.error('Failed Request: {}'.format(response.text))
                status = 'Failure'
        except KeyError as e:
            # TODO: Remove try/except block
            status = 'Failure'
            msg = u'Error: Invalid key {}. [{}] '.format(e, self.request_entity)
            self.tcex.log.error(msg)
        except ValueError as e:
            # TODO: Remove try/except block
            status = 'Failure'
            msg = u'Error: ({})'.format(e)
            self.tcex.log.error(msg)

        return data, status
1180589
def deserialize(cls, v):
        
        if v is None:
            return None
        if cls == Gear and v.get('resource_state') == 3:
            if 'frame_type' in v:
                o = Bike()
            else:
                o = Shoe()
        else:
            o = cls()
        o.from_dict(v)
        return o
10815
def _serialize(self):
        

        # Do something appropriate if the response object is unbound
        if self._defcode is None:
            raise exceptions.UnboundResponse()

        # Build the response
        resp = self.response_class(request=self.req, status=self.code,
                                   headerlist=self._headers.items())

        # Do we have a body?
        if self.result:
            resp.content_type = self.content_type
            resp.body = self.serializer(self.result)

        # Return the response
        return resp
809611
def deserialize(self):
        

        super(Deserializer, self).deserialize()

        try:
            return json.loads(self.req.get_body())
        except TypeError:
            link = 'tools.ietf.org/html/rfc7159'
            self.fail('Typically, this error is due to a missing JSON '
                      'payload in your request when one was required. '
                      'Otherwise, it could be a bug in our API.', link)
        except UnicodeDecodeError:
            link = 'tools.ietf.org/html/rfc7159#section-8.1'
            self.fail('We failed to process your JSON payload & it is '
                      'most likely due to non UTF-8 encoded characters '
                      'in your JSON.', link)
        except ValueError as exc:
            link = 'tools.ietf.org/html/rfc7159'
            self.fail('The JSON payload appears to be malformed & we '
                      'failed to process it. The error with line & column '
                      'numbers is: %s' % exc.message, link)
894204
def decode_response(client_message, to_object=None):
    
    parameters = dict(response=None)
    if not client_message.read_bool():
        parameters['response'] = to_object(client_message.read_data())
    return parameters
587487
def from_response(cls, response: 'ClientResponse') -> Any:
        
        obj = cls.response_wrapper_cls(response, cls(response.headers,
                                                     response.content))
        return obj
572187
def process_response(self, request, response):
        
        if not hasattr(request, 'location'):
            return response

        storage = storage_class(request=request, response=response)
        try:
            storage.set(location=request.location)
        except ValueError:
            # bad location_id
            pass
        return response
839223
def parse_response(self, resp):
        
        p, u = self.getparser()

        if hasattr(resp,'text'):
            # modern requests will do this for us
            text = resp.text # this is unicode(py2)/str(py3)
        else:

            encoding = requests.utils.get_encoding_from_headers(resp.headers)
            if encoding is None:
                encoding='utf-8' # FIXME: what to do here?

            if sys.version_info[0]==2:
                text = unicode(resp.content, encoding, errors='replace')
            else:
                assert sys.version_info[0]==3
                text = str(resp.content, encoding, errors='replace')
        p.feed(text)
        p.close()
        return u.close()