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.29'
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 (
54 'AssociateWhatsAppBusinessAccount',
55 '_',
56 ): 'associate_whatsapp_business_account',
57 (
58 'AssociateWhatsAppBusinessAccount',
59 '-',
60 ): 'associate-whatsapp-business-account',
61 ('CreateWhatsAppFlow', '_'): 'create_whatsapp_flow',
62 ('CreateWhatsAppFlow', '-'): 'create-whatsapp-flow',
63 ('CreateWhatsAppMessageTemplate', '_'): 'create_whatsapp_message_template',
64 ('CreateWhatsAppMessageTemplate', '-'): 'create-whatsapp-message-template',
65 (
66 'CreateWhatsAppMessageTemplateFromLibrary',
67 '_',
68 ): 'create_whatsapp_message_template_from_library',
69 (
70 'CreateWhatsAppMessageTemplateFromLibrary',
71 '-',
72 ): 'create-whatsapp-message-template-from-library',
73 (
74 'CreateWhatsAppMessageTemplateMedia',
75 '_',
76 ): 'create_whatsapp_message_template_media',
77 (
78 'CreateWhatsAppMessageTemplateMedia',
79 '-',
80 ): 'create-whatsapp-message-template-media',
81 ('DeleteWhatsAppFlow', '_'): 'delete_whatsapp_flow',
82 ('DeleteWhatsAppFlow', '-'): 'delete-whatsapp-flow',
83 ('DeleteWhatsAppMessageMedia', '_'): 'delete_whatsapp_message_media',
84 ('DeleteWhatsAppMessageMedia', '-'): 'delete-whatsapp-message-media',
85 ('DeleteWhatsAppMessageTemplate', '_'): 'delete_whatsapp_message_template',
86 ('DeleteWhatsAppMessageTemplate', '-'): 'delete-whatsapp-message-template',
87 ('DeprecateWhatsAppFlow', '_'): 'deprecate_whatsapp_flow',
88 ('DeprecateWhatsAppFlow', '-'): 'deprecate-whatsapp-flow',
89 (
90 'DisassociateWhatsAppBusinessAccount',
91 '_',
92 ): 'disassociate_whatsapp_business_account',
93 (
94 'DisassociateWhatsAppBusinessAccount',
95 '-',
96 ): 'disassociate-whatsapp-business-account',
97 (
98 'GetLinkedWhatsAppBusinessAccount',
99 '_',
100 ): 'get_linked_whatsapp_business_account',
101 (
102 'GetLinkedWhatsAppBusinessAccount',
103 '-',
104 ): 'get-linked-whatsapp-business-account',
105 (
106 'GetLinkedWhatsAppBusinessAccountPhoneNumber',
107 '_',
108 ): 'get_linked_whatsapp_business_account_phone_number',
109 (
110 'GetLinkedWhatsAppBusinessAccountPhoneNumber',
111 '-',
112 ): 'get-linked-whatsapp-business-account-phone-number',
113 ('GetOTelEnrichment', '_'): 'get_otel_enrichment',
114 ('GetOTelEnrichment', '-'): 'get-otel-enrichment',
115 ('GetWhatsAppFlow', '_'): 'get_whatsapp_flow',
116 ('GetWhatsAppFlow', '-'): 'get-whatsapp-flow',
117 ('GetWhatsAppFlowPreview', '_'): 'get_whatsapp_flow_preview',
118 ('GetWhatsAppFlowPreview', '-'): 'get-whatsapp-flow-preview',
119 ('GetWhatsAppMessageMedia', '_'): 'get_whatsapp_message_media',
120 ('GetWhatsAppMessageMedia', '-'): 'get-whatsapp-message-media',
121 ('GetWhatsAppMessageTemplate', '_'): 'get_whatsapp_message_template',
122 ('GetWhatsAppMessageTemplate', '-'): 'get-whatsapp-message-template',
123 (
124 'ListLinkedWhatsAppBusinessAccounts',
125 '_',
126 ): 'list_linked_whatsapp_business_accounts',
127 (
128 'ListLinkedWhatsAppBusinessAccounts',
129 '-',
130 ): 'list-linked-whatsapp-business-accounts',
131 ('ListWhatsAppFlowAssets', '_'): 'list_whatsapp_flow_assets',
132 ('ListWhatsAppFlowAssets', '-'): 'list-whatsapp-flow-assets',
133 ('ListWhatsAppFlows', '_'): 'list_whatsapp_flows',
134 ('ListWhatsAppFlows', '-'): 'list-whatsapp-flows',
135 ('ListWhatsAppMessageTemplates', '_'): 'list_whatsapp_message_templates',
136 ('ListWhatsAppMessageTemplates', '-'): 'list-whatsapp-message-templates',
137 ('ListWhatsAppTemplateLibrary', '_'): 'list_whatsapp_template_library',
138 ('ListWhatsAppTemplateLibrary', '-'): 'list-whatsapp-template-library',
139 ('PostWhatsAppMessageMedia', '_'): 'post_whatsapp_message_media',
140 ('PostWhatsAppMessageMedia', '-'): 'post-whatsapp-message-media',
141 ('PublishWhatsAppFlow', '_'): 'publish_whatsapp_flow',
142 ('PublishWhatsAppFlow', '-'): 'publish-whatsapp-flow',
143 (
144 'PutWhatsAppBusinessAccountEventDestinations',
145 '_',
146 ): 'put_whatsapp_business_account_event_destinations',
147 (
148 'PutWhatsAppBusinessAccountEventDestinations',
149 '-',
150 ): 'put-whatsapp-business-account-event-destinations',
151 ('SendWhatsAppMessage', '_'): 'send_whatsapp_message',
152 ('SendWhatsAppMessage', '-'): 'send-whatsapp-message',
153 ('StartOTelEnrichment', '_'): 'start_otel_enrichment',
154 ('StartOTelEnrichment', '-'): 'start-otel-enrichment',
155 ('StopOTelEnrichment', '_'): 'stop_otel_enrichment',
156 ('StopOTelEnrichment', '-'): 'stop-otel-enrichment',
157 ('UpdateWhatsAppFlow', '_'): 'update_whatsapp_flow',
158 ('UpdateWhatsAppFlow', '-'): 'update-whatsapp-flow',
159 ('UpdateWhatsAppFlowAssets', '_'): 'update_whatsapp_flow_assets',
160 ('UpdateWhatsAppFlowAssets', '-'): 'update-whatsapp-flow-assets',
161 ('UpdateWhatsAppMessageTemplate', '_'): 'update_whatsapp_message_template',
162 ('UpdateWhatsAppMessageTemplate', '-'): 'update-whatsapp-message-template',
163}
164ScalarTypes = ('string', 'integer', 'boolean', 'timestamp', 'float', 'double')
166BOTOCORE_ROOT = os.path.dirname(os.path.abspath(__file__))
169# Used to specify anonymous (unsigned) request signature
170class UNSIGNED:
171 def __copy__(self):
172 return self
174 def __deepcopy__(self, memodict):
175 return self
178UNSIGNED = UNSIGNED()
181def xform_name(name, sep='_', _xform_cache=_xform_cache):
182 """Convert camel case to a "pythonic" name.
184 If the name contains the ``sep`` character, then it is
185 returned unchanged.
187 """
188 if sep in name:
189 # If the sep is in the name, assume that it's already
190 # transformed and return the string unchanged.
191 return name
192 key = (name, sep)
193 if key not in _xform_cache:
194 if _special_case_transform.search(name) is not None:
195 is_special = _special_case_transform.search(name)
196 matched = is_special.group()
197 # Replace something like ARNs, ACLs with _arns, _acls.
198 name = f"{name[: -len(matched)]}{sep}{matched.lower()}"
199 s1 = _first_cap_regex.sub(r'\1' + sep + r'\2', name)
200 transformed = _end_cap_regex.sub(r'\1' + sep + r'\2', s1).lower()
201 _xform_cache[key] = transformed
202 return _xform_cache[key]
205def register_initializer(callback):
206 """Register an initializer function for session creation.
208 This initializer function will be invoked whenever a new
209 `botocore.session.Session` is instantiated.
211 :type callback: callable
212 :param callback: A callable that accepts a single argument
213 of type `botocore.session.Session`.
215 """
216 _INITIALIZERS.append(callback)
219def unregister_initializer(callback):
220 """Unregister an initializer function.
222 :type callback: callable
223 :param callback: A callable that was previously registered
224 with `botocore.register_initializer`.
226 :raises ValueError: If a callback is provided that is not currently
227 registered as an initializer.
229 """
230 _INITIALIZERS.remove(callback)
233def invoke_initializers(session):
234 """Invoke all initializers for a session.
236 :type session: botocore.session.Session
237 :param session: The session to initialize.
239 """
240 for initializer in _INITIALIZERS:
241 initializer(session)