o
    i<                     @  s:  U d Z ddl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 ddlmZmZmZ ddlZddlmZ eeeef Zd	ed
< G dd deddZG dd deddZd+ddZd,ddZ d-ddZ!d.dd Z"ed!d"G d#d$ d$Z#G d%d& d&eddZ$ed!d"G d'd( d(Z%eG d)d* d*Z&dS )/zEnvironment and file-based configuration for Temporal clients.

This module provides utilities to load Temporal client configuration from TOML files
and environment variables.
    )annotations)	dataclassfieldPath)AnyDictLiteralMappingOptionalUnioncast)Self	TypeAlias	TypedDictN)	envconfigr   
DataSourcec                   @  s:   e Zd ZU dZded< ded< ded< ded< ded	< d
S )ClientConfigTLSDictz1Dictionary representation of TLS config for TOML.Optional[bool]disabledstrserver_nameMapping[str, str]server_ca_certclient_cert
client_keyN__name__
__module____qualname____doc____annotations__ r"   r"   Z/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/temporalio/envconfig.pyr         
 r   F)totalc                   @  :   e Zd ZU dZded< ded< ded< ded< ded	< d
S )ClientConfigProfileDictz>Dictionary representation of a client config profile for TOML.r   address	namespaceapi_keyr   tlsr   	grpc_metaNr   r"   r"   r"   r#   r'   "   r$   r'   dOptional[Mapping[str, Any]]returnOptional[DataSource]c                 C  s0   | sd S d| v r| d S d| v rt | d S d S )Ndatapathr   r-   r"   r"   r#   _from_dict_to_source,   s   r4   sourceOptional[Mapping[str, str]]c                 C  sD   t | trdt| iS t | trd| iS t | tr d| diS d S )Nr2   r1   utf-8)
isinstancer   r   bytesdecode)r5   r"   r"   r#   _source_to_dict6   s   


r;   %tuple[Optional[str], Optional[bytes]]c                 C  sx   d }d }t | trt| }||fS t | tr| d}||fS t | tr*| }||fS | d ur8tdt| j ||fS )Nr7   zHconfig_source must be one of pathlib.Path, str, bytes, or None, but got )r8   r   r   encoder9   	TypeErrortyper   )r5   r2   r1   r"   r"   r#   _source_to_path_and_dataB   s$   




r@   Optional[bytes]c                 C  s~   | d u rd S t | tr$t| d}| W  d    S 1 sw   Y  t | tr.| dS t | tr5| S tdt| j	 )Nrbr7   z;Source must be one of pathlib.Path, str, or bytes, but got )
r8   r   openreadr   r=   r9   r>   r?   r   )r5   fr"   r"   r#   _read_sourceU   s   
 


rF   T)frozenc                   @  sz   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ddZ
dddZedddZdS )ClientConfigTLSzoTLS configuration as specified as part of client configuration

    .. warning::
        Experimental API.
    Nr   r   Optional[str]r   r0   server_root_ca_certr   client_private_keyr/   r   c                   sb   i  | j dur| j  d< | jdur| j d< d fdd	}|d
| j |d| j |d| j  S )@Convert to a dictionary that can be used for TOML serialization.Nr   r   key6Literal['server_ca_cert', 'client_cert', 'client_key']r5   r0   c                   s(   |d urt | }r| | < d S d S d S N)r;   )rM   r5   valr3   r"   r#   
set_source   s   z+ClientConfigTLS.to_dict.<locals>.set_sourcer   r   r   )rM   rN   r5   r0   r   r   rJ   r   rK   )selfrQ   r"   r3   r#   to_dictw   s   



zClientConfigTLS.to_dict)Union[bool, temporalio.service.TLSConfig]c                 C  s6   | j du rdS tjj| jt| jt| jt| jdS )z:Create a `temporalio.service.TLSConfig` from this profile.TF)domainrJ   r   rK   )	r   
temporalioservice	TLSConfigr   rF   rJ   r   rK   rS   r"   r"   r#   to_connect_tls_config   s   
z%ClientConfigTLS.to_connect_tls_configr-   Optional[ClientConfigTLSDict]Optional[Self]c              	   C  sD   |sdS | | d| dt| dt| dt| ddS )z+Create a ClientConfigTLS from a dictionary.Nr   r   r   r   r   rR   )getr4   clsr-   r"   r"   r#   	from_dict   s   zClientConfigTLS.from_dict)r/   r   )r/   rU   )r-   r\   r/   r]   )r   r   r   r    r   r!   r   rJ   r   rK   rT   r[   classmethodra   r"   r"   r"   r#   rH   d   s    
 

rH   c                   @  r&   )ClientConnectConfigzArguments for `temporalio.client.Client.connect` that are configurable via
    environment configuration.

    .. warning::
        Experimental API.
    r   target_hostr)   r*   rU   r+   r   rpc_metadataNr   r"   r"   r"   r#   rc      s   
 rc   c                   @  s   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< 	 e	e
d	Zd
ed< 	 ed$ddZd%ddZd&ddZe	d'ddddddd(d"d#ZdS ))ClientConfigProfilea"  Represents a client configuration profile.

    This class holds the configuration as loaded from a file or environment.
    See `to_connect_config` to transform the profile to `ClientConnectConfig`,
    which can be used to create a client.

    .. warning::
        Experimental API.
    NrI   r(   r)   r*   zOptional[ClientConfigTLS]r+   )default_factoryr   r,   r-   r'   r/   r   c              	   C  s:   | | d| d| dt| d| dpi dS )z/Create a ClientConfigProfile from a dictionary.r(   r)   r*   r+   r,   )r(   r)   r*   r+   r,   )r^   rH   ra   r_   r"   r"   r#   ra      s   zClientConfigProfile.from_dictc                 C  sp   i }| j dur| j |d< | jdur| j|d< | jdur | j|d< | jr.| j  }r.||d< | jr6| j|d< |S )rL   Nr(   r)   r*   r+   r,   )r(   r)   r*   r+   rT   r,   )rS   r-   tls_dictr"   r"   r#   rT      s   






zClientConfigProfile.to_dictrc   c                 C  sv   i }| j r
| j |d< | jdur| j|d< | jdur"| j|d< d|d< | jdur.| j |d< | jr6| j|d< tt|S )z1Create a `ClientConnectConfig` from this profile.rd   Nr)   r*   Tr+   re   )r(   r)   r*   r+   r[   r,   r   rc   )rS   configr"   r"   r#   to_client_connect_config   s   







z,ClientConfigProfile.to_client_connect_configF)config_sourcedisable_filedisable_envconfig_file_strictoverride_env_varsprofilerk   r0   rl   boolrm   rn   ro   r6   c          	   	   C  s.   t |\}}tj| ||||||d}t|S )a!  Load a single client profile from given sources, applying env
        overrides.

        To get a :py:class:`ClientConnectConfig`, use the
        :py:meth:`to_client_connect_config` method on the returned profile.

        Args:
            profile: Profile to load from the config.
            config_source: If present, this is used as the configuration source
                instead of default file locations. This can be a path to the file
                or the string/byte contents of the file.
            disable_file: If true, file loading is disabled. This is only used
                when ``config_source`` is not present.
            disable_env: If true, environment variable loading and overriding
                is disabled. This takes precedence over the ``override_env_vars``
                parameter.
            config_file_strict: If true, will error on unrecognized keys.
            override_env_vars: The environment to use for loading and overrides.
                If not provided, the current process's environment is used. To
                use a specific set of environment variables, provide them here.
                To disable environment variable loading, set ``disable_env`` to
                true.

        Returns:
            The client configuration profile.
        )rp   r2   r1   rl   rm   rn   env_vars)r@   _bridge_envconfigload_client_connect_configrf   ra   )	rp   rk   rl   rm   rn   ro   r2   r1   raw_profiler"   r"   r#   load   s   $
	zClientConfigProfile.load)r-   r'   r/   r   )r/   r'   )r/   rc   rO   )rp   rI   rk   r0   rl   rq   rm   rq   rn   rq   ro   r6   r/   rf   )r   r   r   r    r(   r!   r)   r*   r+   r   dictr,   rb   ra   rT   rj   staticmethodrv   r"   r"   r"   r#   rf      s2   
 



rf   c                   @  sl   e Zd ZU dZded< 	 d!ddZed"ddZeddddd#ddZ	e	d$ddddddd%dd Z
dS )&ClientConfigaK  Client configuration loaded from TOML and environment variables.

    This contains a mapping of profile names to client profiles. Use
    `ClientConfigProfile.to_connect_config` to create a `ClientConnectConfig`
    from a profile. See `load_profile` to load an individual profile.

    .. warning::
        Experimental API.
    z!Mapping[str, ClientConfigProfile]profilesr/   %Mapping[str, ClientConfigProfileDict]c                 C  s   dd | j  D S )rL   c                 S  s   i | ]	\}}||  qS r"   )rT   .0kvr"   r"   r#   
<dictcomp>?  s    z(ClientConfig.to_dict.<locals>.<dictcomp>)rz   itemsrZ   r"   r"   r#   rT   =  s   zClientConfig.to_dictr-   Mapping[str, Mapping[str, Any]]r   c                 C  s   | dd |  D dS )z(Create a ClientConfig from a dictionary.c                 S  s"   i | ]\}}|t tt|qS r"   )rf   ra   r   r'   r|   r"   r"   r#   r   J  s    z*ClientConfig.from_dict.<locals>.<dictcomp>)rz   )r   r_   r"   r"   r#   ra   A  s
   zClientConfig.from_dictNF)rk   rn   ro   rk   r0   rn   rq   ro   r6   c                 C  s(   t | \}}tj||||d}t|S )a  Load all client profiles from given sources.

        This does not apply environment variable overrides to the profiles, it
        only uses an environment variable to find the default config file path
        (``TEMPORAL_CONFIG_FILE``). To get a single profile with environment variables
        applied, use :py:meth:`ClientConfigProfile.load`.

        Args:
            config_source: If present, this is used as the configuration source
                instead of default file locations. This can be a path to the file
                or the string/byte contents of the file.
            config_file_strict: If true, will TOML file parsing will error on
                unrecognized keys.
            override_env_vars: The environment variables to use for locating the
                default config file. If not provided, the current process's
                environment is used to check for ``TEMPORAL_CONFIG_FILE``. To
                use a specific set of environment variables, provide them here.
                To disable environment variable loading, set ``disable_file`` to
                true or pass an empty dictionary for this parameter.
        )r2   r1   rn   rr   )r@   rs   load_client_configry   ra   )rk   rn   ro   r2   r1   loaded_profilesr"   r"   r#   rv   P  s   
zClientConfig.load)config_filerl   rm   rn   ro   rp   rI   r   rl   rm   rc   c                C  s2   d}|r
|s
t |}tj| |||||d}| S )a3  Load a single client profile and convert to connect config.

        This is a convenience function that combines loading a profile and
        converting it to a connect config dictionary. This will use the current
        process's environment for overrides unless disabled.

        Args:
            profile: The profile to load from the config. Defaults to "default".
            config_file: Path to a specific TOML config file. If not provided,
                default file locations are used. This is ignored if
                ``disable_file`` is true.
            disable_file: If true, file loading is disabled.
            disable_env: If true, environment variable loading and overriding
                is disabled.
            config_file_strict: If true, will error on unrecognized keys in the
                TOML file.
            override_env_vars: A dictionary of environment variables to use for
                loading and overrides. If not provided, the current process's
                environment is used. To use a specific set of environment
                variables, provide them here. To disable environment variable
                loading, set ``disable_env`` to true.

        Returns:
            TypedDict of keyword arguments for
            :py:meth:`temporalio.client.Client.connect`.
        N)rp   rk   rl   rm   rn   ro   )r   rf   rv   rj   )rp   r   rl   rm   rn   ro   rk   profr"   r"   r#   rt   u  s   $z'ClientConfig.load_client_connect_config)r/   r{   )r-   r   r/   r   )rk   r0   rn   rq   ro   r6   r/   ry   rO   )rp   rI   r   rI   rl   rq   rm   rq   rn   rq   ro   r6   r/   rc   )r   r   r   r    r!   rT   rb   ra   rx   rv   rt   r"   r"   r"   r#   ry   .  s*   
 

$ry   )r-   r.   r/   r0   )r5   r0   r/   r6   )r5   r0   r/   r<   )r5   r0   r/   rA   )'r    
__future__r   dataclassesr   r   pathlibr   typingr   r   r	   r
   r   r   r   typing_extensionsr   r   r   temporalio.servicerW   %temporalio.bridge.temporal_sdk_bridger   rs   r   r9   r   r!   r   r'   r4   r;   r@   rF   rH   rc   rf   ry   r"   r"   r"   r#   <module>   s0    $






Bw