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.42.97'
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 ('CreateWhatsAppMessageTemplate', '_'): 'create_whatsapp_message_template',
62 ('CreateWhatsAppMessageTemplate', '-'): 'create-whatsapp-message-template',
63 (
64 'CreateWhatsAppMessageTemplateFromLibrary',
65 '_',
66 ): 'create_whatsapp_message_template_from_library',
67 (
68 'CreateWhatsAppMessageTemplateFromLibrary',
69 '-',
70 ): 'create-whatsapp-message-template-from-library',
71 (
72 'CreateWhatsAppMessageTemplateMedia',
73 '_',
74 ): 'create_whatsapp_message_template_media',
75 (
76 'CreateWhatsAppMessageTemplateMedia',
77 '-',
78 ): 'create-whatsapp-message-template-media',
79 ('DeleteWhatsAppMessageMedia', '_'): 'delete_whatsapp_message_media',
80 ('DeleteWhatsAppMessageMedia', '-'): 'delete-whatsapp-message-media',
81 ('DeleteWhatsAppMessageTemplate', '_'): 'delete_whatsapp_message_template',
82 ('DeleteWhatsAppMessageTemplate', '-'): 'delete-whatsapp-message-template',
83 (
84 'DisassociateWhatsAppBusinessAccount',
85 '_',
86 ): 'disassociate_whatsapp_business_account',
87 (
88 'DisassociateWhatsAppBusinessAccount',
89 '-',
90 ): 'disassociate-whatsapp-business-account',
91 (
92 'GetLinkedWhatsAppBusinessAccount',
93 '_',
94 ): 'get_linked_whatsapp_business_account',
95 (
96 'GetLinkedWhatsAppBusinessAccount',
97 '-',
98 ): 'get-linked-whatsapp-business-account',
99 (
100 'GetLinkedWhatsAppBusinessAccountPhoneNumber',
101 '_',
102 ): 'get_linked_whatsapp_business_account_phone_number',
103 (
104 'GetLinkedWhatsAppBusinessAccountPhoneNumber',
105 '-',
106 ): 'get-linked-whatsapp-business-account-phone-number',
107 ('GetOTelEnrichment', '_'): 'get_otel_enrichment',
108 ('GetOTelEnrichment', '-'): 'get-otel-enrichment',
109 ('GetWhatsAppMessageMedia', '_'): 'get_whatsapp_message_media',
110 ('GetWhatsAppMessageMedia', '-'): 'get-whatsapp-message-media',
111 ('GetWhatsAppMessageTemplate', '_'): 'get_whatsapp_message_template',
112 ('GetWhatsAppMessageTemplate', '-'): 'get-whatsapp-message-template',
113 (
114 'ListLinkedWhatsAppBusinessAccounts',
115 '_',
116 ): 'list_linked_whatsapp_business_accounts',
117 (
118 'ListLinkedWhatsAppBusinessAccounts',
119 '-',
120 ): 'list-linked-whatsapp-business-accounts',
121 ('ListWhatsAppMessageTemplates', '_'): 'list_whatsapp_message_templates',
122 ('ListWhatsAppMessageTemplates', '-'): 'list-whatsapp-message-templates',
123 ('ListWhatsAppTemplateLibrary', '_'): 'list_whatsapp_template_library',
124 ('ListWhatsAppTemplateLibrary', '-'): 'list-whatsapp-template-library',
125 ('PostWhatsAppMessageMedia', '_'): 'post_whatsapp_message_media',
126 ('PostWhatsAppMessageMedia', '-'): 'post-whatsapp-message-media',
127 (
128 'PutWhatsAppBusinessAccountEventDestinations',
129 '_',
130 ): 'put_whatsapp_business_account_event_destinations',
131 (
132 'PutWhatsAppBusinessAccountEventDestinations',
133 '-',
134 ): 'put-whatsapp-business-account-event-destinations',
135 ('SendWhatsAppMessage', '_'): 'send_whatsapp_message',
136 ('SendWhatsAppMessage', '-'): 'send-whatsapp-message',
137 ('StartOTelEnrichment', '_'): 'start_otel_enrichment',
138 ('StartOTelEnrichment', '-'): 'start-otel-enrichment',
139 ('StopOTelEnrichment', '_'): 'stop_otel_enrichment',
140 ('StopOTelEnrichment', '-'): 'stop-otel-enrichment',
141 ('UpdateWhatsAppMessageTemplate', '_'): 'update_whatsapp_message_template',
142 ('UpdateWhatsAppMessageTemplate', '-'): 'update-whatsapp-message-template',
143}
144ScalarTypes = ('string', 'integer', 'boolean', 'timestamp', 'float', 'double')
146BOTOCORE_ROOT = os.path.dirname(os.path.abspath(__file__))
149# Used to specify anonymous (unsigned) request signature
150class UNSIGNED:
151 def __copy__(self):
152 return self
154 def __deepcopy__(self, memodict):
155 return self
158UNSIGNED = UNSIGNED()
161def xform_name(name, sep='_', _xform_cache=_xform_cache):
162 """Convert camel case to a "pythonic" name.
164 If the name contains the ``sep`` character, then it is
165 returned unchanged.
167 """
168 if sep in name:
169 # If the sep is in the name, assume that it's already
170 # transformed and return the string unchanged.
171 return name
172 key = (name, sep)
173 if key not in _xform_cache:
174 if _special_case_transform.search(name) is not None:
175 is_special = _special_case_transform.search(name)
176 matched = is_special.group()
177 # Replace something like ARNs, ACLs with _arns, _acls.
178 name = f"{name[: -len(matched)]}{sep}{matched.lower()}"
179 s1 = _first_cap_regex.sub(r'\1' + sep + r'\2', name)
180 transformed = _end_cap_regex.sub(r'\1' + sep + r'\2', s1).lower()
181 _xform_cache[key] = transformed
182 return _xform_cache[key]
185def register_initializer(callback):
186 """Register an initializer function for session creation.
188 This initializer function will be invoked whenever a new
189 `botocore.session.Session` is instantiated.
191 :type callback: callable
192 :param callback: A callable that accepts a single argument
193 of type `botocore.session.Session`.
195 """
196 _INITIALIZERS.append(callback)
199def unregister_initializer(callback):
200 """Unregister an initializer function.
202 :type callback: callable
203 :param callback: A callable that was previously registered
204 with `botocore.register_initializer`.
206 :raises ValueError: If a callback is provided that is not currently
207 registered as an initializer.
209 """
210 _INITIALIZERS.remove(callback)
213def invoke_initializers(session):
214 """Invoke all initializers for a session.
216 :type session: botocore.session.Session
217 :param session: The session to initialize.
219 """
220 for initializer in _INITIALIZERS:
221 initializer(session)