U
    cc/                     @   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    9/tmp/pip-unpacked-wheel-yhqslwpj/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 )zRegister 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 )zRegister 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 )zRegister 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 )zRegister 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 )zRegister 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 )zRegister 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 )zRegister 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 )zRegister 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 )zBuild 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 )AbstractSkillzAbstract 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   __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