18
18
import re
19
19
from typing import (
20
20
Dict ,
21
+ Callable ,
21
22
Mapping ,
22
23
MutableMapping ,
23
24
MutableSequence ,
37
38
from google .auth import credentials as ga_credentials # type: ignore
38
39
from google .oauth2 import service_account # type: ignore
39
40
41
+
40
42
try :
41
43
OptionalRetry = Union [retries .AsyncRetry , gapic_v1 .method ._MethodDefault , None ]
42
44
except AttributeError : # pragma: NO COVER
@@ -250,7 +252,9 @@ def __init__(
250
252
self ,
251
253
* ,
252
254
credentials : Optional [ga_credentials .Credentials ] = None ,
253
- transport : Union [str , DatastoreAdminTransport ] = "grpc_asyncio" ,
255
+ transport : Optional [
256
+ Union [str , DatastoreAdminTransport , Callable [..., DatastoreAdminTransport ]]
257
+ ] = "grpc_asyncio" ,
254
258
client_options : Optional [ClientOptions ] = None ,
255
259
client_info : gapic_v1 .client_info .ClientInfo = DEFAULT_CLIENT_INFO ,
256
260
) -> None :
@@ -262,9 +266,11 @@ def __init__(
262
266
credentials identify the application to the service; if none
263
267
are specified, the client will attempt to ascertain the
264
268
credentials from the environment.
265
- transport (Union[str, ~.DatastoreAdminTransport]): The
266
- transport to use. If set to None, a transport is chosen
267
- automatically.
269
+ transport (Optional[Union[str,DatastoreAdminTransport,Callable[..., DatastoreAdminTransport]]]):
270
+ The transport to use, or a Callable that constructs and returns a new transport to use.
271
+ If a Callable is given, it will be called with the same set of initialization
272
+ arguments as used in the DatastoreAdminTransport constructor.
273
+ If set to None, a transport is chosen automatically.
268
274
client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
269
275
Custom options for the client.
270
276
@@ -429,8 +435,8 @@ async def sample_export_entities():
429
435
430
436
"""
431
437
# Create or coerce a protobuf request object.
432
- # Quick check: If we got a request object, we should *not* have
433
- # gotten any keyword arguments that map to the request.
438
+ # - Quick check: If we got a request object, we should *not* have
439
+ # gotten any keyword arguments that map to the request.
434
440
has_flattened_params = any (
435
441
[project_id , labels , entity_filter , output_url_prefix ]
436
442
)
@@ -440,7 +446,10 @@ async def sample_export_entities():
440
446
"the individual field arguments should be set."
441
447
)
442
448
443
- request = datastore_admin .ExportEntitiesRequest (request )
449
+ # - Use the request object if provided (there's no risk of modifying the input as
450
+ # there are no flattened fields), or create one.
451
+ if not isinstance (request , datastore_admin .ExportEntitiesRequest ):
452
+ request = datastore_admin .ExportEntitiesRequest (request )
444
453
445
454
# If we have keyword arguments corresponding to fields on the
446
455
# request, apply these.
@@ -456,11 +465,9 @@ async def sample_export_entities():
456
465
457
466
# Wrap the RPC method; this adds retry and timeout information,
458
467
# and friendly error handling.
459
- rpc = gapic_v1 .method_async .wrap_method (
460
- self ._client ._transport .export_entities ,
461
- default_timeout = 60.0 ,
462
- client_info = DEFAULT_CLIENT_INFO ,
463
- )
468
+ rpc = self ._client ._transport ._wrapped_methods [
469
+ self ._client ._transport .export_entities
470
+ ]
464
471
465
472
# Certain fields should be provided within the metadata header;
466
473
# add these here.
@@ -613,16 +620,19 @@ async def sample_import_entities():
613
620
614
621
"""
615
622
# Create or coerce a protobuf request object.
616
- # Quick check: If we got a request object, we should *not* have
617
- # gotten any keyword arguments that map to the request.
623
+ # - Quick check: If we got a request object, we should *not* have
624
+ # gotten any keyword arguments that map to the request.
618
625
has_flattened_params = any ([project_id , labels , input_url , entity_filter ])
619
626
if request is not None and has_flattened_params :
620
627
raise ValueError (
621
628
"If the `request` argument is set, then none of "
622
629
"the individual field arguments should be set."
623
630
)
624
631
625
- request = datastore_admin .ImportEntitiesRequest (request )
632
+ # - Use the request object if provided (there's no risk of modifying the input as
633
+ # there are no flattened fields), or create one.
634
+ if not isinstance (request , datastore_admin .ImportEntitiesRequest ):
635
+ request = datastore_admin .ImportEntitiesRequest (request )
626
636
627
637
# If we have keyword arguments corresponding to fields on the
628
638
# request, apply these.
@@ -638,11 +648,9 @@ async def sample_import_entities():
638
648
639
649
# Wrap the RPC method; this adds retry and timeout information,
640
650
# and friendly error handling.
641
- rpc = gapic_v1 .method_async .wrap_method (
642
- self ._client ._transport .import_entities ,
643
- default_timeout = 60.0 ,
644
- client_info = DEFAULT_CLIENT_INFO ,
645
- )
651
+ rpc = self ._client ._transport ._wrapped_methods [
652
+ self ._client ._transport .import_entities
653
+ ]
646
654
647
655
# Certain fields should be provided within the metadata header;
648
656
# add these here.
@@ -747,15 +755,16 @@ async def sample_create_index():
747
755
748
756
"""
749
757
# Create or coerce a protobuf request object.
750
- request = datastore_admin .CreateIndexRequest (request )
758
+ # - Use the request object if provided (there's no risk of modifying the input as
759
+ # there are no flattened fields), or create one.
760
+ if not isinstance (request , datastore_admin .CreateIndexRequest ):
761
+ request = datastore_admin .CreateIndexRequest (request )
751
762
752
763
# Wrap the RPC method; this adds retry and timeout information,
753
764
# and friendly error handling.
754
- rpc = gapic_v1 .method_async .wrap_method (
755
- self ._client ._transport .create_index ,
756
- default_timeout = 60.0 ,
757
- client_info = DEFAULT_CLIENT_INFO ,
758
- )
765
+ rpc = self ._client ._transport ._wrapped_methods [
766
+ self ._client ._transport .create_index
767
+ ]
759
768
760
769
# Certain fields should be provided within the metadata header;
761
770
# add these here.
@@ -859,15 +868,16 @@ async def sample_delete_index():
859
868
860
869
"""
861
870
# Create or coerce a protobuf request object.
862
- request = datastore_admin .DeleteIndexRequest (request )
871
+ # - Use the request object if provided (there's no risk of modifying the input as
872
+ # there are no flattened fields), or create one.
873
+ if not isinstance (request , datastore_admin .DeleteIndexRequest ):
874
+ request = datastore_admin .DeleteIndexRequest (request )
863
875
864
876
# Wrap the RPC method; this adds retry and timeout information,
865
877
# and friendly error handling.
866
- rpc = gapic_v1 .method_async .wrap_method (
867
- self ._client ._transport .delete_index ,
868
- default_timeout = 60.0 ,
869
- client_info = DEFAULT_CLIENT_INFO ,
870
- )
878
+ rpc = self ._client ._transport ._wrapped_methods [
879
+ self ._client ._transport .delete_index
880
+ ]
871
881
872
882
# Certain fields should be provided within the metadata header;
873
883
# add these here.
@@ -952,25 +962,16 @@ async def sample_get_index():
952
962
Datastore composite index definition.
953
963
"""
954
964
# Create or coerce a protobuf request object.
955
- request = datastore_admin .GetIndexRequest (request )
965
+ # - Use the request object if provided (there's no risk of modifying the input as
966
+ # there are no flattened fields), or create one.
967
+ if not isinstance (request , datastore_admin .GetIndexRequest ):
968
+ request = datastore_admin .GetIndexRequest (request )
956
969
957
970
# Wrap the RPC method; this adds retry and timeout information,
958
971
# and friendly error handling.
959
- rpc = gapic_v1 .method_async .wrap_method (
960
- self ._client ._transport .get_index ,
961
- default_retry = retries .AsyncRetry (
962
- initial = 0.1 ,
963
- maximum = 60.0 ,
964
- multiplier = 1.3 ,
965
- predicate = retries .if_exception_type (
966
- core_exceptions .DeadlineExceeded ,
967
- core_exceptions .ServiceUnavailable ,
968
- ),
969
- deadline = 60.0 ,
970
- ),
971
- default_timeout = 60.0 ,
972
- client_info = DEFAULT_CLIENT_INFO ,
973
- )
972
+ rpc = self ._client ._transport ._wrapped_methods [
973
+ self ._client ._transport .get_index
974
+ ]
974
975
975
976
# Certain fields should be provided within the metadata header;
976
977
# add these here.
@@ -1056,25 +1057,16 @@ async def sample_list_indexes():
1056
1057
1057
1058
"""
1058
1059
# Create or coerce a protobuf request object.
1059
- request = datastore_admin .ListIndexesRequest (request )
1060
+ # - Use the request object if provided (there's no risk of modifying the input as
1061
+ # there are no flattened fields), or create one.
1062
+ if not isinstance (request , datastore_admin .ListIndexesRequest ):
1063
+ request = datastore_admin .ListIndexesRequest (request )
1060
1064
1061
1065
# Wrap the RPC method; this adds retry and timeout information,
1062
1066
# and friendly error handling.
1063
- rpc = gapic_v1 .method_async .wrap_method (
1064
- self ._client ._transport .list_indexes ,
1065
- default_retry = retries .AsyncRetry (
1066
- initial = 0.1 ,
1067
- maximum = 60.0 ,
1068
- multiplier = 1.3 ,
1069
- predicate = retries .if_exception_type (
1070
- core_exceptions .DeadlineExceeded ,
1071
- core_exceptions .ServiceUnavailable ,
1072
- ),
1073
- deadline = 60.0 ,
1074
- ),
1075
- default_timeout = 60.0 ,
1076
- client_info = DEFAULT_CLIENT_INFO ,
1077
- )
1067
+ rpc = self ._client ._transport ._wrapped_methods [
1068
+ self ._client ._transport .list_indexes
10000
1069
+ ]
1078
1070
1079
1071
# Certain fields should be provided within the metadata header;
1080
1072
# add these here.
0 commit comments