o
    i9                     @  s&  d Z ddlmZ ddlZddl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 ddlmZ ddl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Zddl Zddl!Zddl"Zd	Z#ed
ej$j%j&dZ'edej$j%j&dZ(e)e*Z+da,eG dd dZ-eG dd dZ.eddG dd dZ/e/ e/_0eddG dd dZ1eG dd dZ2G dd de	Z3G dd dej4j5j6Z6G dd dej4j5j7Z7G d d! d!ej4j5j8Z8G d"d# d#ej4j5j9Z9G d$d% d%ej4j5j:Z:G d&d' d'e3Z;G d(d) d)eZ<G d*d+ d+ej=j>Z?dS ),zUnderlying gRPC services.    )annotationsN)ABCabstractmethod)	dataclassfield)	timedelta)IntEnum)ClassVarMappingOptionalTupleTypeTypeVarUnionz1.19.0ServiceRequest)boundServiceResponseFc                   @  sT   e Zd ZU dZdZded< 	 dZded< 	 dZded< 	 dZded< 	 dddZ	dS )	TLSConfigz4TLS configuration for connecting to Temporal server.NzOptional[bytes]server_root_ca_certOptional[str]domainclient_certclient_private_keyreturn(temporalio.bridge.client.ClientTlsConfigc                 C  s   t jjj| j| j| j| jdS )N)r   r   r   r   )
temporaliobridgeclientClientTlsConfigr   r   r   r   self r!   X/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/temporalio/service.py_to_bridge_config8   s   zTLSConfig._to_bridge_config)r   r   )
__name__
__module____qualname____doc__r   __annotations__r   r   r   r#   r!   r!   r!   r"   r   $   s   
 r   c                   @  sp   e Zd ZU dZdZded< 	 dZded< 	 dZded	< 	 d
Zded< 	 dZ	ded< 	 dZ
ded< 	 dddZdS )RetryConfigz%Retry configuration for server calls.d   intinitial_interval_millisg?floatrandomization_factorg      ?
multiplieri  max_interval_millisi'  zOptional[int]max_elapsed_time_millis
   max_retriesr   *temporalio.bridge.client.ClientRetryConfigc                 C  s&   t jjj| j| j| j| j| j| j	dS )N)r,   r.   r/   r0   r1   r3   )
r   r   r   ClientRetryConfigr,   r.   r/   r0   r1   r3   r   r!   r!   r"   r#   R   s   zRetryConfig._to_bridge_configN)r   r4   )r$   r%   r&   r'   r,   r(   r.   r/   r0   r1   r3   r#   r!   r!   r!   r"   r)   A   s   
 r)   T)frozenc                   @  sB   e Zd ZU dZdZded< 	 dZded< 	 ded< 	 dddZdS )KeepAliveConfigz0Keep-alive configuration for client connections.i0u  r+   interval_millisi:  timeout_milliszClassVar[KeepAliveConfig]defaultr   .temporalio.bridge.client.ClientKeepAliveConfigc                 C     t jjj| j| jdS )N)r8   r9   )r   r   r   ClientKeepAliveConfigr8   r9   r   r!   r!   r"   r#   i   s   z!KeepAliveConfig._to_bridge_configN)r   r;   )r$   r%   r&   r'   r8   r(   r9   r#   r!   r!   r!   r"   r7   ]   s   
 r7   c                   @  s4   e Zd ZU dZded< 	 dZded< 	 dd	d
ZdS )HttpConnectProxyConfigz<Configuration for HTTP CONNECT proxy for client connections.strtarget_hostNzOptional[Tuple[str, str]]
basic_authr   5temporalio.bridge.client.ClientHttpConnectProxyConfigc                 C  r<   )N)r@   rA   )r   r   r   ClientHttpConnectProxyConfigr@   rA   r   r!   r!   r"   r#   |   s   z(HttpConnectProxyConfig._to_bridge_config)r   rB   )r$   r%   r&   r'   r(   rA   r#   r!   r!   r!   r"   r>   s   s   
 r>   c                   @  s   e Zd ZU dZded< dZded< dZded	< dZd
ed< ej	Z
ded< eedZded< dZded< dZded< dZded< dZded< d ddZd!ddZdS )"ConnectConfigz$Config for connecting to the server.r?   r@   Nr   api_keyFzUnion[bool, TLSConfig]tlszOptional[RetryConfig]retry_configzOptional[KeepAliveConfig]keep_alive_config)default_factoryMapping[str, Union[str, bytes]]rpc_metadata identityboollazyz$Optional[temporalio.runtime.Runtime]runtimez Optional[HttpConnectProxyConfig]http_connect_proxy_configr   Nonec                 C  s&   | j st  dt  | _ dS dS )z'Set extra defaults on unset properties.@N)rM   osgetpidsocketgethostnamer   r!   r!   r"   __post_init__   s   zConnectConfig.__post_init__%temporalio.bridge.client.ClientConfigc                 C  s   d| j v rtd | j }t| jtr| j nd }n)t| jtr-d| j  }| j }n| jr<d| j  }t  }nd| j  }d }tjj	j
|| j|| jrT| j nd | jr]| j nd | j| jdt| jrn| j d
S d d
S )Nz://z]Target host as URL with scheme no longer supported. This will be an error in future versions.zhttps://zhttp://ztemporal-python)

target_urlrE   
tls_configrG   rH   metadatarM   client_nameclient_versionrQ   )r@   warningswarn
isinstancerF   r   r#   r   r   r   ClientConfigrE   rG   rH   rK   rM   __version__rQ   )r    rZ   r[   r!   r!   r"   r#      sD   


zConnectConfig._to_bridge_config)r   rR   )r   rY   )r$   r%   r&   r'   r(   rE   rF   rG   r7   r:   rH   r   dictrK   rM   rO   rP   rQ   rX   r#   r!   r!   r!   r"   rD      s   
 
rD   c                      s   e Zd ZdZed)ddZd* fdd	Zd
di ddd+ddZee	d,ddZ
e	d-ddZe	d.dd Ze	d/d'd(Z  ZS )0ServiceClientz#Direct client to Temporal services.configrD   r   c                   s   t | I dH S )z&Connect directly to Temporal services.N)_BridgeServiceClientconnect)rf   r!   r!   r"   rh      s   zServiceClient.connectrR   c                   sF   t    || _t| | _t| | _t| | _t	| | _
t| | _dS )z#Initialize the base service client.N)super__init__rf   WorkflowServiceworkflow_serviceOperatorServiceoperator_serviceCloudServicecloud_serviceTestServicetest_serviceHealthServicehealth_servicer    rf   	__class__r!   r"   rj      s   




zServiceClient.__init__z/temporal.api.workflowservice.v1.WorkflowServiceFN)serviceretryr\   timeoutrx   r?   ry   rN   r\   rJ   rz   Optional[timedelta]c                  sD   | j jtjjjjj|d|||dI dH }|jtjjjjj	j
jkS )a  Check whether the WorkflowService is up.

        In addition to accepting which service to check health on, this accepts
        some of the same parameters as other RPC calls. See
        :py:meth:`ServiceCall.__call__`.

        Returns:
            True when available, false if the server is running but the service
            is unavailable (rare), or raises an error if server/service cannot
            be reached.
        )rx   )ry   r\   rz   N)rt   checkr   r   protohealthv1HealthCheckRequeststatusHealthCheckResponseServingStatusSERVING)r    rx   ry   r\   rz   respr!   r!   r"   check_health   s   zServiceClient.check_healthrg   c                 C     t zUnderlying service client.NotImplementedErrorr   r!   r!   r"   worker_service_client   s   z#ServiceClient.worker_service_clientc                 C  r   )z%Update service client's RPC metadata.r   r    r\   r!   r!   r"   update_rpc_metadata     z!ServiceClient.update_rpc_metadatarE   r   c                 C  r   )z Update service client's API key.r   r    rE   r!   r!   r"   update_api_key  r   zServiceClient.update_api_keyrpcreqgoogle.protobuf.message.Message	resp_typeType[ServiceResponse]r   c                  s   t Nr   )r    r   r   r   rx   ry   r\   rz   r!   r!   r"   	_rpc_call  s   zServiceClient._rpc_call)rf   rD   r   re   rf   rD   r   rR   )
rx   r?   ry   rN   r\   rJ   rz   r{   r   rN   r   rg   r\   rJ   r   rR   rE   r   r   rR   r   r?   r   r   r   r   rx   r?   ry   rN   r\   rJ   rz   r{   r   r   )r$   r%   r&   r'   staticmethodrh   rj   r   propertyr   r   r   r   r   __classcell__r!   r!   rv   r"   re      s&    re   c                   @     e Zd ZdZdS )rk   z1Client to the Temporal server's workflow service.Nr$   r%   r&   r'   r!   r!   r!   r"   rk         rk   c                   @  r   )rm   z1Client to the Temporal server's operator service.Nr   r!   r!   r!   r"   rm     r   rm   c                   @  r   )ro   z.Client to the Temporal server's cloud service.Nr   r!   r!   r!   r"   ro   #  r   ro   c                   @  r   )rq   z2Client to the Temporal test server's test service.Nr   r!   r!   r!   r"   rq   '  r   rq   c                   @  r   )rs   z/Client to the Temporal server's health service.Nr   r!   r!   r!   r"   rs   +  r   rs   c                      sb   e Zd Zed$ddZd% fddZd&d
dZed'ddZd(ddZ	d)ddZ
d*d"d#Z  ZS )+rg   rf   rD   r   c                   s"   t | }| js| I d H  |S r   )rg   rO   _connected_client)rf   r   r!   r!   r"   rh   0  s
   z_BridgeServiceClient.connectrR   c                   s*   t  | | | _d | _t | _d S r   )ri   rj   r#   _bridge_config_bridge_clientasyncioLock_bridge_client_connect_lockru   rv   r!   r"   rj   8  s   
z_BridgeServiceClient.__init__temporalio.bridge.client.Clientc              	     s~   | j 4 I d H * | js%| jjptjj }tjjj	
|j| jI d H | _| jW  d   I d H  S 1 I d H s8w   Y  d S r   )r   r   rf   rP   r   Runtimer:   r   r   Clientrh   _core_runtimer   )r    rP   r!   r!   r"   r   >  s   
0z&_BridgeServiceClient._connected_clientc                 C  s   | S r   r!   r   r!   r!   r"   r   H  r   z*_BridgeServiceClient.worker_service_clientr\   rJ   c                 C  "   || j _| jr| j| dS dS )zUpdate Core client metadata.N)r   r\   r   update_metadatar   r!   r!   r"   r   M     z(_BridgeServiceClient.update_rpc_metadatarE   r   c                 C  r   )zUpdate Core client API key.N)r   rE   r   r   r   r!   r!   r"   r   U  r   z#_BridgeServiceClient.update_api_keyr   r?   r   r   r   r   rx   ry   rN   rz   r{   r   c             
     s   t rtd||| z#|  I d H }|j|||||||dI d H }	t r,td|||	 |	W S  tjjjyK }
 z|
j	\}}}t|t
||d }
~
ww )NzService %s request to %s: %s)rx   r   r   r   ry   r\   rz   zService %s response from %s: %s)
LOG_PROTOSloggerdebugr   callr   r   r   RPCErrorargsRPCStatusCode)r    r   r   r   rx   ry   r\   rz   r   r   errr   messagedetailsr!   r!   r"   r   ]  s,   	z_BridgeServiceClient._rpc_call)rf   rD   r   rg   r   )r   r   r   r   r   r   )r$   r%   r&   r   rh   rj   r   r   r   r   r   r   r   r!   r!   rv   r"   rg   /  s    



rg   c                   @  sT   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdS )r   z%Status code for :py:class:`RPCError`.r                           	   r2                     N)r$   r%   r&   r'   OK	CANCELLEDUNKNOWNINVALID_ARGUMENTDEADLINE_EXCEEDED	NOT_FOUNDALREADY_EXISTSPERMISSION_DENIEDRESOURCE_EXHAUSTEDFAILED_PRECONDITIONABORTEDOUT_OF_RANGEUNIMPLEMENTEDINTERNALUNAVAILABLE	DATA_LOSSUNAUTHENTICATEDr!   r!   r!   r"   r     s&    r   c                      sZ   e Zd ZdZd fd
dZedddZedddZedddZedddZ	  Z
S )r   zError during RPC call.r   r?   r   r   raw_grpc_statusbytesr   rR   c                   s(   t  | || _|| _|| _d| _dS )zInitialize RPC error.N)ri   rj   _message_status_raw_grpc_status_grpc_status)r    r   r   r   rv   r!   r"   rj     s
   
zRPCError.__init__c                 C     | j S )zMessage for the error.)r   r   r!   r!   r"   r        zRPCError.messagec                 C  r   )zStatus code for the error.)r   r   r!   r!   r"   r     r   zRPCError.statusc                 C  r   )zRaw gRPC status bytes.)r   r   r!   r!   r"   r     r   zRPCError.raw_grpc_status#temporalio.api.common.v1.GrpcStatusc                 C  s0   | j du rtjjj }|| j || _ | j S )z%Status of the gRPC call with details.N)r   r   apicommonr   
GrpcStatusParseFromStringr   )r    r   r!   r!   r"   grpc_status  s
   
zRPCError.grpc_status)r   r?   r   r   r   r   r   rR   )r   r?   )r   r   )r   r   )r   r   )r$   r%   r&   r'   rj   r   r   r   r   r   r   r!   r!   rv   r"   r     s    
r   )@r'   
__future__r   r   loggingrT   rV   r_   abcr   r   dataclassesr   r   datetimer   enumr   typingr	   r
   r   r   r   r   r   google.protobuf.messagegoogletemporalio.api.common.v1r   temporalio.bridge.client!temporalio.bridge.proto.health.v1$temporalio.bridge.services_generatedtemporalio.exceptionstemporalio.runtimerc   protobufr   Messager   r   	getLoggerr$   r   r   r   r)   r7   r:   r>   rD   re   r   services_generatedrk   rm   ro   rq   rs   rg   r   
exceptionsTemporalErrorr   r!   r!   r!   r"   <module>   sX    $
EPP