U
    ÌZj/  ã                   @   sÂ   d dl mZmZmZmZ d dlmZmZ ddlm	Z	 ddl
mZmZmZmZmZmZmZmZ ddlmZmZ edƒZedƒZed	ƒZG d
d„ deƒZG dd„ deƒZG dd„ deeeef ƒZdS )é    )ÚListÚTypeVarÚAnyÚGeneric)ÚABCMetaÚabstractmethodé   )ÚRuntimeConfigException)ÚAbstractRequestHandlerÚAbstractRequestInterceptorÚAbstractResponseInterceptorÚAbstractExceptionHandlerÚGenericRequestHandlerChainÚGenericRequestMapperÚGenericHandlerAdapterÚGenericExceptionMapper)ÚAbstractTemplateLoaderÚAbstractTemplateRendererÚTÚ
SkillInputÚSkillOutputc                   @   s   e Zd ZdZddd„ZdS )ÚRuntimeConfigurationa   Configuration Object that represents standard components
    needed to build the dispatcher in the :py:class:`AbstractSkill`.

    :param request_mappers: List of request mapper instances.
    :type request_mappers: list(GenericRequestMapper)
    :param handler_adapters: List of handler adapter instances.
    :type handler_adapters: list(GenericHandlerAdapter)
    :param request_interceptors: List of
        request interceptor instances.
    :type request_interceptors: list(AbstractRequestInterceptor)
    :param response_interceptors: List of
        response interceptor instances.
    :type response_interceptors: list(AbstractResponseInterceptor)
    :param exception_mapper: Exception mapper instance.
    :type exception_mapper: GenericExceptionMapper
    Nc                 C   sj   |dkrg }|| _ |dkrg }|| _|dkr0g }|| _|dkrBg }|| _|| _|dkrZg }|| _|| _dS )aá  Configuration object that represents standard components
        needed for building :py:class:`Skill`.

        :param request_mappers: List of request mapper instances.
        :type request_mappers: list(GenericRequestMapper)
        :param handler_adapters: List of handler adapter instances.
        :type handler_adapters: list(GenericHandlerAdapter)
        :param request_interceptors: List of
            request interceptor instances.
        :type request_interceptors: list(AbstractRequestInterceptor)
        :param response_interceptors: List of
            response interceptor instances.
        :type response_interceptors: list(AbstractResponseInterceptor)
        :param exception_mapper: Exception mapper instance.
        :type exception_mapper: GenericExceptionMapper
        :param loaders: List of loaders instance.
        :type loaders: list(AbstractTemplateLoader)
        :param renderer: Renderer instance.
        :type renderer: AbstractTemplateRenderer
        N)Úrequest_mappersÚhandler_adaptersÚrequest_interceptorsÚresponse_interceptorsÚexception_mapperÚloadersÚrenderer)Úselfr   r   r   r   r   r   r   © r    úX/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/ask_sdk_runtime/skill.pyÚ__init__5   s"    zRuntimeConfiguration.__init__)NNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   r    r    r    r!   r   #   s           ýr   c                   @   s`   e Zd Z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S )ÚRuntimeConfigurationBuilderzbBuilder class for creating a runtime configuration object, from
    base dispatch components.
    c                 C   s(   g | _ g | _g | _g | _g | _d| _dS )zjBuilder class for creating a runtime configuration object,
        from base dispatch components.
        N)Úrequest_handler_chainsÚglobal_request_interceptorsÚglobal_response_interceptorsÚexception_handlersr   r   )r   r    r    r!   r"   l   s    z$RuntimeConfigurationBuilder.__init__c                 C   s8   |dkrt dƒ‚t|tƒs"t dƒ‚| j t|d�¡ dS )zÙRegister input to the request handlers list.

        :param request_handler: Request Handler instance to be
            registered.
        :type request_handler: AbstractRequestHandler
        :return: None
        Nz-Valid Request Handler instance to be providedz)Input should be a RequestHandler instance)Úrequest_handler)r	   Ú
isinstancer
   r(   Úappendr   )r   r,   r    r    r!   Úadd_request_handlerx   s    	ÿ
ÿÿz/RuntimeConfigurationBuilder.add_request_handlerc                 C   s   |D ]}|   |¡ qdS )zêRegister input to the request handlers list.

        :param request_handlers: List of Request Handler instances to be
            registered.
        :type request_handlers: list(AbstractRequestHandler)
        :return: None
        N)r/   )r   Zrequest_handlersr,   r    r    r!   Úadd_request_handlersŒ   s    	z0RuntimeConfigurationBuilder.add_request_handlersc                 C   s2   |dkrt dƒ‚t|tƒs"t dƒ‚| j |¡ dS )zãRegister input to the exception handlers list.

        :param exception_handler: Exception Handler instance to be
            registered.
        :type exception_handler: AbstractExceptionHandler
        :return: None
        Nz/Valid Exception Handler instance to be providedz,Input should be an ExceptionHandler instance)r	   r-   r   r+   r.   )r   Zexception_handlerr    r    r!   Úadd_exception_handler˜   s    	ÿ
ÿz1RuntimeConfigurationBuilder.add_exception_handlerc                 C   s2   |dkrt dƒ‚t|tƒs"t dƒ‚| j |¡ dS )zôRegister input to the global request interceptors list.

        :param request_interceptor: Request Interceptor instance to be
            registered.
        :type request_interceptor: AbstractRequestInterceptor
        :return: None
        Nz1Valid Request Interceptor instance to be providedz-Input should be a RequestInterceptor instance)r	   r-   r   r)   r.   )r   Zrequest_interceptorr    r    r!   Úadd_global_request_interceptor«   s    	ÿ
ÿz:RuntimeConfigurationBuilder.add_global_request_interceptorc                 C   s2   |dkrt dƒ‚t|tƒs"t dƒ‚| j |¡ dS )zùRegister input to the global response interceptors list.

        :param response_interceptor: Response Interceptor instance to
            be registered.
        :type response_interceptor: AbstractResponseInterceptor
        :return: None
        Nz2Valid Response Interceptor instance to be providedz.Input should be a ResponseInterceptor instance)r	   r-   r   r*   r.   )r   Zresponse_interceptorr    r    r!   Úadd_global_response_interceptor¾   s    	ÿ
ÿz;RuntimeConfigurationBuilder.add_global_response_interceptorc                 C   s8   |dkrt dƒ‚t|tƒs(t d |¡ƒ‚| j |¡ dS )z¹Register input to the loaders list.

        :param loader: Loader to load the template
        :type loader:  :py:class:`ask_sdk_runtime.view_resolvers.AbstractTemplateLoader`
        Nz$Valid Loader instance to be providedz.{} should be a AbstractTemplateLoader instance)r	   r-   r   Úformatr   r.   )r   Úloaderr    r    r!   Ú
add_loaderÑ   s    ÿ
ÿz&RuntimeConfigurationBuilder.add_loaderc                 C   s   |D ]}|   |¡ q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)r6   )r   r   r5   r    r    r!   Úadd_loadersâ   s    z'RuntimeConfigurationBuilder.add_loadersc                 C   s,   |dkrt dƒ‚t|tƒs"t dƒ‚|| _dS )z¿Register input to the renderer.

        :param renderer: Renderer to render the template
        :type renderer:  :py:class:`ask_sdk_runtime.view_resolvers.AbstractTemplateRenderer`
        Nz&Valid Renderer instance to be providedz3Input should be a AbstractTemplateRenderer instance)r	   r-   r   r   )r   r   r    r    r!   Úadd_rendererì   s    ÿ
ÿz(RuntimeConfigurationBuilder.add_rendererc              	   C   sD   t | jd�}t| jd�}tƒ }t|g|g|| j| j| j| j	d�}|S )z«Build the runtime configuration object from the registered
        components.

        :return: Runtime Configuration Object
        :rtype: RuntimeConfiguration
        )r(   )r+   )r   r   r   r   r   r   r   )
r   r(   r   r+   r   r   r)   r*   r   r   )r   Zrequest_mapperr   Zhandler_adapterZruntime_configurationr    r    r!   Úget_runtime_configurationý   s"    ÿÿù	z5RuntimeConfigurationBuilder.get_runtime_configurationN)r#   r$   r%   r&   r"   r/   r0   r1   r2   r3   r6   r7   r8   r9   r    r    r    r!   r'   g   s   
r'   c                   @   s,   e Zd ZdZeZedd„ ƒZedd„ ƒZdS )ÚAbstractSkillz—Abstract class that acts as entry level container for skill
    invocation.

    Domain SDKs should implement the `supports` and `invoke` methods.
    c                 C   s   t ‚dS )ag  Check if the skill supports the corresponding input.

        :param event: input instance containing request information.
        :type event: SkillInput
        :param context: Context passed during invocation
        :type context: Any
        :return: boolean if this type of request can be handled by this
            skill.
        :rtype: bool
        N©ÚNotImplementedError©r   ÚeventÚcontextr    r    r!   Úsupports  s    zAbstractSkill.supportsc                 C   s   t ‚dS )an  Invokes the dispatcher, to handle the skill input and
        return a skill output.

        :param event: input instance containing request information.
        :type event: SkillInput
        :param context: Context passed during invocation
        :type context: Any
        :return: output generated by handling the request.
        :rtype: SkillOutput
        Nr;   r=   r    r    r!   Úinvoke.  s    zAbstractSkill.invokeN)	r#   r$   r%   r&   r   Z__metaclass__r   r@   rA   r    r    r    r!   r:     s   
r:   N)Útypingr   r   r   r   Úabcr   r   Ú
exceptionsr	   Zdispatch_componentsr
   r   r   r   r   r   r   r   Zview_resolversr   r   r   r   r   Úobjectr   r'   r:   r    r    r    r!   Ú<module>   s   (D 1