o
    i%                     @   s.  d Z ddlmZmZ ddlmZmZmZmZm	Z	m
Z
mZmZmZmZ ddlZddlZddlZddlmZmZ ddlmZmZ ddlmZmZmZmZmZmZ edZedeee	e gef f ZG d	d
 d
ej j!ej"j!Z#de	e dee de	e fddZ$de	e
e  dee
e  de	e
e  fddZ%dS )zPlugin module for Temporal SDK.

This module provides plugin functionality that allows customization of both client
and worker behavior in the Temporal SDK through configurable parameters.
    )AbstractAsyncContextManagerasynccontextmanager)
AnyAsyncIterator	AwaitableCallableOptionalSequenceTypeTypeVarUnioncastN)ClientConfigWorkflowHistory)ConnectConfigServiceClient)ReplayerReplayerConfigWorkerWorkerConfigWorkflowReplayResultWorkflowRunnerTc                   @   s  e Zd ZdZdddddddddd	dedeejj dee	ej
j  dee	e  dee	e  d	ee	e  d
ee dee	ejj  dee	ee   deeg ed f  ddfddZdefddZdedefddZdedeegee f dejjfddZdedefddZdedefddZ de!dee!ged f ddfddZ"e#d e$d!e%e& dee$e%e& gee%e'  f de%e%e'  fd"d#Z(dS )$SimplePluginzA simple plugin definition which has a limited set of configurations but makes it easier to produce
    a plugin which needs to configure them.
    N)	data_converterclient_interceptors
activitiesnexus_service_handlers	workflowsworkflow_runnerworker_interceptors workflow_failure_exception_typesrun_contextnamer   r   r   r   r   r   r    r!   r"   returnc       	         C   s@   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	dS )a  Create a simple plugin with configurable parameters. Each of the parameters will be applied to any
            component for which they are applicable. All arguments are optional, and all but run_context can also
            be callables for more complex modification. See the type PluginParameter above.
            For details on each argument, see below.

        Args:
            name: The name of the plugin.
            data_converter: Data converter for serialization, or callable to customize existing one.
                Applied to the Client and Replayer.
            client_interceptors: Client interceptors to append, or callable to customize existing ones.
                Applied to the Client. Note, if the provided interceptor is also a worker.Interceptor,
                it will be added to any worker which uses that client.
            activities: Activity functions to append, or callable to customize existing ones.
                Applied to the Worker.
            nexus_service_handlers: Nexus service handlers to append, or callable to customize existing ones.
                Applied to the Worker.
            workflows: Workflow classes to append, or callable to customize existing ones.
                Applied to the Worker and Replayer.
            workflow_runner: Workflow runner, or callable to customize existing one.
                Applied to the Worker and Replayer.
            worker_interceptors: Worker interceptors to append, or callable to customize existing ones.
                Applied to the Worker and Replayer.
            workflow_failure_exception_types: Exception types for workflow failures to append,
                or callable to customize existing ones. Applied to the Worker and Replayer.
            run_context: A place to run custom code to wrap around the Worker (or Replayer) execution.
                Specifically, it's an async context manager producer. Applied to the Worker and Replayer.

        Returns:
            A configured Plugin instance.
        N)
_namer   r   r   r   r   r   r    r!   r"   )selfr#   r   r   r   r   r   r   r    r!   r"    r'   W/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/temporalio/plugin.py__init__-   s   2
zSimplePlugin.__init__c                 C   s   | j S )See base class.)r%   )r&   r'   r'   r(   r#   j   s   zSimplePlugin.nameconfigc                 C   sD   t |d| j}|r||d< t|d| j}|dur ||d< |S )r*   r   interceptorsN)_resolve_parametergetr   _resolve_append_parameterr   )r&   r+   r   r,   r'   r'   r(   configure_clientn   s   zSimplePlugin.configure_clientnextc                    s   ||I dH S r*   Nr'   )r&   r+   r1   r'   r'   r(   connect_service_client~   s   z#SimplePlugin.connect_service_clientc                 C   s   t |d| j}|r||d< t |d| j}|dur ||d< t |d| j}|dur1||d< t|d| j}|r@||d< t |d| j}|durQ||d< t |d| j}|durb||d< |S )r*   r   r   Nr   r   r,   r!   )	r/   r.   r   r   r   r-   r   r    r!   )r&   r+   r   r   r   r   r,   failure_exception_typesr'   r'   r(   configure_worker   s<   zSimplePlugin.configure_workerc                 C   s   t |d| j}|r||d< t|d| j}|dur ||d< t |d| j}|r/||d< t|d| j}|dur@||d< t|d| j}|durQ||d< |S )r*   r   r   Nr   r,   r!   )r-   r.   r   r/   r   r   r    r!   )r&   r+   r   r   r   r,   r4   r'   r'   r(   configure_replayer   s2   zSimplePlugin.configure_replayerworkerc              	      sj   | j r,|   4 I dH  ||I dH  W d  I dH  dS 1 I dH s%w   Y  dS ||I dH  dS r2   r"   )r&   r7   r1   r'   r'   r(   
run_worker   s   .zSimplePlugin.run_workerreplayer	historiesc              
   C  s   | j rG|   4 I dH . |||4 I dH }|V  W d  I dH  n1 I dH s*w   Y  W d  I dH  dS 1 I dH s@w   Y  dS |||4 I dH }|V  W d  I dH  dS 1 I dH sew   Y  dS r2   r8   )r&   r:   r;   r1   resultsr'   r'   r(   run_replayer   s   *..zSimplePlugin.run_replayer))__name__
__module____qualname____doc__strPluginParameter
temporalio	converterDataConverterr	   clientInterceptorr   r   r
   r   r7   BaseExceptionr   r   r)   r#   r   r0   r   r   r   servicer3   r   r5   r   r6   r   r9   r   r   r   r   r   r=   r'   r'   r'   r(   r   (   s    



	




=
'!




r   existing	parameterr$   c                 C   s8   |d u r| S t |rtttt gtt f || S |S N)callabler   r   r   r   rK   rL   r'   r'   r(   r-      s
    r-   c                 C   sP   |d u r| S t |rttttt  gttt  f || S t| p"g t| S rM   )rN   r   r   r   r	   r   listrO   r'   r'   r(   r/      s   r/   )&rA   
contextlibr   r   typingr   r   r   r   r   r	   r
   r   r   r   temporalio.clientrD   temporalio.convertertemporalio.workerr   r   temporalio.servicer   r   r   r   r   r   r   r   r   rC   rG   Pluginr7   r   r-   r/   r'   r'   r'   r(   <module>   s6    0 	 E



