Skip to content

Commit

Permalink
Partially address PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan343 committed Aug 16, 2024
1 parent 7db1cf3 commit 752465c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
25 changes: 11 additions & 14 deletions botocore/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
from botocore.compat import ETree, XMLParseError
from botocore.eventstream import EventStream, NoInitialResponseError
from botocore.utils import (
ensure_boolean,
is_json_value_header,
lowercase_dict,
merge_dicts,
Expand Down Expand Up @@ -204,7 +205,7 @@ class ResponseParser:
# This is a list of known values for the "location" key in the
# serialization dict. The location key tells us where in the response
# to parse the value.
KNOWN_LOCATIONS = ['statusCode', 'header', 'headers']
KNOWN_LOCATIONS = ('statusCode', 'header', 'headers')

def __init__(self, timestamp_parser=None, blob_parser=None):
if timestamp_parser is None:
Expand Down Expand Up @@ -437,11 +438,10 @@ def _handle_structure(self, shape, node):
member_shape = members[member_name]
location = member_shape.serialization.get('location')
if (
location
and location in self.KNOWN_LOCATIONS
location in self.KNOWN_LOCATIONS
or member_shape.serialization.get('eventheader')
):
# All members with know locations have already been handled,
# All members with known locations have already been handled,
# so we don't need to parse these members.
continue
xml_name = self._member_key_name(member_shape, member_name)
Expand Down Expand Up @@ -551,6 +551,8 @@ def _handle_blob(self, shape, text):


class QueryParser(BaseXMLResponseParser):
ROOT_NODE_SUFFIX = 'Result'

def _do_error_parse(self, response, shape):
xml_contents = response['body']
root = self._parse_xml_string_to_dom(xml_contents)
Expand Down Expand Up @@ -589,9 +591,8 @@ def _parse_body_as_xml(self, response, shape, inject_metadata=True):
operation_name = response.get("context", {}).get(
"operation_name", ""
)
inferred_wrapper_name = operation_name + "Result"
inferred_wrapper = self._find_result_wrapped_shape(
inferred_wrapper_name, root
f"{operation_name}{self.ROOT_NODE_SUFFIX}", root
)
if inferred_wrapper is not None:
start = inferred_wrapper
Expand All @@ -615,6 +616,8 @@ def _inject_response_metadata(self, node, inject_into):


class EC2QueryParser(QueryParser):
ROOT_NODE_SUFFIX = 'Response'

def _inject_response_metadata(self, node, inject_into):
mapping = self._build_name_to_xml_node(node)
child_node = mapping.get('requestId')
Expand Down Expand Up @@ -979,7 +982,7 @@ def _parse_non_payload_attrs(
for name in member_shapes:
member_shape = member_shapes[name]
location = member_shape.serialization.get('location')
if location is None or location not in self.KNOWN_LOCATIONS:
if location is None:
continue
elif location == 'statusCode':
final_parsed[name] = self._parse_shape(
Expand Down Expand Up @@ -1052,13 +1055,7 @@ def _initial_body_parse(self, body_contents):
return self._parse_body_as_json(body_contents)

def _handle_boolean(self, shape, value):
# It's possible to receive a boolean as a string
if isinstance(value, str):
if value == 'true':
return True
else:
return False
return value
return ensure_boolean(value)

def _handle_integer(self, shape, value):
return int(value)
Expand Down
5 changes: 4 additions & 1 deletion botocore/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,10 @@ def _serialize_payload(
body_params, shape_members[payload_member]
)
else:
serialized['body'] = self._serialize_empty_body()
if shape_members[payload_member].is_tagged_union:
serialized['body'] = b''
else:
serialized['body'] = self._serialize_empty_body()
elif partitioned['body_kwargs']:
serialized['body'] = self._serialize_body_params(
partitioned['body_kwargs'], shape
Expand Down
11 changes: 4 additions & 7 deletions tests/unit/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"""

import copy
import math
import os
import xml.etree.ElementTree as ET
from base64 import b64decode
Expand Down Expand Up @@ -99,12 +98,12 @@
'rest-json': RestJSONParser,
'rest-xml': RestXMLParser,
}
PROTOCOL_TEST_BLACKLIST = [
PROTOCOL_TEST_BLOCKLIST = (
# These cases test functionality outside the serializers and parsers.
"Test cases for QueryIdempotencyTokenAutoFill operation",
"Test cases for PutWithContentEncoding operation",
"Test cases for HttpChecksumRequired operation",
]
)


class TestType(Enum):
Expand All @@ -122,7 +121,7 @@ def _compliance_tests(test_type=None):
for full_path in _walk_files():
if full_path.endswith('.json'):
for model, case, basename in _load_cases(full_path):
if model.get('description') in PROTOCOL_TEST_BLACKLIST:
if model.get('description') in PROTOCOL_TEST_BLOCKLIST:
continue
if 'params' in case and inp:
yield model, case, basename
Expand Down Expand Up @@ -324,9 +323,7 @@ def _convert_bytes_to_str(parsed):

def _special_floats_to_str(value):
if isinstance(value, float):
if value in [float('Infinity'), float('-Infinity')] or math.isnan(
value
):
if value in [float('Infinity'), float('-Infinity')] or value != value:
return json.dumps(value)
return value

Expand Down

0 comments on commit 752465c

Please sign in to comment.