Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/boto3/utils.py: 52%
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 2015 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# https://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.
13from collections import namedtuple
14from importlib import import_module
16_ServiceContext = namedtuple(
17 'ServiceContext',
18 [
19 'service_name',
20 'service_model',
21 'service_waiter_model',
22 'resource_json_definitions',
23 ],
24)
27class ServiceContext(_ServiceContext):
28 """Provides important service-wide, read-only information about a service
30 :type service_name: str
31 :param service_name: The name of the service
33 :type service_model: :py:class:`botocore.model.ServiceModel`
34 :param service_model: The model of the service.
36 :type service_waiter_model: :py:class:`botocore.waiter.WaiterModel` or
37 a waiter model-like object such as
38 :py:class:`boto3.utils.LazyLoadedWaiterModel`
39 :param service_waiter_model: The waiter model of the service.
41 :type resource_json_definitions: dict
42 :param resource_json_definitions: The loaded json models of all resource
43 shapes for a service. It is equivalient of loading a
44 ``resource-1.json`` and retrieving the value at the key "resources".
45 """
47 pass
50def lazy_call(full_name, **kwargs):
51 parent_kwargs = kwargs
53 def _handler(**kwargs):
54 module, function_name = full_name.rsplit('.', 1)
55 module = import_module(module)
56 kwargs.update(parent_kwargs)
57 return getattr(module, function_name)(**kwargs)
59 return _handler
62def inject_attribute(class_attributes, name, value):
63 if name in class_attributes:
64 raise RuntimeError(
65 f'Cannot inject class attribute "{name}", attribute '
66 f'already exists in class dict.'
67 )
68 else:
69 class_attributes[name] = value
72class LazyLoadedWaiterModel:
73 """A lazily loaded waiter model
75 This does not load the service waiter model until an attempt is made
76 to retrieve the waiter model for a specific waiter. This is helpful
77 in docstring generation where we do not need to actually need to grab
78 the waiter-2.json until it is accessed through a ``get_waiter`` call
79 when the docstring is generated/accessed.
80 """
82 def __init__(self, bc_session, service_name, api_version):
83 self._session = bc_session
84 self._service_name = service_name
85 self._api_version = api_version
87 def get_waiter(self, waiter_name):
88 return self._session.get_waiter_model(
89 self._service_name, self._api_version
90 ).get_waiter(waiter_name)