3
3
"""
4
4
from __future__ import division
5
5
6
+ import inspect
6
7
import json
7
8
import logging
8
9
import random
11
12
import uuid
12
13
from base64 import b64decode
13
14
from threading import local
15
+ from typing import Any , Dict , List , Mapping , Optional , Sequence , cast
14
16
15
17
import six
16
18
import botocore .client
22
24
from botocore .session import get_session
23
25
from six .moves import range
24
26
27
+ from pynamodb .connection ._botocore_private import BotocoreBaseClientPrivate
25
28
from pynamodb .connection .util import pythonic
26
29
from pynamodb .constants import (
27
30
RETURN_CONSUMED_CAPACITY_VALUES , RETURN_ITEM_COLL_METRICS_VALUES ,
@@ -247,7 +250,8 @@ def __init__(self, region=None, host=None,
247
250
self ._tables = {}
248
251
self .host = host
249
252
self ._local = local ()
250
- self ._client = None
253
+ self ._client : Optional [BotocoreBaseClientPrivate ] = None
254
+ self ._convert_to_request_dict__endpoint_url = False
251
255
if region :
252
256
self .region = region
253
257
else :
@@ -364,10 +368,28 @@ def _make_api_call(self, operation_name, operation_kwargs):
364
368
2. It provides a place to monkey patch HTTP requests for unit testing
365
369
"""
366
370
operation_model = self .client ._service_model .operation_model (operation_name )
367
- request_dict = self .client ._convert_to_request_dict (
368
- operation_kwargs ,
369
- operation_model ,
370
- )
371
+ if self ._convert_to_request_dict__endpoint_url :
372
+ request_context = {
373
+ 'client_region' : self .region ,
374
+ 'client_config' : self .client .meta .config ,
375
+ 'has_streaming_input' : operation_model .has_streaming_input ,
376
+ 'auth_type' : operation_model .auth_type ,
377
+ }
378
+ endpoint_url , additional_headers = self .client ._resolve_endpoint_ruleset (
379
+ operation_model , operation_kwargs , request_context
380
+ )
381
+ request_dict = self .client ._convert_to_request_dict (
382
+ api_params = operation_kwargs ,
383
+ operation_model = operation_model ,
384
+ endpoint_url = endpoint_url ,
385
+ context = request_context ,
386
+ headers = additional_headers ,
387
+ )
388
+ else :
389
+ request_dict = self .client ._convert_to_request_dict (
390
+ operation_kwargs ,
391
+ operation_model ,
392
+ )
371
393
372
394
for i in range (0 , self ._max_retry_attempts_exception + 1 ):
373
395
attempt_number = i + 1
@@ -518,7 +540,7 @@ def session(self):
518
540
return self ._local .session
519
541
520
542
@property
521
- def client (self ):
543
+ def client (self ) -> BotocoreBaseClientPrivate :
522
544
"""
523
545
Returns a botocore dynamodb client
524
546
"""
@@ -531,8 +553,10 @@ def client(self):
531
553
parameter_validation = False , # Disable unnecessary validation for performance
532
554
connect_timeout = self ._connect_timeout_seconds ,
533
555
read_timeout = self ._read_timeout_seconds ,
534
- max_pool_connections = self ._max_pool_connections )
535
- self ._client = self .session .create_client (SERVICE_NAME , self .region , endpoint_url = self .host , config = config )
556
+ max_pool_connections = self ._max_pool_connections ,
557
+ )
558
+ self ._client = cast (BotocoreBaseClientPrivate , self .session .create_client (SERVICE_NAME , self .region , endpoint_url = self .host , config = config ))
559
+ self ._convert_to_request_dict__endpoint_url = 'endpoint_url' in inspect .signature (self ._client ._convert_to_request_dict ).parameters
536
560
return self ._client
537
561
538
562
def get_meta_table (self , table_name , refresh = False ):
0 commit comments