def _get_raw_parts(self, http_response_type=None): # type (Optional[Type[_HttpResponseBase]]) -> Iterator[HttpResponse] """Assuming this body is multipart, return the iterator or parts. If parts are application/http use http_response_type or HttpClientTransportResponse as enveloppe. """ if http_response_type is None: http_response_type = HttpClientTransportResponse body_as_bytes = self.body() # In order to use email.message parser, I need full HTTP bytes. Faking something to make the parser happy http_body = (b"Content-Type: " + self.content_type.encode("ascii") + b"\r\n\r\n" + body_as_bytes) message = message_parser(http_body) # type: Message # Rebuild an HTTP response from pure string requests = self.request.multipart_mixed_info[ 0] # type: List[HttpRequest] responses = [] for request, raw_reponse in zip(requests, message.get_payload()): if raw_reponse.get_content_type() == "application/http": responses.append( _deserialize_response( raw_reponse.get_payload(decode=True), request, http_response_type=http_response_type, )) else: raise ValueError( "Multipart doesn't support part other than application/http for now" ) return responses
def _get_raw_parts_helper(response, http_response_type): """Helper for _get_raw_parts Assuming this body is multipart, return the iterator or parts. If parts are application/http use http_response_type or HttpClientTransportResponse as enveloppe. """ body_as_bytes = response.body() # In order to use email.message parser, I need full HTTP bytes. Faking something to make the parser happy http_body = (b"Content-Type: " + response.content_type.encode("ascii") + b"\r\n\r\n" + body_as_bytes) message = message_parser(http_body) # type: Message requests = response.request.multipart_mixed_info[0] return response._decode_parts(message, http_response_type, requests) # pylint: disable=protected-access
def _get_raw_parts(self, http_response_type=None): # type (Optional[Type[_HttpResponseBase]]) -> Iterator[HttpResponse] """Assuming this body is multipart, return the iterator or parts. If parts are application/http use http_response_type or HttpClientTransportResponse as enveloppe. """ if http_response_type is None: http_response_type = HttpClientTransportResponse body_as_bytes = self.body() # In order to use email.message parser, I need full HTTP bytes. Faking something to make the parser happy http_body = (b"Content-Type: " + self.content_type.encode("ascii") + b"\r\n\r\n" + body_as_bytes) message = message_parser(http_body) # type: Message requests = self.request.multipart_mixed_info[ 0] # type: List[HttpRequest] return self._decode_parts(message, http_response_type, requests)