Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/botocore/plugin.py: 45%
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 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"). You
4# may not use this file except in compliance with the License. A copy of
5# the License is located at
6#
7# http://aws.amazon.com/apache2.0/
8#
9# or in the "license" file accompanying this file. This file is
10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11# ANY KIND, either express or implied. See the License for the specific
12# language governing permissions and limitations under the License.
13"""
14NOTE: This module is considered private and is subject to abrupt breaking
15changes without prior announcement. Please do not use it directly.
16"""
18import importlib
19import logging
20import os
21from contextvars import ContextVar
22from dataclasses import dataclass
23from typing import Optional
25log = logging.getLogger(__name__)
28@dataclass
29class PluginContext:
30 """
31 Encapsulation of plugins tracked within the `_plugin_context` context variable.
32 """
34 plugins: Optional[str] = None
37_plugin_context = ContextVar("_plugin_context")
40def get_plugin_context():
41 """Get the current `_plugin_context` context variable if set, else None."""
42 return _plugin_context.get(None)
45def set_plugin_context(ctx):
46 """Set the current `_plugin_context` context variable."""
47 token = _plugin_context.set(ctx)
48 return token
51def reset_plugin_context(token):
52 """Reset the current `_plugin_context` context variable."""
53 _plugin_context.reset(token)
56def get_botocore_plugins():
57 context = get_plugin_context()
58 if context is not None:
59 plugins = context.plugins
60 if plugins is None:
61 context.plugins = os.environ.get('BOTOCORE_EXPERIMENTAL__PLUGINS')
62 else:
63 return plugins
64 return os.environ.get('BOTOCORE_EXPERIMENTAL__PLUGINS')
67def load_client_plugins(client, plugins):
68 for plugin_name, module_name in plugins.items():
69 log.debug(
70 "Importing client plugin %s from module %s",
71 plugin_name,
72 module_name,
73 )
74 try:
75 module = importlib.import_module(module_name)
76 module.initialize_client_plugin(client)
77 except ModuleNotFoundError:
78 log.debug(
79 "Failed to locate the following plugin module: %s.",
80 plugin_name,
81 )
82 except Exception as e:
83 log.debug(
84 "Error raised during the loading of %s: %s", plugin_name, e
85 )