Пример #1
0
 def test_client_name_with_non_alphabet_characters(self):
     self.service_description['metadata']['serviceFullName'] = (
         'Amazon My-Service')
     self.assertEqual(
         get_service_module_name(self.service_model),
         'MyService'
     )
Пример #2
0
 def test_client_name_using_abreviation(self):
     self.service_description['metadata']['serviceAbbreviation'] = (
         'Abbreviation')
     self.assertEqual(
         get_service_module_name(self.service_model),
         'Abbreviation'
     )
def get_botocore_class_name(metadata: Dict[str, str]) -> str:
    """
    Get Botocore class name from Service metadata.
    """
    service_model = MagicMock()
    service_model.service_name = metadata.get("serviceId", "")
    service_model.metadata = metadata
    return get_service_module_name(service_model)
Пример #4
0
    def get_paginator(self, operation_name):
        """Create a paginator for an operation.

        :type operation_name: string
        :param operation_name: The operation name.  This is the same name
            as the method name on the client.  For example, if the
            method name is ``create_foo``, and you'd normally invoke the
            operation as ``client.create_foo(**kwargs)``, if the
            ``create_foo`` operation can be paginated, you can use the
            call ``client.get_paginator("create_foo")``.

        :raise OperationNotPageableError: Raised if the operation is not
            pageable.  You can use the ``client.can_paginate`` method to
            check if an operation is pageable.

        :rtype: L{botocore.paginate.Paginator}
        :return: A paginator object.

        """
        if not self.can_paginate(operation_name):
            raise OperationNotPageableError(operation_name=operation_name)
        else:
            actual_operation_name = self._PY_TO_OP_NAME[operation_name]

            # Create a new paginate method that will serve as a proxy to
            # the underlying Paginator.paginate method. This is needed to
            # attach a docstring to the method.
            def paginate(self, **kwargs):
                return Paginator.paginate(self, **kwargs)

            paginator_config = self._cache['page_config'][
                actual_operation_name]
            # Add the docstring for the paginate method.
            paginate.__doc__ = PaginatorDocstring(
                paginator_name=actual_operation_name,
                event_emitter=self.meta.events,
                service_model=self.meta.service_model,
                paginator_config=paginator_config,
                include_signature=False
            )

            # Rename the paginator class based on the type of paginator.
            paginator_class_name = str('%s.Paginator.%s' % (
                get_service_module_name(self.meta.service_model),
                actual_operation_name))

            # Create the new paginator class
            documented_paginator_cls = type(
                paginator_class_name, (Paginator,), {'paginate': paginate})

            operation_model = self._service_model.operation_model(actual_operation_name)
            paginator = documented_paginator_cls(
                getattr(self, operation_name),
                paginator_config,
                operation_model)
            return paginator
Пример #5
0
    def get_paginator(self, operation_name):
        """Create a paginator for an operation.

        :type operation_name: string
        :param operation_name: The operation name.  This is the same name
            as the method name on the client.  For example, if the
            method name is ``create_foo``, and you'd normally invoke the
            operation as ``client.create_foo(**kwargs)``, if the
            ``create_foo`` operation can be paginated, you can use the
            call ``client.get_paginator("create_foo")``.

        :raise OperationNotPageableError: Raised if the operation is not
            pageable.  You can use the ``client.can_paginate`` method to
            check if an operation is pageable.

        :rtype: L{botocore.paginate.Paginator}
        :return: A paginator object.

        """
        if not self.can_paginate(operation_name):
            raise OperationNotPageableError(operation_name=operation_name)
        else:
            actual_operation_name = self._PY_TO_OP_NAME[operation_name]

            # Create a new paginate method that will serve as a proxy to
            # the underlying Paginator.paginate method. This is needed to
            # attach a docstring to the method.
            def paginate(self, **kwargs):
                return Paginator.paginate(self, **kwargs)

            paginator_config = self._cache['page_config'][
                actual_operation_name]
            # Add the docstring for the paginate method.
            paginate.__doc__ = PaginatorDocstring(
                paginator_name=actual_operation_name,
                event_emitter=self.meta.events,
                service_model=self.meta.service_model,
                paginator_config=paginator_config,
                include_signature=False)

            # Rename the paginator class based on the type of paginator.
            paginator_class_name = str(
                '%s.Paginator.%s' % (get_service_module_name(
                    self.meta.service_model), actual_operation_name))

            # Create the new paginator class
            documented_paginator_cls = type(paginator_class_name,
                                            (Paginator, ),
                                            {'paginate': paginate})

            operation_model = self._service_model.operation_model(
                actual_operation_name)
            paginator = documented_paginator_cls(getattr(self, operation_name),
                                                 paginator_config,
                                                 operation_model)
            return paginator
Пример #6
0
 def _create_client_class(self, service_name, service_model):
     class_attributes = self._create_methods(service_model)
     py_name_to_operation_name = self._create_name_mapping(service_model)
     class_attributes['_PY_TO_OP_NAME'] = py_name_to_operation_name
     bases = [BaseClient]
     self._event_emitter.emit('creating-client-class.%s' % service_name,
                              class_attributes=class_attributes,
                              base_classes=bases)
     class_name = get_service_module_name(service_model)
     cls = type(str(class_name), tuple(bases), class_attributes)
     return cls
Пример #7
0
 def _create_client_class(self, service_name, service_model):
     class_attributes = self._create_methods(service_model)
     py_name_to_operation_name = self._create_name_mapping(service_model)
     class_attributes['_PY_TO_OP_NAME'] = py_name_to_operation_name
     bases = [BaseClient]
     self._event_emitter.emit('creating-client-class.%s' % service_name,
                              class_attributes=class_attributes,
                              base_classes=bases)
     class_name = get_service_module_name(service_model)
     cls = type(str(class_name), tuple(bases), class_attributes)
     return cls
Пример #8
0
 def _create_client_exceptions(self, service_model):
     cls_props = {}
     code_to_exception = {}
     for error_shape in service_model.error_shapes:
         exception_name = str(error_shape.name)
         exception_cls = type(exception_name, (ClientError, ), {})
         cls_props[exception_name] = exception_cls
         code = str(error_shape.error_code)
         code_to_exception[code] = exception_cls
     cls_name = str(get_service_module_name(service_model) + 'Exceptions')
     client_exceptions_cls = type(cls_name, (BaseClientExceptions, ),
                                  cls_props)
     return client_exceptions_cls(code_to_exception)
Пример #9
0
def create_waiter_with_client(waiter_name, waiter_model, client, loop):
    """

    :type waiter_name: str
    :param waiter_name: The name of the waiter.  The name should match
        the name (including the casing) of the key name in the waiter
        model file (typically this is CamelCasing).

    :type waiter_model: botocore.waiter.WaiterModel
    :param waiter_model: The model for the waiter configuration.

    :type client: botocore.client.BaseClient
    :param client: The botocore client associated with the service.

    :rtype: botocore.waiter.Waiter
    :return: The waiter object.

    """
    single_waiter_config = waiter_model.get_waiter(waiter_name)
    operation_name = xform_name(single_waiter_config.operation)
    operation_method = NormalizedOperationMethod(
        getattr(client, operation_name))

    # Create a new wait method that will serve as a proxy to the underlying
    # Waiter.wait method. This is needed to attach a docstring to the
    # method.
    async def wait(self, **kwargs):
        await AIOWaiter.wait(self, **kwargs)

    wait.__doc__ = WaiterDocstring(
        waiter_name=waiter_name,
        event_emitter=client.meta.events,
        service_model=client.meta.service_model,
        service_waiter_model=waiter_model,
        include_signature=False
    )

    # Rename the waiter class based on the type of waiter.
    waiter_class_name = str('%s.AIOWaiter.%s' % (
        get_service_module_name(client.meta.service_model),
        waiter_name))

    # Create the new waiter class
    documented_waiter_cls = type(
        waiter_class_name, (AIOWaiter,), {'wait': wait})

    # Return an instance of the new waiter class.
    return documented_waiter_cls(
        waiter_name, single_waiter_config, operation_method, loop=loop
    )
Пример #10
0
def document_resource_waiter(
    section,
    resource_name,
    event_emitter,
    service_model,
    resource_waiter_model,
    service_waiter_model,
    include_signature=True,
):
    waiter_model = service_waiter_model.get_waiter(
        resource_waiter_model.waiter_name)
    operation_model = service_model.operation_model(waiter_model.operation)

    ignore_params = get_resource_ignore_params(resource_waiter_model.params)
    service_module_name = get_service_module_name(service_model)
    description = ('Waits until this {} is {}. This method calls '
                   ':py:meth:`{}.Waiter.{}.wait` which polls. '
                   ':py:meth:`{}.Client.{}` every {} seconds until '
                   'a successful state is reached. An error is returned '
                   'after {} failed checks.'.format(
                       resource_name,
                       ' '.join(resource_waiter_model.name.split('_')[2:]),
                       service_module_name,
                       xform_name(resource_waiter_model.waiter_name),
                       service_module_name,
                       xform_name(waiter_model.operation),
                       waiter_model.delay,
                       waiter_model.max_attempts,
                   ))
    example_prefix = '{}.{}'.format(xform_name(resource_name),
                                    resource_waiter_model.name)
    document_model_driven_method(
        section=section,
        method_name=resource_waiter_model.name,
        operation_model=operation_model,
        event_emitter=event_emitter,
        example_prefix=example_prefix,
        method_description=description,
        exclude_input=ignore_params,
        include_signature=include_signature,
    )
    if 'return' in section.available_sections:
        # Waiters do not return anything so we should remove
        # any sections that may document the underlying return
        # value of the client method.
        return_section = section.get_section('return')
        return_section.clear_text()
        return_section.remove_all_sections()
        return_section.write(':returns: None')
Пример #11
0
def document_load_reload_action(
    section,
    action_name,
    resource_name,
    event_emitter,
    load_model,
    service_model,
    include_signature=True,
):
    """Documents the resource load action

    :param section: The section to write to

    :param action_name: The name of the loading action should be load or reload

    :param resource_name: The name of the resource

    :param event_emitter: The event emitter to use to emit events

    :param load_model: The model of the load action

    :param service_model: The model of the service

    :param include_signature: Whether or not to include the signature.
        It is useful for generating docstrings.
    """
    description = (
        'Calls :py:meth:`{}.Client.{}` to update the attributes of the '
        '{} resource. Note that the load and reload methods are '
        'the same method and can be used interchangeably.'.format(
            get_service_module_name(service_model),
            xform_name(load_model.request.operation),
            resource_name,
        ))
    example_resource_name = xform_name(resource_name)
    if service_model.service_name == resource_name:
        example_resource_name = resource_name
    example_prefix = f'{example_resource_name}.{action_name}'
    document_model_driven_method(
        section=section,
        method_name=action_name,
        operation_model=OperationModel({}, service_model),
        event_emitter=event_emitter,
        method_description=description,
        example_prefix=example_prefix,
        include_signature=include_signature,
    )
 def _create_client_exceptions(self, service_model):
     cls_props = {}
     code_to_exception = {}
     for shape_name in service_model.shape_names:
         shape = service_model.shape_for(shape_name)
         if shape.metadata.get('exception', False):
             exception_name = str(shape.name)
             exception_cls = type(exception_name, (ClientError,), {})
             code = shape.metadata.get("error", {}).get("code")
             cls_props[exception_name] = exception_cls
             if code:
                 code_to_exception[code] = exception_cls
             else:
                 # Use the exception name if there is no explicit code
                 # modeled
                 code_to_exception[exception_name] = exception_cls
     cls_name = str(get_service_module_name(service_model) + 'Exceptions')
     client_exceptions_cls = type(
         cls_name, (BaseClientExceptions,), cls_props)
     return client_exceptions_cls(code_to_exception)
Пример #13
0
 def _create_client_exceptions(self, service_model):
     cls_props = {}
     code_to_exception = {}
     for shape_name in service_model.shape_names:
         shape = service_model.shape_for(shape_name)
         if shape.metadata.get('exception', False):
             exception_name = str(shape.name)
             exception_cls = type(exception_name, (ClientError,), {})
             code = shape.metadata.get("error", {}).get("code")
             cls_props[exception_name] = exception_cls
             if code:
                 code_to_exception[code] = exception_cls
             else:
                 # Use the exception name if there is no explicit code
                 # modeled
                 code_to_exception[exception_name] = exception_cls
     cls_name = str(get_service_module_name(service_model) + 'Exceptions')
     client_exceptions_cls = type(
         cls_name, (BaseClientExceptions,), cls_props)
     return client_exceptions_cls(code_to_exception)
Пример #14
0
def document_load_reload_action(section,
                                action_name,
                                resource_name,
                                event_emitter,
                                load_model,
                                service_model,
                                include_signature=True):
    """Documents the resource load action

    :param section: The section to write to

    :param action_name: The name of the loading action should be load or reload

    :param resource_name: The name of the resource

    :param event_emitter: The event emitter to use to emit events

    :param load_model: The model of the load action

    :param service_model: The model of the service

    :param include_signature: Whether or not to include the signature.
        It is useful for generating docstrings.
    """
    description = (
        'Calls  :py:meth:`%s.Client.%s` to update the attributes of the'
        ' %s resource' %
        (get_service_module_name(service_model),
         xform_name(load_model.request.operation), resource_name))
    example_resource_name = xform_name(resource_name)
    if service_model.service_name == resource_name:
        example_resource_name = resource_name
    example_prefix = '%s.%s' % (example_resource_name, action_name)
    document_model_driven_method(section=section,
                                 method_name=action_name,
                                 operation_model=OperationModel({},
                                                                service_model),
                                 event_emitter=event_emitter,
                                 method_description=description,
                                 example_prefix=example_prefix,
                                 include_signature=include_signature)
Пример #15
0
def document_resource_waiter(section, resource_name, event_emitter,
                             service_model, resource_waiter_model,
                             service_waiter_model, include_signature=True):
    waiter_model = service_waiter_model.get_waiter(
        resource_waiter_model.waiter_name)
    operation_model = service_model.operation_model(
        waiter_model.operation)

    ignore_params = get_resource_ignore_params(resource_waiter_model.params)
    service_module_name = get_service_module_name(service_model)
    description = (
        'Waits until this %s is %s. This method calls '
        ':py:meth:`%s.Waiter.%s.wait` which polls. '
        ':py:meth:`%s.Client.%s` every %s seconds until '
        'a successful state is reached. An error is returned '
        'after %s failed checks.' % (
            resource_name, ' '.join(resource_waiter_model.name.split('_')[2:]),
            service_module_name,
            xform_name(resource_waiter_model.waiter_name),
            service_module_name,
            xform_name(waiter_model.operation),
            waiter_model.delay, waiter_model.max_attempts))
    example_prefix = '%s.%s' % (
        xform_name(resource_name), resource_waiter_model.name)
    document_model_driven_method(
        section=section, method_name=resource_waiter_model.name,
        operation_model=operation_model,
        event_emitter=event_emitter,
        example_prefix=example_prefix,
        method_description=description,
        exclude_input=ignore_params,
        include_signature=include_signature
    )
    if 'return' in section.available_sections:
        # Waiters do not return anything so we should remove
        # any sections that may document the underlying return
        # value of the client method.
        return_section = section.get_section('return')
        return_section.clear_text()
        return_section.remove_all_sections()
        return_section.write(':returns: None')
Пример #16
0
def document_load_reload_action(section, action_name, resource_name,
                                event_emitter, load_model, service_model,
                                include_signature=True):
    """Documents the resource load action

    :param section: The section to write to

    :param action_name: The name of the loading action should be load or reload

    :param resource_name: The name of the resource

    :param event_emitter: The event emitter to use to emit events

    :param load_model: The model of the load action

    :param service_model: The model of the service

    :param include_signature: Whether or not to include the signature.
        It is useful for generating docstrings.
    """
    description = (
        'Calls  :py:meth:`%s.Client.%s` to update the attributes of the'
        ' %s resource. Note that the load and reload methods are '
        'the same method and can be used interchangeably.' % (
            get_service_module_name(service_model),
            xform_name(load_model.request.operation),
            resource_name)
    )
    example_resource_name = xform_name(resource_name)
    if service_model.service_name == resource_name:
        example_resource_name = resource_name
    example_prefix = '%s.%s' % (example_resource_name, action_name)
    document_model_driven_method(
        section=section, method_name=action_name,
        operation_model=OperationModel({}, service_model),
        event_emitter=event_emitter,
        method_description=description,
        example_prefix=example_prefix,
        include_signature=include_signature
    )
def document_wait_method(section,
                         waiter_name,
                         event_emitter,
                         service_model,
                         service_waiter_model,
                         include_signature=True):
    """Documents a the wait method of a waiter

    :param section: The section to write to

    :param waiter_name: The name of the waiter

    :param event_emitter: The event emitter to use to emit events

    :param service_model: The service model

    :param service_waiter_model: The waiter model associated to the service

    :param include_signature: Whether or not to include the signature.
        It is useful for generating docstrings.
    """
    waiter_model = service_waiter_model.get_waiter(waiter_name)
    operation_model = service_model.operation_model(waiter_model.operation)

    wait_description = (
        'Polls :py:meth:`{0}.Client.{1}` every {2} '
        'seconds until a successful state is reached. An error is '
        'returned after {3} failed checks.'.format(
            get_service_module_name(service_model),
            xform_name(waiter_model.operation), waiter_model.delay,
            waiter_model.max_attempts))

    document_model_driven_method(section,
                                 'wait',
                                 operation_model,
                                 event_emitter=event_emitter,
                                 method_description=wait_description,
                                 example_prefix='waiter.wait',
                                 document_output=False,
                                 include_signature=include_signature)
Пример #18
0
def document_wait_method(section, waiter_name, event_emitter,
                         service_model, service_waiter_model,
                         include_signature=True):
    """Documents a the wait method of a waiter

    :param section: The section to write to

    :param waiter_name: The name of the waiter

    :param event_emitter: The event emitter to use to emit events

    :param service_model: The service model

    :param service_waiter_model: The waiter model associated to the service

    :param include_signature: Whether or not to include the signature.
        It is useful for generating docstrings.
    """
    waiter_model = service_waiter_model.get_waiter(waiter_name)
    operation_model = service_model.operation_model(
        waiter_model.operation)

    wait_description = (
        'Polls :py:meth:`{0}.Client.{1}` every {2} '
        'seconds until a successful state is reached. An error is '
        'returned after {3} failed checks.'.format(
            get_service_module_name(service_model),
            xform_name(waiter_model.operation),
            waiter_model.delay, waiter_model.max_attempts)
    )

    document_model_driven_method(
        section, 'wait', operation_model,
        event_emitter=event_emitter,
        method_description=wait_description,
        example_prefix='waiter.wait',
        document_output=False,
        include_signature=include_signature
    )
Пример #19
0
 def test_client_name_with_non_alphabet_characters(self):
     self.service_description['metadata']['serviceFullName'] = (
         'Amazon My-Service')
     self.assertEqual(get_service_module_name(self.service_model),
                      'MyService')
Пример #20
0
 def test_client_name_with_no_full_name_or_abbreviation(self):
     del self.service_description['metadata']['serviceFullName']
     self.assertEqual(
         get_service_module_name(self.service_model),
         'myservice'
     )
Пример #21
0
 def test_default(self):
     self.assertEqual(
         get_service_module_name(self.service_model),
         'MyService'
     )
Пример #22
0
def document_wait_method(section,
                         waiter_name,
                         event_emitter,
                         service_model,
                         service_waiter_model,
                         include_signature=True):
    """Documents a the wait method of a waiter

    :param section: The section to write to

    :param waiter_name: The name of the waiter

    :param event_emitter: The event emitter to use to emit events

    :param service_model: The service model

    :param service_waiter_model: The waiter model associated to the service

    :param include_signature: Whether or not to include the signature.
        It is useful for generating docstrings.
    """
    waiter_model = service_waiter_model.get_waiter(waiter_name)
    operation_model = service_model.operation_model(waiter_model.operation)

    waiter_config_members = OrderedDict()

    waiter_config_members['Delay'] = DocumentedShape(
        name='Delay',
        type_name='integer',
        documentation=('<p>The amount of time in seconds to wait between '
                       'attempts. Default: {0}</p>'.format(
                           waiter_model.delay)))

    waiter_config_members['MaxAttempts'] = DocumentedShape(
        name='MaxAttempts',
        type_name='integer',
        documentation=('<p>The maximum number of attempts to be made. '
                       'Default: {0}</p>'.format(waiter_model.max_attempts)))

    botocore_waiter_params = [
        DocumentedShape(
            name='WaiterConfig',
            type_name='structure',
            documentation=(
                '<p>A dictionary that provides parameters to control '
                'waiting behavior.</p>'),
            members=waiter_config_members)
    ]

    wait_description = (
        'Polls :py:meth:`{0}.Client.{1}` every {2} '
        'seconds until a successful state is reached. An error is '
        'returned after {3} failed checks.'.format(
            get_service_module_name(service_model),
            xform_name(waiter_model.operation), waiter_model.delay,
            waiter_model.max_attempts))

    document_model_driven_method(section,
                                 'wait',
                                 operation_model,
                                 event_emitter=event_emitter,
                                 method_description=wait_description,
                                 example_prefix='waiter.wait',
                                 include_input=botocore_waiter_params,
                                 document_output=False,
                                 include_signature=include_signature)
Пример #23
0
def document_sub_resource(section, resource_name, sub_resource_model,
                          service_model, include_signature=True):
    """Documents a resource action

    :param section: The section to write to

    :param resource_name: The name of the resource

    :param sub_resource_model: The model of the subresource

    :param service_model: The model of the service

    :param include_signature: Whether or not to include the signature.
        It is useful for generating docstrings.
    """
    identifiers_needed = []
    for identifier in sub_resource_model.resource.identifiers:
        if identifier.source == 'input':
            identifiers_needed.append(xform_name(identifier.target))

    if include_signature:
        signature_args = get_identifier_args_for_signature(identifiers_needed)
        section.style.start_sphinx_py_method(
            sub_resource_model.name, signature_args)

    method_intro_section = section.add_new_section(
        'method-intro')
    description = 'Creates a %s resource.' % sub_resource_model.resource.type
    method_intro_section.include_doc_string(description)
    example_section = section.add_new_section('example')
    example_values = get_identifier_values_for_example(identifiers_needed)
    example_resource_name = xform_name(resource_name)
    if service_model.service_name == resource_name:
        example_resource_name = resource_name
    example = '%s = %s.%s(%s)' % (
        xform_name(sub_resource_model.resource.type),
        example_resource_name,
        sub_resource_model.name, example_values
    )
    example_section.style.start_codeblock()
    example_section.write(example)
    example_section.style.end_codeblock()

    param_section = section.add_new_section('params')
    for identifier in identifiers_needed:
        description = get_identifier_description(
            sub_resource_model.name, identifier)
        param_section.write(':type %s: string' % identifier)
        param_section.style.new_line()
        param_section.write(':param %s: %s' % (
            identifier, description))
        param_section.style.new_line()

    return_section = section.add_new_section('return')
    return_section.style.new_line()
    return_section.write(
        ':rtype: :py:class:`%s.%s`' % (
            get_service_module_name(service_model),
            sub_resource_model.resource.type))
    return_section.style.new_line()
    return_section.write(
        ':returns: A %s resource' % sub_resource_model.resource.type)
    return_section.style.new_line()
def document_paginate_method(section,
                             paginator_name,
                             event_emitter,
                             service_model,
                             paginator_config,
                             include_signature=True):
    """Documents the paginate method of a paginator

    :param section: The section to write to

    :param paginator_name: The name of the paginator. It is snake cased.

    :param event_emitter: The event emitter to use to emit events

    :param service_model: The service model

    :param paginator_config: The paginator config associated to a particular
        paginator.

    :param include_signature: Whether or not to include the signature.
        It is useful for generating docstrings.
    """
    # Retrieve the operation model of the underlying operation.
    operation_model = service_model.operation_model(paginator_name)

    # Add representations of the request and response parameters
    # we want to include in the description of the paginate method.
    # These are parameters we expose via the botocore interface.
    pagination_config_members = OrderedDict()

    pagination_config_members['MaxItems'] = DocumentedShape(
        name='MaxItems',
        type_name='integer',
        documentation=('<p>The total number of items to return. If the total '
                       'number of items available is more than the value '
                       'specified in max-items then a <code>NextToken</code> '
                       'will be provided in the output that you can use to '
                       'resume pagination.</p>'))

    pagination_config_members['PageSize'] = DocumentedShape(
        name='PageSize',
        type_name='integer',
        documentation='<p>The size of each page.<p>')

    pagination_config_members['StartingToken'] = DocumentedShape(
        name='StartingToken',
        type_name='string',
        documentation=('<p>A token to specify where to start paginating. '
                       'This is the <code>NextToken</code> from a previous '
                       'response.</p>'))

    botocore_pagination_params = [
        DocumentedShape(
            name='PaginationConfig',
            type_name='structure',
            documentation=(
                '<p>A dictionary that provides parameters to control '
                'pagination.</p>'),
            members=pagination_config_members)
    ]

    botocore_pagination_response_params = [
        DocumentedShape(name='NextToken',
                        type_name='string',
                        documentation=('<p>A token to resume pagination.</p>'))
    ]

    service_pagination_params = []

    # Add the normal input token of the method to a list
    # of input paramters that we wish to hide since we expose our own.
    if isinstance(paginator_config['input_token'], list):
        service_pagination_params += paginator_config['input_token']
    else:
        service_pagination_params.append(paginator_config['input_token'])

    # Hide the limit key in the documentation.
    if paginator_config.get('limit_key', None):
        service_pagination_params.append(paginator_config['limit_key'])

    # Hide the output tokens in the documentation.
    service_pagination_response_params = []
    if isinstance(paginator_config['output_token'], list):
        service_pagination_response_params += paginator_config['output_token']
    else:
        service_pagination_response_params.append(
            paginator_config['output_token'])

    paginate_description = (
        'Creates an iterator that will paginate through responses '
        'from :py:meth:`{0}.Client.{1}`.'.format(
            get_service_module_name(service_model),
            xform_name(paginator_name)))

    document_model_driven_method(
        section,
        'paginate',
        operation_model,
        event_emitter=event_emitter,
        method_description=paginate_description,
        example_prefix='response_iterator = paginator.paginate',
        include_input=botocore_pagination_params,
        include_output=botocore_pagination_response_params,
        exclude_input=service_pagination_params,
        exclude_output=service_pagination_response_params,
        include_signature=include_signature)
Пример #25
0
def document_sub_resource(section,
                          resource_name,
                          sub_resource_model,
                          service_model,
                          include_signature=True):
    """Documents a resource action

    :param section: The section to write to

    :param resource_name: The name of the resource

    :param sub_resource_model: The model of the subresource

    :param service_model: The model of the service

    :param include_signature: Whether or not to include the signature.
        It is useful for generating docstrings.
    """
    identifiers_needed = []
    for identifier in sub_resource_model.resource.identifiers:
        if identifier.source == 'input':
            identifiers_needed.append(xform_name(identifier.target))

    if include_signature:
        signature_args = get_identifier_args_for_signature(identifiers_needed)
        section.style.start_sphinx_py_method(sub_resource_model.name,
                                             signature_args)

    method_intro_section = section.add_new_section('method-intro')
    description = 'Creates a %s resource.' % sub_resource_model.resource.type
    method_intro_section.include_doc_string(description)
    example_section = section.add_new_section('example')
    example_values = get_identifier_values_for_example(identifiers_needed)
    example_resource_name = xform_name(resource_name)
    if service_model.service_name == resource_name:
        example_resource_name = resource_name
    example = '%s = %s.%s(%s)' % (xform_name(
        sub_resource_model.resource.type), example_resource_name,
                                  sub_resource_model.name, example_values)
    example_section.style.start_codeblock()
    example_section.write(example)
    example_section.style.end_codeblock()

    param_section = section.add_new_section('params')
    for identifier in identifiers_needed:
        description = get_identifier_description(sub_resource_model.name,
                                                 identifier)
        param_section.write(':type %s: string' % identifier)
        param_section.style.new_line()
        param_section.write(':param %s: %s' % (identifier, description))
        param_section.style.new_line()

    return_section = section.add_new_section('return')
    return_section.style.new_line()
    return_section.write(':rtype: :py:class:`%s.%s`' %
                         (get_service_module_name(service_model),
                          sub_resource_model.resource.type))
    return_section.style.new_line()
    return_section.write(':returns: A %s resource' %
                         sub_resource_model.resource.type)
    return_section.style.new_line()
Пример #26
0
def document_wait_method(section, waiter_name, event_emitter,
                         service_model, service_waiter_model,
                         include_signature=True):
    """Documents a the wait method of a waiter

    :param section: The section to write to

    :param waiter_name: The name of the waiter

    :param event_emitter: The event emitter to use to emit events

    :param service_model: The service model

    :param service_waiter_model: The waiter model associated to the service

    :param include_signature: Whether or not to include the signature.
        It is useful for generating docstrings.
    """
    waiter_model = service_waiter_model.get_waiter(waiter_name)
    operation_model = service_model.operation_model(
        waiter_model.operation)

    waiter_config_members = OrderedDict()

    waiter_config_members['Delay'] = DocumentedShape(
        name='Delay', type_name='integer',
        documentation=(
            '<p>The amount of time in seconds to wait between '
            'attempts. Default: {0}</p>'.format(waiter_model.delay)))

    waiter_config_members['MaxAttempts'] = DocumentedShape(
        name='MaxAttempts', type_name='integer',
        documentation=(
            '<p>The maximum number of attempts to be made. '
            'Default: {0}</p>'.format(waiter_model.max_attempts)))

    botocore_waiter_params = [
        DocumentedShape(
            name='WaiterConfig', type_name='structure',
            documentation=(
                '<p>A dictionary that provides parameters to control '
                'waiting behavior.</p>'),
            members=waiter_config_members)
    ]

    wait_description = (
        'Polls :py:meth:`{0}.Client.{1}` every {2} '
        'seconds until a successful state is reached. An error is '
        'returned after {3} failed checks.'.format(
            get_service_module_name(service_model),
            xform_name(waiter_model.operation),
            waiter_model.delay, waiter_model.max_attempts)
    )

    document_model_driven_method(
        section, 'wait', operation_model,
        event_emitter=event_emitter,
        method_description=wait_description,
        example_prefix='waiter.wait',
        include_input=botocore_waiter_params,
        document_output=False,
        include_signature=include_signature
    )
Пример #27
0
 def test_default(self):
     self.assertEqual(get_service_module_name(self.service_model),
                      'MyService')
Пример #28
0
def document_paginate_method(section, paginator_name, event_emitter,
                             service_model, paginator_config,
                             include_signature=True):
    """Documents the paginate method of a paginator

    :param section: The section to write to

    :param paginator_name: The name of the paginator. It is snake cased.

    :param event_emitter: The event emitter to use to emit events

    :param service_model: The service model

    :param paginator_config: The paginator config associated to a particular
        paginator.

    :param include_signature: Whether or not to include the signature.
        It is useful for generating docstrings.
    """
    # Retrieve the operation model of the underlying operation.
    operation_model = service_model.operation_model(
        paginator_name)

    # Add representations of the request and response parameters
    # we want to include in the description of the paginate method.
    # These are parameters we expose via the botocore interface.
    pagination_config_members = OrderedDict()

    pagination_config_members['MaxItems'] = DocumentedShape(
        name='MaxItems', type_name='integer',
        documentation=(
            '<p>The total number of items to return. If the total '
            'number of items available is more than the value '
            'specified in max-items then a <code>NextToken</code> '
            'will be provided in the output that you can use to '
            'resume pagination.</p>'))

    pagination_config_members['PageSize'] = DocumentedShape(
        name='PageSize', type_name='integer',
        documentation='<p>The size of each page.<p>')

    pagination_config_members['StartingToken'] = DocumentedShape(
        name='StartingToken', type_name='string',
        documentation=(
            '<p>A token to specify where to start paginating. '
            'This is the <code>NextToken</code> from a previous '
            'response.</p>'))

    botocore_pagination_params = [
        DocumentedShape(
            name='PaginationConfig', type_name='structure',
            documentation=(
                '<p>A dictionary that provides parameters to control '
                'pagination.</p>'),
            members=pagination_config_members)
    ]

    botocore_pagination_response_params = [
        DocumentedShape(
            name='NextToken', type_name='string',
            documentation=(
                '<p>A token to resume pagination.</p>'))
    ]

    service_pagination_params = []

    # Add the normal input token of the method to a list
    # of input paramters that we wish to hide since we expose our own.
    if isinstance(paginator_config['input_token'], list):
        service_pagination_params += paginator_config['input_token']
    else:
        service_pagination_params.append(paginator_config['input_token'])

    # Hide the limit key in the documentation.
    if paginator_config.get('limit_key', None):
        service_pagination_params.append(paginator_config['limit_key'])

    # Hide the output tokens in the documentation.
    service_pagination_response_params = []
    if isinstance(paginator_config['output_token'], list):
        service_pagination_response_params += paginator_config[
            'output_token']
    else:
        service_pagination_response_params.append(paginator_config[
            'output_token'])

    paginate_description = (
        'Creates an iterator that will paginate through responses '
        'from :py:meth:`{0}.Client.{1}`.'.format(
            get_service_module_name(service_model), xform_name(paginator_name))
    )

    document_model_driven_method(
        section, 'paginate', operation_model,
        event_emitter=event_emitter,
        method_description=paginate_description,
        example_prefix='response_iterator = paginator.paginate',
        include_input=botocore_pagination_params,
        include_output=botocore_pagination_response_params,
        exclude_input=service_pagination_params,
        exclude_output=service_pagination_response_params,
        include_signature=include_signature
    )
Пример #29
0
 def test_client_name_with_no_full_name_or_abbreviation(self):
     del self.service_description['metadata']['serviceFullName']
     self.assertEqual(get_service_module_name(self.service_model),
                      'myservice')
Пример #30
0
 def test_client_name_using_abreviation(self):
     self.service_description['metadata']['serviceAbbreviation'] = (
         'Abbreviation')
     self.assertEqual(get_service_module_name(self.service_model),
                      'Abbreviation')