U
    ÌZjq.  ã                   @   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rŽd 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 )ÚAbstractSkillBuilderzþAbstract 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   ú`/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/ask_sdk_runtime/skill_builder.pyÚ__init__/   s    zAbstractSkillBuilder.__init__c                 C   s   | 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   s    	ÿz(AbstractSkillBuilder.add_request_handlerc                 C   s   | j  |¡ dS )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   ?   s    	ÿz*AbstractSkillBuilder.add_exception_handlerc                 C   s   | j  |¡ dS )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   s    	ÿz3AbstractSkillBuilder.add_global_request_interceptorc                 C   s   | j  |¡ dS )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   s    	ÿz4AbstractSkillBuilder.add_global_response_interceptorc                 C   s   | j  |¡ dS )z¯Register 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   s    z AbstractSkillBuilder.add_loadersc                 C   s   | j  |¡ dS )zÌRegister 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   s    zAbstractSkillBuilder.add_loaderc                 C   s   | j  |¡ dS )zÑRegister 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   s    z!AbstractSkillBuilder.add_rendererc                    s   ‡ ‡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                    sf   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   ˆ |ƒS r   r   ©r   Úhandler_input©Úcan_handle_funcr   r   Ú<lambda>™   s   ÿzGAbstractSkillBuilder.request_handler.<locals>.wrapper.<locals>.<lambda>c                    s   ˆ |ƒS r   r   r)   ©Úhandle_funcr   r   r-   ›   s   ÿ©Z
can_handleÚhandlezRequestHandler{}Ú_Ú )r   )	Úcallabler
   ÚtypeÚformatÚ__name__ÚtitleÚreplacer   r   )r/   Úclass_attributesZrequest_handler_class©r,   r   r.   r   Úwrapper’   s     ÿ

ýÿ ýz5AbstractSkillBuilder.request_handler.<locals>.wrapperr   ©r   r,   r<   r   r;   r   r   ~   s    z$AbstractSkillBuilder.request_handlerc                    s   ‡ ‡fdd„}|S )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                    sf   t ˆƒrt ˆ ƒstdƒ‚‡fdd„‡ fdd„dœ}td ˆ j ¡  dd¡¡tf|ƒ}ˆj|ƒ d	� ˆ S )
NzUException Handler can_handle_func and handle_func input parameters should be callablec                    s
   ˆ ||ƒS r   r   ©r   r*   Ú	exceptionr+   r   r   r-   Å   s    ÿzIAbstractSkillBuilder.exception_handler.<locals>.wrapper.<locals>.<lambda>c                    s
   ˆ ||ƒS r   r   r>   r.   r   r   r-   Ç   s    ÿr0   zExceptionHandler{}r2   r3   )r   )	r4   r
   r5   r6   r7   r8   r9   r	   r   )r/   r:   Zexception_handler_classr;   r.   r   r<   ½   s$    ÿ

üÿ ýÿz7AbstractSkillBuilder.exception_handler.<locals>.wrapperr   r=   r   r;   r   r   ¨   s    z&AbstractSkillBuilder.exception_handlerc                    s   ‡ 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                    sT   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                    s   ˆ |ƒS r   r   r)   ©Úprocess_funcr   r   r-   ê   s   ÿzRAbstractSkillBuilder.global_request_interceptor.<locals>.wrapper.<locals>.<lambda>zRequestInterceptor{}r2   r3   )r    )	r4   r
   r5   r6   r7   r8   r9   r   r   )rB   r:   r    r   rA   r   r<   ã   s$    ÿ 
ÿÿ ýÿz@AbstractSkillBuilder.global_request_interceptor.<locals>.wrapperr   ©r   r<   r   r   r   Úglobal_request_interceptorÕ   s    z/AbstractSkillBuilder.global_request_interceptorc                    s   ‡ fdd„}|S )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                    sT   t ˆ ƒstdƒ‚d‡ fdd„i}td ˆ j ¡  dd¡¡tf|ƒ}ˆj|ƒ d� ˆ S )	NzKGlobal Response Interceptor process_func input parameter should be callabler@   c                    s
   ˆ ||ƒS r   r   )r   r*   ÚresponserA   r   r   r-     s    ÿzSAbstractSkillBuilder.global_response_interceptor.<locals>.wrapper.<locals>.<lambda>zResponseInterceptor{}r2   r3   )r"   )	r4   r
   r5   r6   r7   r8   r9   r   r!   )rB   r:   r"   r   rA   r   r<     s$    ÿ
þÿ ýÿzAAbstractSkillBuilder.global_response_interceptor.<locals>.wrapperr   rC   r   r   r   Úglobal_response_interceptorø   s    z0AbstractSkillBuilder.global_response_interceptorc                 C   s   t ‚dS )zŸCreate a skill object using the registered components.

        :return: a skill object that can be used for invocation.
        :rtype: AbstractSkill
        N)ÚNotImplementedErrorr   r   r   r   Úcreate  s    zAbstractSkillBuilder.createN)r7   Ú
__module__Ú__qualname__Ú__doc__r   Z__metaclass__r   r   r   r   r!   r#   r%   r'   r   r   rD   rF   r   rH   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   