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.71' 

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 ('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 ('GetWhatsAppFlow', '_'): 'get_whatsapp_flow', 

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

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

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

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

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

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

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

139 ( 

140 'ListLinkedWhatsAppBusinessAccounts', 

141 '_', 

142 ): 'list_linked_whatsapp_business_accounts', 

143 ( 

144 'ListLinkedWhatsAppBusinessAccounts', 

145 '-', 

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

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

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

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

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

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

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

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

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

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

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

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

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

159 ( 

160 'PutWhatsAppBusinessAccountEventDestinations', 

161 '_', 

162 ): 'put_whatsapp_business_account_event_destinations', 

163 ( 

164 'PutWhatsAppBusinessAccountEventDestinations', 

165 '-', 

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

167 ('SendWhatsAppConversionEvent', '_'): 'send_whatsapp_conversion_event', 

168 ('SendWhatsAppConversionEvent', '-'): 'send-whatsapp-conversion-event', 

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

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

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

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

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

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

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

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

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

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

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

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

181} 

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

183 

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

185 

186 

187# Used to specify anonymous (unsigned) request signature 

188class UNSIGNED: 

189 def __copy__(self): 

190 return self 

191 

192 def __deepcopy__(self, memodict): 

193 return self 

194 

195 

196UNSIGNED = UNSIGNED() 

197 

198 

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

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

201 

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

203 returned unchanged. 

204 

205 """ 

206 if sep in name: 

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

208 # transformed and return the string unchanged. 

209 return name 

210 key = (name, sep) 

211 if key not in _xform_cache: 

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

213 is_special = _special_case_transform.search(name) 

214 matched = is_special.group() 

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

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

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

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

219 _xform_cache[key] = transformed 

220 return _xform_cache[key] 

221 

222 

223def register_initializer(callback): 

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

225 

226 This initializer function will be invoked whenever a new 

227 `botocore.session.Session` is instantiated. 

228 

229 :type callback: callable 

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

231 of type `botocore.session.Session`. 

232 

233 """ 

234 _INITIALIZERS.append(callback) 

235 

236 

237def unregister_initializer(callback): 

238 """Unregister an initializer function. 

239 

240 :type callback: callable 

241 :param callback: A callable that was previously registered 

242 with `botocore.register_initializer`. 

243 

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

245 registered as an initializer. 

246 

247 """ 

248 _INITIALIZERS.remove(callback) 

249 

250 

251def invoke_initializers(session): 

252 """Invoke all initializers for a session. 

253 

254 :type session: botocore.session.Session 

255 :param session: The session to initialize. 

256 

257 """ 

258 for initializer in _INITIALIZERS: 

259 initializer(session)