Exemplo n.º 1
0
    def decorator(*a, **b):
        result = func(*a, **b)
        response = result
        classz = None

        if isinstance(result, tuple):
            response = result[0]
            classz = result[1]

        content = response.content
        successful_call = response.ok

        if successful_call:
            if classz is not None:
                return json.loads(
                    content.decode('utf-8'),
                    object_hook=lambda d: classz(**d)
                    if '__type__' not in d else CustomDecoder.custom_hook(d))
            return json.loads(content.decode('utf-8'), cls=CustomDecoder)

        decoded_dict = json.loads(content.decode('utf-8'))
        try:
            error_message = decoded_dict['message']
        except KeyError:
            error_message = response.text
        raise ClientException(error_message, response.status_code)
Exemplo n.º 2
0
 def update(self, kwargs):
     # type: ({}) -> None
     """
     This method is setting object fields starting from a dictionary
     :param kwargs: fields dictionary (rest server response)
     """
     for key, value in kwargs.items():
         kwargs[key] = CustomDecoder.custom_hook(value)
     self.__dict__.update(kwargs)