From 0f50a5381cb5a46a2ccc4c9a23cd986775e58afe Mon Sep 17 00:00:00 2001 From: James Saryerwinnie Date: Mon, 21 Apr 2014 14:48:08 -0700 Subject: [PATCH] Add support for parsing S3 metadata types A special case is required to parsed rest-xml, map types with a location of header. The only place this is used is for S3 metadata types. --- botocore/response.py | 16 +++++++++++++++- .../response_parsing/test_response_parsing.py | 11 ++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/botocore/response.py b/botocore/response.py index 7a75eb00e3..3895d94fb3 100644 --- a/botocore/response.py +++ b/botocore/response.py @@ -328,9 +328,23 @@ def merge_header_values(self, headers): location = member.get('location') if location == 'header': location_name = member.get('location_name') - if location_name in headers: + if member['type'] == 'map': + self._merge_map_header_values(headers, location_name, + member_name, member) + elif location_name in headers: self.value[member_name] = headers[location_name] + def _merge_map_header_values(self, headers, location_name, + member_name, member): + final_map_value = {} + for header_name in headers: + if header_name.startswith(location_name): + header_value = headers[header_name] + actual_name = header_name[len(location_name):] + final_map_value[actual_name] = header_value + if final_map_value: + self.value[member_name] = final_map_value + class JSONResponse(Response): diff --git a/tests/unit/response_parsing/test_response_parsing.py b/tests/unit/response_parsing/test_response_parsing.py index 15b3cb4998..adac8b8e1a 100644 --- a/tests/unit/response_parsing/test_response_parsing.py +++ b/tests/unit/response_parsing/test_response_parsing.py @@ -175,7 +175,9 @@ def test_head_object(self): 'Content-Type': 'binary/octet-stream', 'accept-ranges': 'bytes', 'Last-Modified': 'Tue, 20 Aug 2013 18:33:25 GMT', - 'x-amz-server-side-encryption': 'AES256' + 'x-amz-server-side-encryption': 'AES256', + 'x-amz-meta-mykey1': 'value1', + 'x-amz-meta-mykey2': 'value2', }) http_response.content = '' http_response.request.method = 'HEAD' @@ -185,8 +187,11 @@ def test_head_object(self): "LastModified": "Tue, 20 Aug 2013 18:33:25 GMT", "ContentLength": "265", "ETag": '"40d06eb6194712ac1c915783004ef730"', - "ServerSideEncryption": "AES256" - } + "ServerSideEncryption": "AES256", + "Metadata": { + 'mykey1': 'value1', + 'mykey2': 'value2', + }} response_data = get_response(self.session, put_object, http_response)[1] self.assertEqual(response_data, expected)