| 9 | |
| 10 | |
| 11 | class Payload: |
| 12 | def __init__(self, message, response_code=200, headers={}): |
| 13 | self.__response_code = response_code |
| 14 | self.__message = message if type(message) is bytes else message.encode('utf8') |
| 15 | self.__headers = headers |
| 16 | |
| 17 | |
| 18 | def response_code(self): |
| 19 | """ |
| 20 | Response code to send to the client. |
| 21 | """ |
| 22 | return self.__response_code |
| 23 | |
| 24 | |
| 25 | def message(self): |
| 26 | """ |
| 27 | The message to send to the client. |
| 28 | """ |
| 29 | return self.__message |
| 30 | |
| 31 | |
| 32 | def length(self): |
| 33 | """ |
| 34 | The length of the response. |
| 35 | """ |
| 36 | return len(self.message()) |
| 37 | |
| 38 | |
| 39 | def headers(self): |
| 40 | """ |
| 41 | The headers to be sent to the client. Please, note, that these do not include |
| 42 | the Content-Length header, which you need to send separately. |
| 43 | """ |
| 44 | return self.__headers |
| 45 | |
| 46 | |
| 47 | def __repr__(self): |
| 48 | return "{}: {}: {}".format(self.response_code(), self.length(), self.message()) |
| 49 | |
| 50 | |
| 51 | class ResponseProviderMixin: |
no outgoing calls