33"""
44from __future__ import division
55
6+ import inspect
67import json
78import logging
89import random
1112import uuid
1213from base64 import b64decode
1314from threading import local
15+ from typing import Any , Dict , List , Mapping , Optional , Sequence , cast
1416
1517import six
1618import botocore .client
2224from botocore .session import get_session
2325from six .moves import range
2426
27+ from pynamodb .connection ._botocore_private import BotocoreBaseClientPrivate
2528from pynamodb .connection .util import pythonic
2629from pynamodb .constants import (
2730 RETURN_CONSUMED_CAPACITY_VALUES , RETURN_ITEM_COLL_METRICS_VALUES ,
@@ -247,7 +250,8 @@ def __init__(self, region=None, host=None,
247250 self ._tables = {}
248251 self .host = host
249252 self ._local = local ()
250- self ._client = None
253+ self ._client : Optional [BotocoreBaseClientPrivate ] = None
254+ self ._convert_to_request_dict__endpoint_url = False
251255 if region :
252256 self .region = region
253257 else :
@@ -364,10 +368,28 @@ def _make_api_call(self, operation_name, operation_kwargs):
364368 2. It provides a place to monkey patch HTTP requests for unit testing
365369 """
366370 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+ )
371393
372394 for i in range (0 , self ._max_retry_attempts_exception + 1 ):
373395 attempt_number = i + 1
@@ -518,7 +540,7 @@ def session(self):
518540 return self ._local .session
519541
520542 @property
521- def client (self ):
543+ def client (self ) -> BotocoreBaseClientPrivate :
522544 """
523545 Returns a botocore dynamodb client
524546 """
@@ -531,8 +553,10 @@ def client(self):
531553 parameter_validation = False , # Disable unnecessary validation for performance
532554 connect_timeout = self ._connect_timeout_seconds ,
533555 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
536560 return self ._client
537561
538562 def get_meta_table (self , table_name , refresh = False ):
0 commit comments