Deserializes response into an object.

        :param response: RESTResponse object to be deserialized.
        :param response_type: class literal for
            deserialzied object, or string of class name.

        :return: deserialized object.
180913
def deserialize(self, response, response_type):
        
        # handle file downloading
        # save response body into a tmp file and return the instance
        if "file" == response_type:
            return self.__deserialize_file(response)

        # fetch data from response object
        try:
            data = json.loads(response.data)
        except ValueError:
            data = response.data

        return self.__deserialize(data, response_type)
105830
def response_class(self, cls):
        
        s = self._clone()
        s._response_class = cls
        return s
173328
def deserialize_import(response_json)
      return FioAPI::Payments::Status.new(error_code: 500) unless response_json
      FioAPI::Payments::Status.new(
        error_code: response_json.try_path('errorCode').to_i,
        error_message: response_json.try_path('message').to_s,
        id_instruction: response_json.try_path('idInstruction').to_i,
        sum_credit: response_json.try_path('sums', 'sum', 'sumCredit').to_f,
        sum_debet: response_json.try_path('sums', 'sum', 'sumDebet').to_f
      )
    end
1192786
def deserialize_iter(self, attr, iter_type):
        
        if attr is None:
            return None
        if isinstance(attr, ET.Element): # If I receive an element here, get the children
            attr = list(attr)
        if not isinstance(attr, (list, set)):
            raise DeserializationError("Cannot deserialize as [{}] an object of type {}".format(
                iter_type,
                type(attr)
            ))
        return [self.deserialize_data(a, iter_type) for a in attr]
608419
def _deserialize(data, klass):
    
    if data is None:
        return None

    if klass in six.integer_types or klass in (float, str, bool):
        return _deserialize_primitive(data, klass)
    elif klass == object:
        return _deserialize_object(data)
    elif klass == datetime.date:
        return deserialize_date(data)
    elif klass == datetime.datetime:
        return deserialize_datetime(data)
    elif type(klass) == typing.GenericMeta:
        if klass.__extra__ == list:
            return _deserialize_list(data, klass.__args__[0])
        if klass.__extra__ == dict:
            return _deserialize_dict(data, klass.__args__[1])
    else:
        return deserialize_model(data, klass)
991914
def clean_response(response):
    ''''''
    if type(response) is list:
        for elem in response:
            clean_response(elem)
    elif type(response) is dict:
        for key, val in response.items():
            if key == 'self':
                val = response.pop('self')
                response['self_'] = val
                clean_response(val)
            else:
                clean_response(response[key])
    return response
137510
def _handle_response(self, response, data):
        
        # Content-Type headers can include additional parameters(RFC 1521), so
        # we split on ; to match against only the type/subtype
        if data and response.get('content-type', '').split(';')[0] in (
            'application/json', 
            'application/x-javascript',
            'text/javascript',
            'text/x-javascript',
            'text/x-json'
        ):
            return json.loads(data)
        else:
            return data
1283316
def deserialize(cls, target_class, pagination_response):
        

        pagination = client.Pagination()
        pagination.__dict__.update(
            cls.parse_pagination_dict(pagination_response)
        )

        return pagination
1216635
def _deserialize_list(cls, type_item, list_):
        

        list_deserialized = []

        for item in list_:
            item_deserialized = cls.deserialize(type_item, item)
            list_deserialized.append(item_deserialized)

        return list_deserialized
172696
def parse_encrypted_response(self, response):
        
        content_type = response.headers['Content-Type']
        if 'protocol="{0}"'.format(self.protocol_string.decode()) in content_type:
            host = urlsplit(response.request.url).hostname
            msg = self._decrypt_response(response, host)
        else:
            msg = response.text

        return msg
534785
def __deserialize_primitive(self, data, klass):
        
        try:
            return klass(data)
        except UnicodeEncodeError:
            return text(data)
        except TypeError:
            return data
1267415
def to_instance(self, response):
        
        klass = self.schema['title']
        cls = get_model_class(klass, api=self.__api__)
        jdict = json.loads(response.content, encoding="utf-8")
        ### check if we have a response
        properties_dict = jdict[self.schema['title']]
        # @todo: find a way to handle the data
        # validation fails if the none values are not removed
        new_dict = helpers.remove_properties_containing_None(properties_dict)
        #jdict[self.schema['title']] = new_dict
        obj = cls(new_dict)
        #obj.links = jdict[self.schema['title']]['links']
        return obj
890385
def decode_response(response):
    
    def is_compressed(headers):
        encoding = headers.get('content-encoding', [])
        return encoding and encoding[0] in ('gzip', 'deflate')

    def decompress_body(body, encoding):
        """Returns decompressed body according to encoding using zlib.
        to (de-)compress gzip format, use wbits = zlib.MAX_WBITS | 16
        """
        if encoding == 'gzip':
            return zlib.decompress(body, zlib.MAX_WBITS | 16)
        else:  # encoding == 'deflate'
            return zlib.decompress(body)

    # Deepcopy here in case `headers` contain objects that could
    # be mutated by a shallow copy and corrupt the real response.
    response = copy.deepcopy(response)
    headers = CaseInsensitiveDict(response['headers'])
    if is_compressed(headers):
        encoding = headers['content-encoding'][0]
        headers['content-encoding'].remove(encoding)
        if not headers['content-encoding']:
            del headers['content-encoding']

        new_body = decompress_body(response['body']['string'], encoding)
        response['body']['string'] = new_body
        headers['content-length'] = [str(len(new_body))]
        response['headers'] = dict(headers)
    return response
1022695
def deserialize(self):
        

        body = super(Deserializer, self).deserialize()

        self.parse(body)
        return self.normalize(body)
1115515
def clean_response_type(self):
        
        response_type = self.cleaned_data.get('response_type')

        if not response_type:
            raise OAuthValidationError({'error': 'invalid_request',
                'error_description': "No 'response_type' supplied."})

        types = response_type.split(" ")

        for type in types:
            if type not in RESPONSE_TYPE_CHOICES:
                raise OAuthValidationError({
                    'error': 'unsupported_response_type',
                    'error_description': u"'%s' is not a supported response "
                        "type." % type})

        return response_type
910335
@SuppressWarnings("unchecked")
    public <T> T deserialize(String body, Type returnType) {
        try {
            if (isLenientOnJson) {
                JsonReader jsonReader = new JsonReader(new StringReader(body));
                // see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
                jsonReader.setLenient(true);
                return gson.fromJson(jsonReader, returnType);
            } else {
                return gson.fromJson(body, returnType);
            }
        } catch (JsonParseException e) {
            // Fallback processing when failed to parse JSON form response body:
            // return the response body string directly for the String return type;
            if (returnType.equals(String.class))
                return (T) body;
            else
                throw (e);
        }
    }
228354
def process_response(self,
                         method,
                         response,
                         response_type=None,
                         objects_type=None):
        

        try:
            response_json = response.json(
                object_hook=
                lambda x: ResponseObject(x) if isinstance(x, dict) else x)
            if response_type:
                r = response_type(self, response_json.__dict__)
                response_json = r

            if 'objects' in response_json and objects_type:
                response_json.objects = [
                    objects_type(self, obj.__dict__)
                    for obj in response_json.objects
                ]
        except ValueError:
            response_json = None

        if response.status_code == 400:
            if response_json and 'error' in response_json:
                raise ValidationError(response_json.error)
            raise ValidationError(
                'A parameter is missing or is invalid while accessing resource'
                'at: {url}'.format(url=response.url))

        if response.status_code == 401:
            if response_json and 'error' in response_json:
                raise AuthenticationError(response_json.error)
            raise AuthenticationError(
                'Failed to authenticate while accessing resource at: '
                '{url}'.format(url=response.url))

        if response.status_code == 404:
            if response_json and 'error' in response_json:
                raise ResourceNotFoundError(response_json.error)
            raise ResourceNotFoundError(
                'Resource not found at: {url}'.format(url=response.url))

        if response.status_code == 405:
            if response_json and 'error' in response_json:
                raise InvalidRequestError(response_json.error)
            raise InvalidRequestError(
                'HTTP method "{method}" not allowed to access resource at: '
                '{url}'.format(method=method, url=response.url))

        if response.status_code == 500:
            if response_json and 'error' in response_json:
                raise PlivoServerError(response_json.error)
            raise PlivoServerError(
                'A server error occurred while accessing resource at: '
                '{url}'.format(url=response.url))

        if method == 'DELETE':
            if response.status_code != 204:
                raise PlivoRestError('Resource at {url} could not be '
                                     'deleted'.format(url=response.url))

        elif response.status_code not in [200, 201, 202]:
            raise PlivoRestError(
                'Received status code {status_code} for the HTTP method '
                '"{method}"'.format(
                    status_code=response.status_code, method=method))

        return response_json