def escape_xml_payload(params, **kwargs): # Replace \r and \n with the escaped sequence over the whole XML document # to avoid linebreak normalization modifying customer input when the # document is parsed. Ideally, we would do this in ElementTree.tostring, # but it doesn't allow us to override entity escaping for text fields. For # this operation \r and \n can only appear in the XML document if they were # passed as part of the customer input. body = params['body'] replaced = False if b'\r' in body: replaced = True body = body.replace(b'\r', b'
') if b'\n' in body: replaced = True body = body.replace(b'\n', b'
') if not replaced: return params['body'] = body if 'Content-MD5' in params['headers']: # The Content-MD5 is now wrong, so we'll need to recalculate it del params['headers']['Content-MD5'] conditionally_calculate_md5(params, **kwargs)
def _prepare_additional_traits(self, request, operation_model): """Determine if additional traits are required for given model""" if operation_model.http_checksum_required: conditionally_calculate_md5(request) return request
def _prepare_additional_traits_in_response( self, response: HttpResponse, operation_model: OperationModel): """Applies additional traits on the raw response for a given model or protocol.""" if operation_model.http_checksum_required: conditionally_calculate_md5(response) return response