Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
utils.py101 linesDownload Raw Back to boto3
1# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# https://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13import sys14from collections import namedtuple15 16_ServiceContext = namedtuple(17    'ServiceContext',18    [19        'service_name',20        'service_model',21        'service_waiter_model',22        'resource_json_definitions',23    ],24)25 26 27class ServiceContext(_ServiceContext):28    """Provides important service-wide, read-only information about a service29 30    :type service_name: str31    :param service_name: The name of the service32 33    :type service_model: :py:class:`botocore.model.ServiceModel`34    :param service_model: The model of the service.35 36    :type service_waiter_model: :py:class:`botocore.waiter.WaiterModel` or37        a waiter model-like object such as38        :py:class:`boto3.utils.LazyLoadedWaiterModel`39    :param service_waiter_model: The waiter model of the service.40 41    :type resource_json_definitions: dict42    :param resource_json_definitions: The loaded json models of all resource43        shapes for a service. It is equivalient of loading a44        ``resource-1.json`` and retrieving the value at the key "resources".45    """46 47    pass48 49 50def import_module(name):51    """Import module given a name.52 53    Does not support relative imports.54 55    """56    __import__(name)57    return sys.modules[name]58 59 60def lazy_call(full_name, **kwargs):61    parent_kwargs = kwargs62 63    def _handler(**kwargs):64        module, function_name = full_name.rsplit('.', 1)65        module = import_module(module)66        kwargs.update(parent_kwargs)67        return getattr(module, function_name)(**kwargs)68 69    return _handler70 71 72def inject_attribute(class_attributes, name, value):73    if name in class_attributes:74        raise RuntimeError(75            f'Cannot inject class attribute "{name}", attribute '76            f'already exists in class dict.'77        )78    else:79        class_attributes[name] = value80 81 82class LazyLoadedWaiterModel:83    """A lazily loaded waiter model84 85    This does not load the service waiter model until an attempt is made86    to retrieve the waiter model for a specific waiter. This is helpful87    in docstring generation where we do not need to actually need to grab88    the waiter-2.json until it is accessed through a ``get_waiter`` call89    when the docstring is generated/accessed.90    """91 92    def __init__(self, bc_session, service_name, api_version):93        self._session = bc_session94        self._service_name = service_name95        self._api_version = api_version96 97    def get_waiter(self, waiter_name):98        return self._session.get_waiter_model(99            self._service_name, self._api_version100        ).get_waiter(waiter_name)101 
codekingpro/portable-devtools · Team Ai