Exemple #1
0
    def process_response(self, response: BaseResponse):
        if self._headers_included and isinstance(response, SerializableMixin):
            self._stream.write(response.to_bytes())

        if not self._stream.readable():
            response.body = MuxBody(self._stream)
        else:
            response.body = Body(self._stream)

        return response
Exemple #2
0
    def open_file(cls, filename: str, response: BaseResponse, mode='wb+'):
        '''Open a file object on to the Response Body.

        Args:
            filename: The path where the file is to be saved
            response: Response
            mode: The file mode

        This function will create the directories if not exist.
        '''
        _logger.debug('Saving file to {0}, mode={1}.',
                      filename, mode)

        dir_path = os.path.dirname(filename)
        if dir_path and not os.path.exists(dir_path):
            os.makedirs(dir_path)

        response.body = Body(open(filename, mode))