Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/botocore/__init__.py: 54%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright (c) 2012-2013 Mitch Garnaat http://garnaat.org/
2# Copyright 2012-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"). You
5# may not use this file except in compliance with the License. A copy of
6# the License is located at
7#
8# http://aws.amazon.com/apache2.0/
9#
10# or in the "license" file accompanying this file. This file is
11# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12# ANY KIND, either express or implied. See the License for the specific
13# language governing permissions and limitations under the License.
15import logging
16import os
17import re
18from logging import NullHandler
20__version__ = '1.43.89'
23# Configure default logger to do nothing
24log = logging.getLogger('botocore')
25log.addHandler(NullHandler())
27_INITIALIZERS = []
29_first_cap_regex = re.compile('(.)([A-Z][a-z]+)')
30_end_cap_regex = re.compile('([a-z0-9])([A-Z])')
31# The regex below handles the special case where some acronym
32# name is pluralized, e.g GatewayARNs, ListWebACLs, SomeCNAMEs.
33_special_case_transform = re.compile('[A-Z]{2,}s$')
34# Prepopulate the cache with special cases that don't match
35# our regular transformation.
36_xform_cache = {
37 ('CreateCachediSCSIVolume', '_'): 'create_cached_iscsi_volume',
38 ('CreateCachediSCSIVolume', '-'): 'create-cached-iscsi-volume',
39 ('DescribeCachediSCSIVolumes', '_'): 'describe_cached_iscsi_volumes',
40 ('DescribeCachediSCSIVolumes', '-'): 'describe-cached-iscsi-volumes',
41 ('DescribeStorediSCSIVolumes', '_'): 'describe_stored_iscsi_volumes',
42 ('DescribeStorediSCSIVolumes', '-'): 'describe-stored-iscsi-volumes',
43 ('CreateStorediSCSIVolume', '_'): 'create_stored_iscsi_volume',
44 ('CreateStorediSCSIVolume', '-'): 'create-stored-iscsi-volume',
45 ('ListHITsForQualificationType', '_'): 'list_hits_for_qualification_type',
46 ('ListHITsForQualificationType', '-'): 'list-hits-for-qualification-type',
47 ('ExecutePartiQLStatement', '_'): 'execute_partiql_statement',
48 ('ExecutePartiQLStatement', '-'): 'execute-partiql-statement',
49 ('ExecutePartiQLTransaction', '_'): 'execute_partiql_transaction',
50 ('ExecutePartiQLTransaction', '-'): 'execute-partiql-transaction',
51 ('ExecutePartiQLBatch', '_'): 'execute_partiql_batch',
52 ('ExecutePartiQLBatch', '-'): 'execute-partiql-batch',
53 ('CreateOAuth2Token', '_'): 'create_oauth2_token',
54 ('CreateOAuth2Token', '-'): 'create-oauth2-token',
55 ('CreateOAuth2TokenWithIAM', '_'): 'create_oauth2_token_with_iam',
56 ('CreateOAuth2TokenWithIAM', '-'): 'create-oauth2-token-with-iam',
57 (
58 'IntrospectOAuth2TokenWithIAM',
59 '_',
60 ): 'introspect_oauth2_token_with_iam',
61 (
62 'IntrospectOAuth2TokenWithIAM',
63 '-',
64 ): 'introspect-oauth2-token-with-iam',
65 ('RevokeOAuth2TokenWithIAM', '_'): 'revoke_oauth2_token_with_iam',
66 ('RevokeOAuth2TokenWithIAM', '-'): 'revoke-oauth2-token-with-iam',
67 (
68 'AssociateWhatsAppBusinessAccount',
69 '_',
70 ): 'associate_whatsapp_business_account',
71 (
72 'AssociateWhatsAppBusinessAccount',
73 '-',
74 ): 'associate-whatsapp-business-account',
75 ('CreateWhatsAppDataset', '_'): 'create_whatsapp_dataset',
76 ('CreateWhatsAppDataset', '-'): 'create-whatsapp-dataset',
77 ('CreateWhatsAppFlow', '_'): 'create_whatsapp_flow',
78 ('CreateWhatsAppFlow', '-'): 'create-whatsapp-flow',
79 ('CreateWhatsAppMessageTemplate', '_'): 'create_whatsapp_message_template',
80 ('CreateWhatsAppMessageTemplate', '-'): 'create-whatsapp-message-template',
81 (
82 'CreateWhatsAppMessageTemplateFromLibrary',
83 '_',
84 ): 'create_whatsapp_message_template_from_library',
85 (
86 'CreateWhatsAppMessageTemplateFromLibrary',
87 '-',
88 ): 'create-whatsapp-message-template-from-library',
89 (
90 'CreateWhatsAppMessageTemplateMedia',
91 '_',
92 ): 'create_whatsapp_message_template_media',
93 (
94 'CreateWhatsAppMessageTemplateMedia',
95 '-',
96 ): 'create-whatsapp-message-template-media',
97 ('DeleteWhatsAppFlow', '_'): 'delete_whatsapp_flow',
98 ('DeleteWhatsAppFlow', '-'): 'delete-whatsapp-flow',
99 ('DeleteWhatsAppMessageMedia', '_'): 'delete_whatsapp_message_media',
100 ('DeleteWhatsAppMessageMedia', '-'): 'delete-whatsapp-message-media',
101 ('DeleteWhatsAppMessageTemplate', '_'): 'delete_whatsapp_message_template',
102 ('DeleteWhatsAppMessageTemplate', '-'): 'delete-whatsapp-message-template',
103 ('DeprecateWhatsAppFlow', '_'): 'deprecate_whatsapp_flow',
104 ('DeprecateWhatsAppFlow', '-'): 'deprecate-whatsapp-flow',
105 (
106 'DisassociateWhatsAppBusinessAccount',
107 '_',
108 ): 'disassociate_whatsapp_business_account',
109 (
110 'DisassociateWhatsAppBusinessAccount',
111 '-',
112 ): 'disassociate-whatsapp-business-account',
113 (
114 'GetLinkedWhatsAppBusinessAccount',
115 '_',
116 ): 'get_linked_whatsapp_business_account',
117 (
118 'GetLinkedWhatsAppBusinessAccount',
119 '-',
120 ): 'get-linked-whatsapp-business-account',
121 (
122 'GetLinkedWhatsAppBusinessAccountPhoneNumber',
123 '_',
124 ): 'get_linked_whatsapp_business_account_phone_number',
125 (
126 'GetLinkedWhatsAppBusinessAccountPhoneNumber',
127 '-',
128 ): 'get-linked-whatsapp-business-account-phone-number',
129 ('GetOTelEnrichment', '_'): 'get_otel_enrichment',
130 ('GetOTelEnrichment', '-'): 'get-otel-enrichment',
131 ('GetWhatsAppBusinessPublicKey', '_'): 'get_whatsapp_business_public_key',
132 ('GetWhatsAppBusinessPublicKey', '-'): 'get-whatsapp-business-public-key',
133 ('GetWhatsAppFlow', '_'): 'get_whatsapp_flow',
134 ('GetWhatsAppFlow', '-'): 'get-whatsapp-flow',
135 ('GetWhatsAppFlowPreview', '_'): 'get_whatsapp_flow_preview',
136 ('GetWhatsAppFlowPreview', '-'): 'get-whatsapp-flow-preview',
137 ('GetWhatsAppMessageMedia', '_'): 'get_whatsapp_message_media',
138 ('GetWhatsAppMessageMedia', '-'): 'get-whatsapp-message-media',
139 ('GetWhatsAppMessageTemplate', '_'): 'get_whatsapp_message_template',
140 ('GetWhatsAppMessageTemplate', '-'): 'get-whatsapp-message-template',
141 (
142 'ListLinkedWhatsAppBusinessAccounts',
143 '_',
144 ): 'list_linked_whatsapp_business_accounts',
145 (
146 'ListLinkedWhatsAppBusinessAccounts',
147 '-',
148 ): 'list-linked-whatsapp-business-accounts',
149 ('ListWhatsAppFlowAssets', '_'): 'list_whatsapp_flow_assets',
150 ('ListWhatsAppFlowAssets', '-'): 'list-whatsapp-flow-assets',
151 ('ListWhatsAppFlows', '_'): 'list_whatsapp_flows',
152 ('ListWhatsAppFlows', '-'): 'list-whatsapp-flows',
153 ('ListWhatsAppMessageTemplates', '_'): 'list_whatsapp_message_templates',
154 ('ListWhatsAppMessageTemplates', '-'): 'list-whatsapp-message-templates',
155 ('ListWhatsAppTemplateLibrary', '_'): 'list_whatsapp_template_library',
156 ('ListWhatsAppTemplateLibrary', '-'): 'list-whatsapp-template-library',
157 ('PostWhatsAppMessageMedia', '_'): 'post_whatsapp_message_media',
158 ('PostWhatsAppMessageMedia', '-'): 'post-whatsapp-message-media',
159 ('PublishWhatsAppFlow', '_'): 'publish_whatsapp_flow',
160 ('PublishWhatsAppFlow', '-'): 'publish-whatsapp-flow',
161 ('PutWhatsAppBusinessPublicKey', '_'): 'put_whatsapp_business_public_key',
162 ('PutWhatsAppBusinessPublicKey', '-'): 'put-whatsapp-business-public-key',
163 (
164 'PutWhatsAppBusinessAccountEventDestinations',
165 '_',
166 ): 'put_whatsapp_business_account_event_destinations',
167 (
168 'PutWhatsAppBusinessAccountEventDestinations',
169 '-',
170 ): 'put-whatsapp-business-account-event-destinations',
171 ('SendWhatsAppConversionEvent', '_'): 'send_whatsapp_conversion_event',
172 ('SendWhatsAppConversionEvent', '-'): 'send-whatsapp-conversion-event',
173 ('SendWhatsAppMessage', '_'): 'send_whatsapp_message',
174 ('SendWhatsAppMessage', '-'): 'send-whatsapp-message',
175 ('StartOTelEnrichment', '_'): 'start_otel_enrichment',
176 ('StartOTelEnrichment', '-'): 'start-otel-enrichment',
177 ('StopOTelEnrichment', '_'): 'stop_otel_enrichment',
178 ('StopOTelEnrichment', '-'): 'stop-otel-enrichment',
179 ('UpdateWhatsAppFlow', '_'): 'update_whatsapp_flow',
180 ('UpdateWhatsAppFlow', '-'): 'update-whatsapp-flow',
181 ('UpdateWhatsAppFlowAssets', '_'): 'update_whatsapp_flow_assets',
182 ('UpdateWhatsAppFlowAssets', '-'): 'update-whatsapp-flow-assets',
183 ('UpdateWhatsAppMessageTemplate', '_'): 'update_whatsapp_message_template',
184 ('UpdateWhatsAppMessageTemplate', '-'): 'update-whatsapp-message-template',
185}
186ScalarTypes = ('string', 'integer', 'boolean', 'timestamp', 'float', 'double')
188BOTOCORE_ROOT = os.path.dirname(os.path.abspath(__file__))
191# Used to specify anonymous (unsigned) request signature
192class UNSIGNED:
193 def __copy__(self):
194 return self
196 def __deepcopy__(self, memodict):
197 return self
200UNSIGNED = UNSIGNED()
203def xform_name(name, sep='_', _xform_cache=_xform_cache):
204 """Convert camel case to a "pythonic" name.
206 If the name contains the ``sep`` character, then it is
207 returned unchanged.
209 """
210 if sep in name:
211 # If the sep is in the name, assume that it's already
212 # transformed and return the string unchanged.
213 return name
214 key = (name, sep)
215 if key not in _xform_cache:
216 if _special_case_transform.search(name) is not None:
217 is_special = _special_case_transform.search(name)
218 matched = is_special.group()
219 # Replace something like ARNs, ACLs with _arns, _acls.
220 name = f"{name[: -len(matched)]}{sep}{matched.lower()}"
221 s1 = _first_cap_regex.sub(r'\1' + sep + r'\2', name)
222 transformed = _end_cap_regex.sub(r'\1' + sep + r'\2', s1).lower()
223 _xform_cache[key] = transformed
224 return _xform_cache[key]
227def register_initializer(callback):
228 """Register an initializer function for session creation.
230 This initializer function will be invoked whenever a new
231 `botocore.session.Session` is instantiated.
233 :type callback: callable
234 :param callback: A callable that accepts a single argument
235 of type `botocore.session.Session`.
237 """
238 _INITIALIZERS.append(callback)
241def unregister_initializer(callback):
242 """Unregister an initializer function.
244 :type callback: callable
245 :param callback: A callable that was previously registered
246 with `botocore.register_initializer`.
248 :raises ValueError: If a callback is provided that is not currently
249 registered as an initializer.
251 """
252 _INITIALIZERS.remove(callback)
255def invoke_initializers(session):
256 """Invoke all initializers for a session.
258 :type session: botocore.session.Session
259 :param session: The session to initialize.
261 """
262 for initializer in _INITIALIZERS:
263 initializer(session)