o
    /_Wcq.                     @   s   d dl Z d dlmZmZ ddlmZ ddlmZmZm	Z	m
Z
 ddlmZ ddlmZmZ e jrGd dl mZmZmZ dd	lmZ ed
ZedZG dd deZdS )    N)ABCMetaabstractmethod   )RuntimeConfigurationBuilder)AbstractRequestHandlerAbstractRequestInterceptorAbstractResponseInterceptorAbstractExceptionHandler)SkillBuilderException)AbstractTemplateLoaderAbstractTemplateRenderer)CallableTypeVarList)AbstractSkillTInputc                   @   s   e Zd ZdZeZdd Zdd Zdd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zedd ZdS )AbstractSkillBuilderzAbstract Skill Builder with helper functions for building
    :py:class:`ask_sdk_runtime.skill.AbstractSkill` object.

    Domain SDKs has to implement the `create` method that returns
    an instance of the skill implementation for the domain type.
    c                 C   s   t  | _d S N)r   runtime_configuration_builderself r   ?D:\Flask\env\Lib\site-packages\ask_sdk_runtime/skill_builder.py__init__/   s   zAbstractSkillBuilder.__init__c                 C      | j | dS )a  Register input to the request handlers list.

        :param request_handler: Request Handler instance to be
            registered.
        :type request_handler: ask_sdk_runtime.dispatch_components.request_components.AbstractRequestHandler
        :return: None
        N)r   add_request_handler)r   request_handlerr   r   r   r   3      	z(AbstractSkillBuilder.add_request_handlerc                 C   r   )a  Register input to the exception handlers list.

        :param exception_handler: Exception Handler instance to be
            registered.
        :type exception_handler: ask_sdk_runtime.dispatch_components.request_components.AbstractExceptionHandler
        :return: None
        N)r   add_exception_handler)r   exception_handlerr   r   r   r   ?   r   z*AbstractSkillBuilder.add_exception_handlerc                 C   r   )a+  Register input to the global request interceptors list.

        :param request_interceptor: Request Interceptor instance to be
            registered.
        :type request_interceptor: ask_sdk_runtime.dispatch_components.request_components.AbstractRequestInterceptor
        :return: None
        N)r   add_global_request_interceptor)r   request_interceptorr   r   r   r!   K   r   z3AbstractSkillBuilder.add_global_request_interceptorc                 C   r   )a0  Register input to the global response interceptors list.

        :param response_interceptor: Response Interceptor instance to
            be registered.
        :type response_interceptor: ask_sdk_runtime.dispatch_components.request_components.AbstractResponseInterceptor
        :return: None
        N)r   add_global_response_interceptor)r   response_interceptorr   r   r   r#   W   r   z4AbstractSkillBuilder.add_global_response_interceptorc                 C   r   )zRegister input to the loaders list.

        :param loaders: List of loaders
        :type loaders:  :py:class:`ask_sdk_runtime.view_resolvers.AbstractTemplateLoader`
        N)r   add_loaders)r   loadersr   r   r   r%   c      z AbstractSkillBuilder.add_loadersc                 C   r   )zRegister input to loaders list.

        :param loader: Loader to load template from a specific data source
        :type loader: :py:class:`ask_sdk_runtime.view_resolvers.AbstractTemplateLoader`
        N)r   
add_loader)r   loaderr   r   r   r(   l   r'   zAbstractSkillBuilder.add_loaderc                 C   r   )zRegister renderer to generate template responses.

        :param renderer: Renderer to render the template
        :type renderer:  :py:class:`ask_sdk_runtime.view_resolvers.AbstractTemplateRenderer`
        N)r   add_renderer)r   rendererr   r   r   r*   u   r'   z!AbstractSkillBuilder.add_rendererc                        fdd}|S )aa  Decorator that can be used to add request handlers easily to
        the builder.

        The can_handle_func has to be a Callable instance, which takes
        a single parameter and no varargs or kwargs. This is because
        of the RequestHandler class signature restrictions. The
        returned wrapper function can be applied as a decorator on any
        function that returns a response object by the skill. The
        function should follow the signature of the handle function in
        :py:class:`ask_sdk_runtime.dispatch_components.request_components.AbstractRequestHandler`
        class.

        :param can_handle_func: The function that validates if the
            request can be handled.
        :type can_handle_func: Callable[[Input], bool]
        :return: Wrapper function that can be decorated on a handle
            function.
        c                    f   t rt  stdfdd fddd}td j ddtf|}j| d	  S )
NzSRequest Handler can_handle_func and handle_func input parameters should be callablec                        |S r   r   r   handler_inputcan_handle_funcr   r   <lambda>       zGAbstractSkillBuilder.request_handler.<locals>.wrapper.<locals>.<lambda>c                    r.   r   r   r/   handle_funcr   r   r3      r4   Z
can_handlehandlezRequestHandler{}_ )r   )	callabler
   typeformat__name__titlereplacer   r   )r6   class_attributesZrequest_handler_classr2   r   r5   r   wrapper   s   

z5AbstractSkillBuilder.request_handler.<locals>.wrapperr   r   r2   rC   r   rB   r   r   ~   s   z$AbstractSkillBuilder.request_handlerc                    r,   )a  Decorator that can be used to add exception handlers easily
        to the builder.

        The can_handle_func has to be a Callable instance, which takes
        two parameters and no varargs or kwargs. This is because of the
        ExceptionHandler class signature restrictions. The returned
        wrapper function can be applied as a decorator on any function
        that processes the exception raised during dispatcher and
        returns a response object by the skill. The function should
        follow the signature of the handle function in
        :py:class:`ask_sdk_runtime.dispatch_components.exception_components.AbstractExceptionHandler`
        class.

        :param can_handle_func: The function that validates if the
            exception can be handled.
        :type can_handle_func: Callable[[Input, Exception], bool]
        :return: Wrapper function that can be decorated on a handle
            function.
        c                    r-   )
NzUException Handler can_handle_func and handle_func input parameters should be callablec                    
    ||S r   r   r   r0   	exceptionr1   r   r   r3          zIAbstractSkillBuilder.exception_handler.<locals>.wrapper.<locals>.<lambda>c                    rE   r   r   rF   r5   r   r   r3      rH   r7   zExceptionHandler{}r9   r:   )r    )	r;   r
   r<   r=   r>   r?   r@   r	   r   )r6   rA   Zexception_handler_classrB   r5   r   rC      s"   

z7AbstractSkillBuilder.exception_handler.<locals>.wrapperr   rD   r   rB   r   r       s   z&AbstractSkillBuilder.exception_handlerc                        fdd}|S )a  Decorator that can be used to add global request
        interceptors easily to the builder.

        The returned wrapper function can be applied as a decorator on
        any function that processes the input. The function should
        follow the signature of the process function in
        :py:class:`ask_sdk_runtime.dispatch_components.request_components.AbstractRequestInterceptor`
        class.

        :return: Wrapper function that can be decorated on a
            interceptor process function.
        c                    T   t  stdd fddi}td j ddtf|}j| d  S )	NzJGlobal Request Interceptor process_func input parameter should be callableprocessc                    r.   r   r   r/   process_funcr   r   r3      r4   zRAbstractSkillBuilder.global_request_interceptor.<locals>.wrapper.<locals>.<lambda>zRequestInterceptor{}r9   r:   )r"   )	r;   r
   r<   r=   r>   r?   r@   r   r!   )rM   rA   r"   r   rL   r   rC      s    z@AbstractSkillBuilder.global_request_interceptor.<locals>.wrapperr   r   rC   r   r   r   global_request_interceptor   s   z/AbstractSkillBuilder.global_request_interceptorc                    rI   )aA  Decorator that can be used to add global
        response interceptors easily to the builder.

        The returned wrapper function can be applied as a decorator
        on any function that processes the input and the response
        generated by the request handler. The function should follow
        the signature of the process function in
        :py:class:`ask_sdk_runtime.dispatch_components.request_components.AbstractResponseInterceptor`
        class.

        :return: Wrapper function that can be decorated on a
            interceptor process function.
        c                    rJ   )	NzKGlobal Response Interceptor process_func input parameter should be callablerK   c                    rE   r   r   )r   r0   responserL   r   r   r3     rH   zSAbstractSkillBuilder.global_response_interceptor.<locals>.wrapper.<locals>.<lambda>zResponseInterceptor{}r9   r:   )r$   )	r;   r
   r<   r=   r>   r?   r@   r   r#   )rM   rA   r$   r   rL   r   rC     s"   
zAAbstractSkillBuilder.global_response_interceptor.<locals>.wrapperr   rN   r   r   r   global_response_interceptor   s   z0AbstractSkillBuilder.global_response_interceptorc                 C   s   t )zCreate a skill object using the registered components.

        :return: a skill object that can be used for invocation.
        :rtype: AbstractSkill
        )NotImplementedErrorr   r   r   r   create  s   zAbstractSkillBuilder.createN)r>   
__module____qualname____doc__r   __metaclass__r   r   r   r!   r#   r%   r(   r*   r   r    rO   rQ   r   rS   r   r   r   r   r   &   s"    			*-#%r   )typingabcr   r   Zskillr   Zdispatch_componentsr   r   r   r	   
exceptionsr
   Zview_resolversr   r   TYPE_CHECKINGr   r   r   r   r   r   objectr   r   r   r   r   <module>   s   