
    IR-e^C                     D    d dl mZ d dlmZ dgZdgZ G d d          ZdS )   )
SAMPClient)SAMPHubProxySAMPIntegratedClientzSAMPIntegratedClient.*c                      e Zd ZdZ	 	 	 	 	 	 d+dZed             Zd,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 Zd Zd-dZd Zej        j        e_        d Zej        j        e_        d  Z ej         j        e _        d.d!Z!ej!        j        e!_        d.d"Z"ej"        j        e"_        d.d#Z#ej#        j        e#_        d$ Z$ej$        j        e$_        d/d%Z%ej%        j        e%_        d/d&Z&ej&        j        e&_        d' Z'ej'        j        e'_        d0d(Z(ej(        j        e(_        d) Z)ej)        j        e)_        d* Z*ej*        j        e*_        dS )1r   ao  
    A Simple SAMP client.

    This class is meant to simplify the client usage providing a proxy class
    that merges the :class:`~astropy.samp.SAMPClient` and
    :class:`~astropy.samp.SAMPHubProxy` functionalities in a
    simplified API.

    Parameters
    ----------
    name : str, optional
        Client name (corresponding to ``samp.name`` metadata keyword).

    description : str, optional
        Client description (corresponding to ``samp.description.text`` metadata
        keyword).

    metadata : dict, optional
        Client application metadata in the standard SAMP format.

    addr : str, optional
        Listening address (or IP). This defaults to 127.0.0.1 if the internet
        is not reachable, otherwise it defaults to the host name.

    port : int, optional
        Listening XML-RPC server socket port. If left set to 0 (the default),
        the operating system will select a free port.

    callable : bool, optional
        Whether the client can receive calls and notifications. If set to
        `False`, then the client can send notifications and calls, but can not
        receive any.
    N    Tc                 X    t                      | _        ||||||d| _        	 d | _        d S )N)namedescriptionmetadataaddrportcallable)r   hubclient_argumentsclient)selfr	   r
   r   r   r   r   s          >lib/python3.11/site-packages/astropy/samp/integrated_client.py__init__zSAMPIntegratedClient.__init__/   sF      >> &  !
 !
	 99    c                 2    | j         j        o| j        j        S )z
        Testing method to verify the client connection with a running Hub.

        Returns
        -------
        is_connected : bool
            True if the client is connected to a Hub, False otherwise.
        )r   is_connectedr   
is_runningr   s    r   r   z!SAMPIntegratedClient.is_connectedN   s     x$?)??r      c                     | j                             |||           t          | j         fi | j        | _        | j                                         | j                                         dS )aN  
        Connect with the current or specified SAMP Hub, start and register the
        client.

        Parameters
        ----------
        hub : `~astropy.samp.SAMPHubServer`, optional
            The hub to connect to.

        hub_params : dict, optional
            Optional dictionary containing the lock-file content of the Hub
            with which to connect. This dictionary has the form
            ``{<token-name>: <token-string>, ...}``.

        pool_size : int, optional
            The number of socket connections opened to communicate with the
            Hub.
        N)r   connectr   r   r   startregister)r   r   
hub_params	pool_sizes       r   r   zSAMPIntegratedClient.connectZ   sj    & 	j)444 !CCT-BCCr   c                 N   | j         r	 | j                                         | j        j        r| j                                         | j                                         dS # | j        j        r| j                                         | j                                         w xY wdS )zw
        Unregister the client from the current SAMP Hub, stop the client and
        disconnect from the Hub.
        N)r   r   
unregisterr   stopr   
disconnectr   s    r   r$   zSAMPIntegratedClient.disconnectx   s    
  	&&&&(((;) 'K$$&&&##%%%%% ;) 'K$$&&&##%%%%	& 	&s   A" "A B"c                 4    | j                                         S )zL
        Proxy to ``ping`` SAMP Hub method (Standard Profile only).
        )r   pingr   s    r   r&   zSAMPIntegratedClient.ping   s     x}}r   c                 6    | j                             |          S )z?
        Proxy to ``declareMetadata`` SAMP Hub method.
        )r   declare_metadata)r   r   s     r   r(   z%SAMPIntegratedClient.declare_metadata   s     {++H555r   c                 \    | j                             |                                 |          S )z;
        Proxy to ``getMetadata`` SAMP Hub method.
        )r   get_metadataget_private_keyr   	client_ids     r   r*   z!SAMPIntegratedClient.get_metadata   s(     x$$T%9%9%;%;YGGGr   c                 \    | j                             |                                 |          S )z@
        Proxy to ``getSubscriptions`` SAMP Hub method.
        )r   get_subscriptionsr+   r,   s     r   r/   z&SAMPIntegratedClient.get_subscriptions   s(     x))$*>*>*@*@)LLLr   c                 Z    | j                             |                                           S )z
        Proxy to ``getRegisteredClients`` SAMP Hub method.

        This returns all the registered clients, excluding the current client.
        )r   get_registered_clientsr+   r   s    r   r1   z+SAMPIntegratedClient.get_registered_clients   s&     x..t/C/C/E/EFFFr   c                 \    | j                             |                                 |          S )zD
        Proxy to ``getSubscribedClients`` SAMP Hub method.
        )r   get_subscribed_clientsr+   )r   mtypes     r   r3   z+SAMPIntegratedClient.get_subscribed_clients   s(     x..t/C/C/E/EuMMMr   c                 h    i }d|v r&|d         }|d= ||d}|                     |           n||d}|S )N	extra_kws)z
samp.mtypezsamp.paramsupdate)r   r4   paramsmsgextras        r   _format_easy_msgz%SAMPIntegratedClient._format_easy_msg   sX    &  ;'E{#!&v>>CJJu!&v>>C
r   c                 ^    | j                             |                                 ||          S )z6
        Proxy to ``notify`` SAMP Hub method.
        )r   notifyr+   )r   recipient_idmessages      r   r>   zSAMPIntegratedClient.notify   s(     xt3355|WMMMr   c                 V    |                      ||                     ||                    S )a4  
        Easy to use version of :meth:`~astropy.samp.integrated_client.SAMPIntegratedClient.notify`.

        This is a proxy to ``notify`` method that allows to send the
        notification message in a simplified way.

        Note that reserved ``extra_kws`` keyword is a dictionary with the
        special meaning of being used to add extra keywords, in addition to
        the standard ``samp.mtype`` and ``samp.params``, to the message sent.

        Parameters
        ----------
        recipient_id : str
            Recipient ID

        mtype : str
            the MType to be notified

        params : dict or set of str
            Variable keyword set which contains the list of parameters for the
            specified MType.

        Examples
        --------
        >>> from astropy.samp import SAMPIntegratedClient
        >>> cli = SAMPIntegratedClient()
        >>> ...
        >>> cli.enotify("samp.msg.progress", msgid = "xyz", txt = "initialization",
        ...             percent = "10", extra_kws = {"my.extra.info": "just an example"})
        )r>   r<   )r   r?   r4   r9   s       r   enotifyzSAMPIntegratedClient.enotify   s(    > {{<)>)>uf)M)MNNNr   c                 \    | j                             |                                 |          S )z9
        Proxy to ``notifyAll`` SAMP Hub method.
        )r   
notify_allr+   )r   r@   s     r   rD   zSAMPIntegratedClient.notify_all   s(     x""4#7#7#9#97CCCr   c                 T    |                      |                     ||                    S )a  
        Easy to use version of :meth:`~astropy.samp.integrated_client.SAMPIntegratedClient.notify_all`.

        This is a proxy to ``notifyAll`` method that allows to send the
        notification message in a simplified way.

        Note that reserved ``extra_kws`` keyword is a dictionary with the
        special meaning of being used to add extra keywords, in addition to
        the standard ``samp.mtype`` and ``samp.params``, to the message sent.

        Parameters
        ----------
        mtype : str
            MType to be notified.

        params : dict or set of str
            Variable keyword set which contains the list of parameters for
            the specified MType.

        Examples
        --------
        >>> from astropy.samp import SAMPIntegratedClient
        >>> cli = SAMPIntegratedClient()
        >>> ...
        >>> cli.enotify_all("samp.msg.progress", txt = "initialization",
        ...                 percent = "10",
        ...                 extra_kws = {"my.extra.info": "just an example"})
        )rD   r<   )r   r4   r9   s      r   enotify_allz SAMPIntegratedClient.enotify_all   s&    : t44UFCCDDDr   c                 `    | j                             |                                 |||          S )z4
        Proxy to ``call`` SAMP Hub method.
        )r   callr+   )r   r?   msg_tagr@   s       r   rH   zSAMPIntegratedClient.call  s*     x}}T1133\7GTTTr   c                 X    |                      |||                     ||                    S )a}  
        Easy to use version of :meth:`~astropy.samp.integrated_client.SAMPIntegratedClient.call`.

        This is a proxy to ``call`` method that allows to send a call message
        in a simplified way.

        Note that reserved ``extra_kws`` keyword is a dictionary with the
        special meaning of being used to add extra keywords, in addition to
        the standard ``samp.mtype`` and ``samp.params``, to the message sent.

        Parameters
        ----------
        recipient_id : str
            Recipient ID

        msg_tag : str
            Message tag to use

        mtype : str
            MType to be sent

        params : dict of set of str
            Variable keyword set which contains the list of parameters for
            the specified MType.

        Examples
        --------
        >>> from astropy.samp import SAMPIntegratedClient
        >>> cli = SAMPIntegratedClient()
        >>> ...
        >>> msgid = cli.ecall("abc", "xyz", "samp.msg.progress",
        ...                   txt = "initialization", percent = "10",
        ...                   extra_kws = {"my.extra.info": "just an example"})
        )rH   r<   )r   r?   rI   r4   r9   s        r   ecallzSAMPIntegratedClient.ecall  s+    F yyw0E0EeV0T0TUUUr   c                 ^    | j                             |                                 ||          S )z7
        Proxy to ``callAll`` SAMP Hub method.
        )r   call_allr+   )r   rI   r@   s      r   rM   zSAMPIntegratedClient.call_all0  s*     x  !5!5!7!7'JJJr   c                 Z    |                      ||                     ||                     dS )aV  
        Easy to use version of :meth:`~astropy.samp.integrated_client.SAMPIntegratedClient.call_all`.

        This is a proxy to ``callAll`` method that allows to send the call
        message in a simplified way.

        Note that reserved ``extra_kws`` keyword is a dictionary with the
        special meaning of being used to add extra keywords, in addition to
        the standard ``samp.mtype`` and ``samp.params``, to the message sent.

        Parameters
        ----------
        msg_tag : str
            Message tag to use

        mtype : str
            MType to be sent

        params : dict of set of str
            Variable keyword set which contains the list of parameters for
            the specified MType.

        Examples
        --------
        >>> from astropy.samp import SAMPIntegratedClient
        >>> cli = SAMPIntegratedClient()
        >>> ...
        >>> msgid = cli.ecall_all("xyz", "samp.msg.progress",
        ...                       txt = "initialization", percent = "10",
        ...                       extra_kws = {"my.extra.info": "just an example"})
        N)rM   r<   )r   rI   r4   r9   s       r   	ecall_allzSAMPIntegratedClient.ecall_all6  s/    @ 	gt44UFCCDDDDDr   c                 `    | j                             |                                 |||          S )z;
        Proxy to ``callAndWait`` SAMP Hub method.
        )r   call_and_waitr+   )r   r?   r@   timeouts       r   rQ   z"SAMPIntegratedClient.call_and_waitX  s3     x%%  ""L'7
 
 	
r   c                 X    |                      ||                     ||          |          S )a  
        Easy to use version of :meth:`~astropy.samp.integrated_client.SAMPIntegratedClient.call_and_wait`.

        This is a proxy to ``callAndWait`` method that allows to send the call
        message in a simplified way.

        Note that reserved ``extra_kws`` keyword is a dictionary with the
        special meaning of being used to add extra keywords, in addition to
        the standard ``samp.mtype`` and ``samp.params``, to the message sent.

        Parameters
        ----------
        recipient_id : str
            Recipient ID

        mtype : str
            MType to be sent

        timeout : str
            Call timeout in seconds

        params : dict of set of str
            Variable keyword set which contains the list of parameters for
            the specified MType.

        Examples
        --------
        >>> from astropy.samp import SAMPIntegratedClient
        >>> cli = SAMPIntegratedClient()
        >>> ...
        >>> cli.ecall_and_wait("xyz", "samp.msg.progress", "5",
        ...                    txt = "initialization", percent = "10",
        ...                    extra_kws = {"my.extra.info": "just an example"})
        )rQ   r<   )r   r?   r4   rR   r9   s        r   ecall_and_waitz#SAMPIntegratedClient.ecall_and_wait`  s4    F !!$//v>>
 
 	
r   c                 ^    | j                             |                                 ||          S )z5
        Proxy to ``reply`` SAMP Hub method.
        )r   replyr+   )r   msg_idresponses      r   rV   zSAMPIntegratedClient.reply  s(     x~~d2244fhGGGr   c                 r    d|i}||                     d|i           ||                     d|i           |S )Nzsamp.statuszsamp.resultz
samp.errorr7   )r   statusresulterrorr:   s        r   _format_easy_responsez*SAMPIntegratedClient._format_easy_response  sK    f%JJv.///JJe,---
r   c                 X    |                      ||                     |||                    S )aa  
        Easy to use version of :meth:`~astropy.samp.integrated_client.SAMPIntegratedClient.reply`.

        This is a proxy to ``reply`` method that allows to send a reply
        message in a simplified way.

        Parameters
        ----------
        msg_id : str
            Message ID to which reply.

        status : str
            Content of the ``samp.status`` response keyword.

        result : dict
            Content of the ``samp.result`` response keyword.

        error : dict
            Content of the ``samp.error`` response keyword.

        Examples
        --------
        >>> from astropy.samp import SAMPIntegratedClient, SAMP_STATUS_ERROR
        >>> cli = SAMPIntegratedClient()
        >>> ...
        >>> cli.ereply("abd", SAMP_STATUS_ERROR, result={},
        ...            error={"samp.errortxt": "Test error message"})
        )rV   r]   )r   rW   rZ   r[   r\   s        r   ereplyzSAMPIntegratedClient.ereply  s*    : zz&$"<"<VVU"S"STTTr   c                 :    | j                             |||          S N)r   receive_notification)r   private_key	sender_idr@   s       r   rb   z)SAMPIntegratedClient.receive_notification  s    {//YPPPr   c                 <    | j                             ||||          S ra   )r   receive_call)r   rc   rd   rW   r@   s        r   rf   z!SAMPIntegratedClient.receive_call  s    {''YPPPr   c                 <    | j                             ||||          S ra   )r   receive_response)r   rc   responder_idrI   rX   s        r   rh   z%SAMPIntegratedClient.receive_response  s%    {++w
 
 	
r   c                 B    | j                             ||dd            d S )NT)declarer   )r   bind_receive_messager   r4   functionrk   r   s        r   rl   z)SAMPIntegratedClient.bind_receive_message  s(    (($QU(VVVVVr   c                 @    | j                             ||||           d S ra   )r   bind_receive_notificationrm   s        r   rp   z.SAMPIntegratedClient.bind_receive_notification  s$    --eXwQQQQQr   c                 @    | j                             ||||           d S ra   )r   bind_receive_callrm   s        r   rr   z&SAMPIntegratedClient.bind_receive_call  s$    %%eXwIIIIIr   c                 <    | j                             ||           d S ra   )r   bind_receive_response)r   rI   rn   s      r   rt   z*SAMPIntegratedClient.bind_receive_response  s     ))'8<<<<<r   c                 <    | j                             ||           d S ra   )r   unbind_receive_notificationr   r4   rk   s      r   rv   z0SAMPIntegratedClient.unbind_receive_notification  s     //w?????r   c                 <    | j                             ||           d S ra   )r   unbind_receive_callrw   s      r   ry   z(SAMPIntegratedClient.unbind_receive_call  s     ''w77777r   c                 :    | j                             |           d S ra   )r   unbind_receive_response)r   rI   s     r   r{   z,SAMPIntegratedClient.unbind_receive_response  s    ++G44444r   c                 :    | j                             |           d S ra   )r   declare_subscriptions)r   subscriptionss     r   r}   z*SAMPIntegratedClient.declare_subscriptions  s    ))-88888r   c                 4    | j                                         S ra   )r   r+   r   s    r   r+   z$SAMPIntegratedClient.get_private_key  s    {**,,,r   c                 4    | j                                         S ra   )r   get_public_idr   s    r   r   z"SAMPIntegratedClient.get_public_id  s    {((***r   )NNNNr   T)NNr   )NN)TN)Tra   )+__name__
__module____qualname____doc__r   propertyr   r   r$   r&   r(   r*   r/   r1   r3   r<   r>   rB   rD   rF   rH   rK   rM   rO   rQ   rT   rV   r]   r_   rb   r   rf   rh   rl   rp   rr   rt   rv   ry   r{   r}   r+   r    r   r   r   r      s          H : : : :> 	@ 	@ X	@   <& & &  6 6 6H H HM M MG G GN N N  N N NO O OBD D DE E E>U U U#V #V #VJK K K E  E  ED
 
 
%
 %
 %
NH H H  U U U UBQ Q Q $.#B#J Q Q Q &2:L
 
 

  *:BW W W W $.#B#J R R R R )3(L(T%J J J J !+ < D= = = %/$D$L!@ @ @ @ +5*P*X'8 8 8 8 #-"@"H5 5 5 '1&H&P#9 9 9 9 %/$D$L!- - - )8@O+ + + '4<Mr   N)r   r   	hub_proxyr   __all____doctest_skip__r   r   r   r   <module>r      sx          # # # # # #!
",- l= l= l= l= l= l= l= l= l= l=r   