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

41 statements  

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. 

14 

15import logging 

16import os 

17import re 

18from logging import NullHandler 

19 

20__version__ = '1.43.59' 

21 

22 

23# Configure default logger to do nothing 

24log = logging.getLogger('botocore') 

25log.addHandler(NullHandler()) 

26 

27_INITIALIZERS = [] 

28 

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 ('CreateWhatsAppFlow', '_'): 'create_whatsapp_flow', 

76 ('CreateWhatsAppFlow', '-'): 'create-whatsapp-flow', 

77 ('CreateWhatsAppMessageTemplate', '_'): 'create_whatsapp_message_template', 

78 ('CreateWhatsAppMessageTemplate', '-'): 'create-whatsapp-message-template', 

79 ( 

80 'CreateWhatsAppMessageTemplateFromLibrary', 

81 '_', 

82 ): 'create_whatsapp_message_template_from_library', 

83 ( 

84 'CreateWhatsAppMessageTemplateFromLibrary', 

85 '-', 

86 ): 'create-whatsapp-message-template-from-library', 

87 ( 

88 'CreateWhatsAppMessageTemplateMedia', 

89 '_', 

90 ): 'create_whatsapp_message_template_media', 

91 ( 

92 'CreateWhatsAppMessageTemplateMedia', 

93 '-', 

94 ): 'create-whatsapp-message-template-media', 

95 ('DeleteWhatsAppFlow', '_'): 'delete_whatsapp_flow', 

96 ('DeleteWhatsAppFlow', '-'): 'delete-whatsapp-flow', 

97 ('DeleteWhatsAppMessageMedia', '_'): 'delete_whatsapp_message_media', 

98 ('DeleteWhatsAppMessageMedia', '-'): 'delete-whatsapp-message-media', 

99 ('DeleteWhatsAppMessageTemplate', '_'): 'delete_whatsapp_message_template', 

100 ('DeleteWhatsAppMessageTemplate', '-'): 'delete-whatsapp-message-template', 

101 ('DeprecateWhatsAppFlow', '_'): 'deprecate_whatsapp_flow', 

102 ('DeprecateWhatsAppFlow', '-'): 'deprecate-whatsapp-flow', 

103 ( 

104 'DisassociateWhatsAppBusinessAccount', 

105 '_', 

106 ): 'disassociate_whatsapp_business_account', 

107 ( 

108 'DisassociateWhatsAppBusinessAccount', 

109 '-', 

110 ): 'disassociate-whatsapp-business-account', 

111 ( 

112 'GetLinkedWhatsAppBusinessAccount', 

113 '_', 

114 ): 'get_linked_whatsapp_business_account', 

115 ( 

116 'GetLinkedWhatsAppBusinessAccount', 

117 '-', 

118 ): 'get-linked-whatsapp-business-account', 

119 ( 

120 'GetLinkedWhatsAppBusinessAccountPhoneNumber', 

121 '_', 

122 ): 'get_linked_whatsapp_business_account_phone_number', 

123 ( 

124 'GetLinkedWhatsAppBusinessAccountPhoneNumber', 

125 '-', 

126 ): 'get-linked-whatsapp-business-account-phone-number', 

127 ('GetOTelEnrichment', '_'): 'get_otel_enrichment', 

128 ('GetOTelEnrichment', '-'): 'get-otel-enrichment', 

129 ('GetWhatsAppFlow', '_'): 'get_whatsapp_flow', 

130 ('GetWhatsAppFlow', '-'): 'get-whatsapp-flow', 

131 ('GetWhatsAppFlowPreview', '_'): 'get_whatsapp_flow_preview', 

132 ('GetWhatsAppFlowPreview', '-'): 'get-whatsapp-flow-preview', 

133 ('GetWhatsAppMessageMedia', '_'): 'get_whatsapp_message_media', 

134 ('GetWhatsAppMessageMedia', '-'): 'get-whatsapp-message-media', 

135 ('GetWhatsAppMessageTemplate', '_'): 'get_whatsapp_message_template', 

136 ('GetWhatsAppMessageTemplate', '-'): 'get-whatsapp-message-template', 

137 ( 

138 'ListLinkedWhatsAppBusinessAccounts', 

139 '_', 

140 ): 'list_linked_whatsapp_business_accounts', 

141 ( 

142 'ListLinkedWhatsAppBusinessAccounts', 

143 '-', 

144 ): 'list-linked-whatsapp-business-accounts', 

145 ('ListWhatsAppFlowAssets', '_'): 'list_whatsapp_flow_assets', 

146 ('ListWhatsAppFlowAssets', '-'): 'list-whatsapp-flow-assets', 

147 ('ListWhatsAppFlows', '_'): 'list_whatsapp_flows', 

148 ('ListWhatsAppFlows', '-'): 'list-whatsapp-flows', 

149 ('ListWhatsAppMessageTemplates', '_'): 'list_whatsapp_message_templates', 

150 ('ListWhatsAppMessageTemplates', '-'): 'list-whatsapp-message-templates', 

151 ('ListWhatsAppTemplateLibrary', '_'): 'list_whatsapp_template_library', 

152 ('ListWhatsAppTemplateLibrary', '-'): 'list-whatsapp-template-library', 

153 ('PostWhatsAppMessageMedia', '_'): 'post_whatsapp_message_media', 

154 ('PostWhatsAppMessageMedia', '-'): 'post-whatsapp-message-media', 

155 ('PublishWhatsAppFlow', '_'): 'publish_whatsapp_flow', 

156 ('PublishWhatsAppFlow', '-'): 'publish-whatsapp-flow', 

157 ( 

158 'PutWhatsAppBusinessAccountEventDestinations', 

159 '_', 

160 ): 'put_whatsapp_business_account_event_destinations', 

161 ( 

162 'PutWhatsAppBusinessAccountEventDestinations', 

163 '-', 

164 ): 'put-whatsapp-business-account-event-destinations', 

165 ('SendWhatsAppMessage', '_'): 'send_whatsapp_message', 

166 ('SendWhatsAppMessage', '-'): 'send-whatsapp-message', 

167 ('StartOTelEnrichment', '_'): 'start_otel_enrichment', 

168 ('StartOTelEnrichment', '-'): 'start-otel-enrichment', 

169 ('StopOTelEnrichment', '_'): 'stop_otel_enrichment', 

170 ('StopOTelEnrichment', '-'): 'stop-otel-enrichment', 

171 ('UpdateWhatsAppFlow', '_'): 'update_whatsapp_flow', 

172 ('UpdateWhatsAppFlow', '-'): 'update-whatsapp-flow', 

173 ('UpdateWhatsAppFlowAssets', '_'): 'update_whatsapp_flow_assets', 

174 ('UpdateWhatsAppFlowAssets', '-'): 'update-whatsapp-flow-assets', 

175 ('UpdateWhatsAppMessageTemplate', '_'): 'update_whatsapp_message_template', 

176 ('UpdateWhatsAppMessageTemplate', '-'): 'update-whatsapp-message-template', 

177} 

178ScalarTypes = ('string', 'integer', 'boolean', 'timestamp', 'float', 'double') 

179 

180BOTOCORE_ROOT = os.path.dirname(os.path.abspath(__file__)) 

181 

182 

183# Used to specify anonymous (unsigned) request signature 

184class UNSIGNED: 

185 def __copy__(self): 

186 return self 

187 

188 def __deepcopy__(self, memodict): 

189 return self 

190 

191 

192UNSIGNED = UNSIGNED() 

193 

194 

195def xform_name(name, sep='_', _xform_cache=_xform_cache): 

196 """Convert camel case to a "pythonic" name. 

197 

198 If the name contains the ``sep`` character, then it is 

199 returned unchanged. 

200 

201 """ 

202 if sep in name: 

203 # If the sep is in the name, assume that it's already 

204 # transformed and return the string unchanged. 

205 return name 

206 key = (name, sep) 

207 if key not in _xform_cache: 

208 if _special_case_transform.search(name) is not None: 

209 is_special = _special_case_transform.search(name) 

210 matched = is_special.group() 

211 # Replace something like ARNs, ACLs with _arns, _acls. 

212 name = f"{name[: -len(matched)]}{sep}{matched.lower()}" 

213 s1 = _first_cap_regex.sub(r'\1' + sep + r'\2', name) 

214 transformed = _end_cap_regex.sub(r'\1' + sep + r'\2', s1).lower() 

215 _xform_cache[key] = transformed 

216 return _xform_cache[key] 

217 

218 

219def register_initializer(callback): 

220 """Register an initializer function for session creation. 

221 

222 This initializer function will be invoked whenever a new 

223 `botocore.session.Session` is instantiated. 

224 

225 :type callback: callable 

226 :param callback: A callable that accepts a single argument 

227 of type `botocore.session.Session`. 

228 

229 """ 

230 _INITIALIZERS.append(callback) 

231 

232 

233def unregister_initializer(callback): 

234 """Unregister an initializer function. 

235 

236 :type callback: callable 

237 :param callback: A callable that was previously registered 

238 with `botocore.register_initializer`. 

239 

240 :raises ValueError: If a callback is provided that is not currently 

241 registered as an initializer. 

242 

243 """ 

244 _INITIALIZERS.remove(callback) 

245 

246 

247def invoke_initializers(session): 

248 """Invoke all initializers for a session. 

249 

250 :type session: botocore.session.Session 

251 :param session: The session to initialize. 

252 

253 """ 

254 for initializer in _INITIALIZERS: 

255 initializer(session)