Best Python code snippet using localstack_python
serializer.py
Source:serializer.py
...546 shape_members: dict,547 operation_model: OperationModel,548 ) -> None:549 header_params, payload_params = self._partition_members(parameters, shape)550 self._process_header_members(header_params, response, shape)551 # "HEAD" responeses are basically "GET" responses without the actual body.552 # Do not process the body payload in this case (setting a body could also manipulate the headers)553 if operation_model.http.get("method") != "HEAD":554 self._serialize_payload(payload_params, response, shape, shape_members, operation_model)555 self._serialize_content_type(response, shape, shape_members)556 self._prepare_additional_traits_in_response(response, operation_model)557 def _serialize_payload(558 self,559 parameters: dict,560 response: HttpResponse,561 shape: Optional[Shape],562 shape_members: dict,563 operation_model: OperationModel,564 ) -> None:565 """566 Serializes the given payload.567 :param parameters: The user input params568 :param response: The final serialized HttpResponse569 :param shape: Describes the expected output shape (can be None in case of an "empty" response)570 :param shape_members: The members of the output struct shape571 :param operation_model: The specification of the operation of which the response is serialized here572 :return: None - the given `serialized` dict is modified573 """574 if shape is None:575 return576 payload_member = shape.serialization.get("payload")577 if payload_member is not None and shape_members[payload_member].type_name in [578 "blob",579 "string",580 ]:581 # If it's streaming, then the body is just the value of the payload.582 body_payload = parameters.get(payload_member, b"")583 body_payload = self._encode_payload(body_payload)584 response.data = body_payload585 elif payload_member is not None:586 # If there's a payload member, we serialized that member to the body.587 body_params = parameters.get(payload_member)588 if body_params is not None:589 response.data = self._encode_payload(590 self._serialize_body_params(591 body_params, shape_members[payload_member], operation_model592 )593 )594 else:595 # Otherwise, we use the "traditional" way of serializing the whole parameters dict recursively.596 response.data = self._encode_payload(597 self._serialize_body_params(parameters, shape, operation_model)598 )599 def _serialize_content_type(self, serialized: HttpResponse, shape: Shape, shape_members: dict):600 """601 Some protocols require varied Content-Type headers602 depending on user input. This allows subclasses to apply603 this conditionally.604 """605 pass606 def _has_streaming_payload(self, payload: Optional[str], shape_members):607 """Determine if payload is streaming (a blob or string)."""608 return payload is not None and shape_members[payload].type_name in ["blob", "string"]609 def _prepare_additional_traits_in_response(610 self, response: HttpResponse, operation_model: OperationModel611 ):612 """Adds the request ID to the headers (in contrast to the body - as in the Query protocol)."""613 response = super()._prepare_additional_traits_in_response(response, operation_model)614 response.headers["x-amz-request-id"] = gen_amzn_requestid_long()615 return response616 def _process_header_members(self, parameters: dict, response: HttpResponse, shape: Shape):617 shape_members = shape.members if isinstance(shape, StructureShape) else []618 for name in shape_members:619 member_shape = shape_members[name]620 location = member_shape.serialization.get("location")621 if not location:622 continue623 if name not in parameters:624 # ignores optional keys625 continue626 key = member_shape.serialization.get("name", name)627 value = parameters[name]628 if value is None:629 continue630 if location == "header":...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!