Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/botocore/__init__.py: 57%
42 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
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
19__version__ = '1.33.10'
22class NullHandler(logging.Handler):
23 def emit(self, record):
24 pass
27# Configure default logger to do nothing
28log = logging.getLogger('botocore')
29log.addHandler(NullHandler())
31_INITIALIZERS = []
33_first_cap_regex = re.compile('(.)([A-Z][a-z]+)')
34_end_cap_regex = re.compile('([a-z0-9])([A-Z])')
35# The regex below handles the special case where some acronym
36# name is pluralized, e.g GatewayARNs, ListWebACLs, SomeCNAMEs.
37_special_case_transform = re.compile('[A-Z]{2,}s$')
38# Prepopulate the cache with special cases that don't match
39# our regular transformation.
40_xform_cache = {
41 ('CreateCachediSCSIVolume', '_'): 'create_cached_iscsi_volume',
42 ('CreateCachediSCSIVolume', '-'): 'create-cached-iscsi-volume',
43 ('DescribeCachediSCSIVolumes', '_'): 'describe_cached_iscsi_volumes',
44 ('DescribeCachediSCSIVolumes', '-'): 'describe-cached-iscsi-volumes',
45 ('DescribeStorediSCSIVolumes', '_'): 'describe_stored_iscsi_volumes',
46 ('DescribeStorediSCSIVolumes', '-'): 'describe-stored-iscsi-volumes',
47 ('CreateStorediSCSIVolume', '_'): 'create_stored_iscsi_volume',
48 ('CreateStorediSCSIVolume', '-'): 'create-stored-iscsi-volume',
49 ('ListHITsForQualificationType', '_'): 'list_hits_for_qualification_type',
50 ('ListHITsForQualificationType', '-'): 'list-hits-for-qualification-type',
51 ('ExecutePartiQLStatement', '_'): 'execute_partiql_statement',
52 ('ExecutePartiQLStatement', '-'): 'execute-partiql-statement',
53 ('ExecutePartiQLTransaction', '_'): 'execute_partiql_transaction',
54 ('ExecutePartiQLTransaction', '-'): 'execute-partiql-transaction',
55 ('ExecutePartiQLBatch', '_'): 'execute_partiql_batch',
56 ('ExecutePartiQLBatch', '-'): 'execute-partiql-batch',
57}
58# The items in this dict represent partial renames to apply globally to all
59# services which might have a matching argument or operation. This way a
60# common mis-translation can be fixed without having to call out each
61# individual case.
62ScalarTypes = ('string', 'integer', 'boolean', 'timestamp', 'float', 'double')
64BOTOCORE_ROOT = os.path.dirname(os.path.abspath(__file__))
67# Used to specify anonymous (unsigned) request signature
68class UNSIGNED:
69 def __copy__(self):
70 return self
72 def __deepcopy__(self, memodict):
73 return self
76UNSIGNED = UNSIGNED()
79def xform_name(name, sep='_', _xform_cache=_xform_cache):
80 """Convert camel case to a "pythonic" name.
82 If the name contains the ``sep`` character, then it is
83 returned unchanged.
85 """
86 if sep in name:
87 # If the sep is in the name, assume that it's already
88 # transformed and return the string unchanged.
89 return name
90 key = (name, sep)
91 if key not in _xform_cache:
92 if _special_case_transform.search(name) is not None:
93 is_special = _special_case_transform.search(name)
94 matched = is_special.group()
95 # Replace something like ARNs, ACLs with _arns, _acls.
96 name = f"{name[: -len(matched)]}{sep}{matched.lower()}"
97 s1 = _first_cap_regex.sub(r'\1' + sep + r'\2', name)
98 transformed = _end_cap_regex.sub(r'\1' + sep + r'\2', s1).lower()
99 _xform_cache[key] = transformed
100 return _xform_cache[key]
103def register_initializer(callback):
104 """Register an initializer function for session creation.
106 This initializer function will be invoked whenever a new
107 `botocore.session.Session` is instantiated.
109 :type callback: callable
110 :param callback: A callable that accepts a single argument
111 of type `botocore.session.Session`.
113 """
114 _INITIALIZERS.append(callback)
117def unregister_initializer(callback):
118 """Unregister an initializer function.
120 :type callback: callable
121 :param callback: A callable that was previously registered
122 with `botocore.register_initializer`.
124 :raises ValueError: If a callback is provided that is not currently
125 registered as an initializer.
127 """
128 _INITIALIZERS.remove(callback)
131def invoke_initializers(session):
132 """Invoke all initializers for a session.
134 :type session: botocore.session.Session
135 :param session: The session to initialize.
137 """
138 for initializer in _INITIALIZERS:
139 initializer(session)