Skip to content

Commit ccca363

Browse files
committed
more work
1 parent 21cb2d8 commit ccca363

3 files changed

Lines changed: 57 additions & 4 deletions

File tree

botocore/model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def __init__(self, shape_name, shape_model, shape_resolver=None):
121121
"""
122122
self.name = shape_name
123123
self.type_name = shape_model['type']
124+
self.boxed = shape_model.get('box', False)
124125
self.documentation = shape_model.get('documentation', '')
125126
self._shape_model = shape_model
126127
if shape_resolver is None:

botocore/parsers.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ class ResponseParserError(Exception):
194194
pass
195195

196196

197+
def box_decorator(func):
198+
def handle_box(self, shape, value):
199+
if shape.boxed and value is None:
200+
return None
201+
return func(self, shape, value)
202+
203+
return handle_box
204+
205+
197206
class ResponseParser:
198207
"""Base class for response parsing.
199208
@@ -340,10 +349,18 @@ def _do_modeled_error_parse(self, response, shape, parsed):
340349
f"{self.__class__.__name__}._do_modeled_error_parse"
341350
)
342351

352+
BOXABLE_PRIMITIVE_TYPES = ["long", "integer", "boolean"]
353+
343354
def _parse_shape(self, shape, node):
344355
handler = getattr(
345356
self, f'_handle_{shape.type_name}', self._default_handle
346357
)
358+
if (
359+
shape.type_name in self.BOXABLE_PRIMITIVE_TYPES
360+
and shape.boxed
361+
and node is None
362+
):
363+
return None
347364
return handler(shape, node)
348365

349366
def _handle_list(self, shape, node):
@@ -1331,10 +1348,7 @@ def _handle_boolean(self, shape, value):
13311348
return ensure_boolean(value)
13321349

13331350
def _handle_integer(self, shape, value):
1334-
if value is None:
1335-
return None
1336-
else:
1337-
return int(value)
1351+
return int(value)
13381352

13391353
def _handle_float(self, shape, value):
13401354
return float(value)

main_botocore.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import boto3
2+
3+
boto3.set_stream_logger('')
4+
5+
6+
rds_client = boto3.client('rds-data')
7+
8+
sql = '''
9+
select array[123::int4, null::int4, 456::int4];
10+
'''
11+
12+
recs = rds_client.execute_statement(
13+
secretArn='arn:aws:secretsmanager:us-east-1:135633386280:secret:rds!cluster-9237ce19-931d-48a6-9130-c1f7e4930a27-ZLZKOT',
14+
resourceArn='arn:aws:rds:us-east-1:135633386280:cluster:data-api-test',
15+
database='postgres',
16+
sql=sql,
17+
)
18+
19+
print(f'{recs}')
20+
21+
22+
# TODO: Working below for comparison
23+
24+
# import boto3
25+
# boto3.set_stream_logger('')
26+
#
27+
# rds_client = boto3.client('rds-data')
28+
#
29+
# sql = 'select array[123::int4, 789::int4, 456::int4];'
30+
#
31+
# recs = rds_client.execute_statement(
32+
# secretArn = 'arn:aws:secretsmanager:us-east-1:135633386280:secret:rds!cluster-9237ce19-931d-48a6-9130-c1f7e4930a27-ZLZKOT',
33+
# resourceArn = 'arn:aws:rds:us-east-1:135633386280:cluster:data-api-test',
34+
# database = 'postgres',
35+
# sql = sql
36+
# )
37+
#
38+
# print(f'{recs}')

0 commit comments

Comments
 (0)