U
    e»{j_C  ã                   @   s6   d dl mZ d dlmZ dgZdgZG dd„ dƒZdS )é   )Ú
SAMPClient)ÚSAMPHubProxyÚSAMPIntegratedClientzSAMPIntegratedClient.*c                   @   sÐ  e Zd ZdZdPdd„Zedd„ ƒZdQd
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 d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ ZdRd4d5„Zd6d7„ Zejje_d8d9„ Zejje_d:d;„ Z ej je _dSd<d=„Z!ej!je!_dTd>d?„Z"ej"je"_dUd@dA„Z#ej#je#_dBdC„ Z$ej$je$_dVdDdE„Z%ej%je%_dWdFdG„Z&ej&je&_dHdI„ Z'ej'je'_dXdJdK„Z(ej(je(_dLdM„ Z)ej)je)_dNdO„ Z*ej*je*_dS )Yr   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                 C   s&   t ƒ | _||||||dœ| _d | _d S )N)ÚnameÚdescriptionÚmetadataÚaddrÚportÚcallable)r   ÚhubÚclient_argumentsÚclient)Úselfr   r   r   r	   r
   r   © r   ú]/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/samp/integrated_client.pyÚ__init__/   s    	úzSAMPIntegratedClient.__init__c                 C   s   | 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   r   r   r   r   N   s    
z!SAMPIntegratedClient.is_connectedé   c                 C   s:   | j  |||¡ t| j f| 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   Z
hub_paramsZ	pool_sizer   r   r   r   Z   s    
zSAMPIntegratedClient.connectc                 C   s8   | j r4z| j ¡  W 5 | jjr(| j ¡  | j ¡  X dS )zw
        Unregister the client from the current SAMP Hub, stop the client and
        disconnect from the Hub.
        N)r   r   r   Ústopr   Ú
disconnectÚ
unregisterr   r   r   r   r   x   s    
zSAMPIntegratedClient.disconnectc                 C   s
   | j  ¡ S )zL
        Proxy to ``ping`` SAMP Hub method (Standard Profile only).
        )r   Úpingr   r   r   r   r   †   s    zSAMPIntegratedClient.pingc                 C   s   | j  |¡S )z?
        Proxy to ``declareMetadata`` SAMP Hub method.
        )r   Údeclare_metadata)r   r   r   r   r   r   Œ   s    z%SAMPIntegratedClient.declare_metadatac                 C   s   | j  |  ¡ |¡S )z;
        Proxy to ``getMetadata`` SAMP Hub method.
        )r   Úget_metadataÚget_private_key©r   Z	client_idr   r   r   r   ’   s    z!SAMPIntegratedClient.get_metadatac                 C   s   | j  |  ¡ |¡S )z@
        Proxy to ``getSubscriptions`` SAMP Hub method.
        )r   Úget_subscriptionsr    r!   r   r   r   r"   ˜   s    z&SAMPIntegratedClient.get_subscriptionsc                 C   s   | j  |  ¡ ¡S )z”
        Proxy to ``getRegisteredClients`` SAMP Hub method.

        This returns all the registered clients, excluding the current client.
        )r   Úget_registered_clientsr    r   r   r   r   r#   ž   s    z+SAMPIntegratedClient.get_registered_clientsc                 C   s   | j  |  ¡ |¡S )zD
        Proxy to ``getSubscribedClients`` SAMP Hub method.
        )r   Úget_subscribed_clientsr    )r   Úmtyper   r   r   r$   ¦   s    z+SAMPIntegratedClient.get_subscribed_clientsc                 C   s>   i }d|kr0|d }|d= ||dœ}|  |¡ n
||dœ}|S )NZ	extra_kws)z
samp.mtypezsamp.params©Úupdate)r   r%   ÚparamsÚmsgÚextrar   r   r   Ú_format_easy_msg¬   s    

z%SAMPIntegratedClient._format_easy_msgc                 C   s   | j  |  ¡ ||¡S )z6
        Proxy to ``notify`` SAMP Hub method.
        )r   Únotifyr    )r   Úrecipient_idÚmessager   r   r   r,   ¹   s    zSAMPIntegratedClient.notifyc                 K   s   |   ||  ||¡¡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-   r%   r(   r   r   r   Úenotify¿   s    zSAMPIntegratedClient.enotifyc                 C   s   | j  |  ¡ |¡S )z9
        Proxy to ``notifyAll`` SAMP Hub method.
        )r   Ú
notify_allr    )r   r.   r   r   r   r0   à   s    zSAMPIntegratedClient.notify_allc                 K   s   |   |  ||¡¡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"})
        )r0   r+   )r   r%   r(   r   r   r   Úenotify_allæ   s    z SAMPIntegratedClient.enotify_allc                 C   s   | j  |  ¡ |||¡S )z4
        Proxy to ``call`` SAMP Hub method.
        )r   Úcallr    )r   r-   Úmsg_tagr.   r   r   r   r2     s    zSAMPIntegratedClient.callc                 K   s   |   |||  ||¡¡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"})
        )r2   r+   )r   r-   r3   r%   r(   r   r   r   Úecall  s    $zSAMPIntegratedClient.ecallc                 C   s   | j  |  ¡ ||¡S )z7
        Proxy to ``callAll`` SAMP Hub method.
        )r   Úcall_allr    )r   r3   r.   r   r   r   r5   1  s    zSAMPIntegratedClient.call_allc                 K   s   |   ||  ||¡¡ 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)r5   r+   )r   r3   r%   r(   r   r   r   Ú	ecall_all7  s     zSAMPIntegratedClient.ecall_allc                 C   s   | j  |  ¡ |||¡S )z;
        Proxy to ``callAndWait`` SAMP Hub method.
        )r   Úcall_and_waitr    )r   r-   r.   Útimeoutr   r   r   r7   Y  s       ÿz"SAMPIntegratedClient.call_and_waitc                 K   s   |   ||  ||¡|¡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"})
        )r7   r+   )r   r-   r%   r8   r(   r   r   r   Úecall_and_waita  s
    # 
 ÿz#SAMPIntegratedClient.ecall_and_waitc                 C   s   | j  |  ¡ ||¡S )z5
        Proxy to ``reply`` SAMP Hub method.
        )r   Úreplyr    )r   Úmsg_idÚresponser   r   r   r:   ˆ  s    zSAMPIntegratedClient.replyc                 C   s8   d|i}|d k	r|  d|i¡ |d k	r4|  d|i¡ |S )Nzsamp.statuszsamp.resultz
samp.errorr&   )r   ÚstatusÚresultÚerrorr)   r   r   r   Ú_format_easy_responseŽ  s    z*SAMPIntegratedClient._format_easy_responsec                 C   s   |   ||  |||¡¡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"})
        )r:   r@   )r   r;   r=   r>   r?   r   r   r   Úereply—  s    zSAMPIntegratedClient.ereplyc                 C   s   | j  |||¡S ©N)r   Úreceive_notification)r   Úprivate_keyÚ	sender_idr.   r   r   r   rC   ¸  s    z)SAMPIntegratedClient.receive_notificationc                 C   s   | j  ||||¡S rB   )r   Úreceive_call)r   rD   rE   r;   r.   r   r   r   rF   ½  s    z!SAMPIntegratedClient.receive_callc                 C   s   | j  ||||¡S rB   )r   Úreceive_response)r   rD   Zresponder_idr3   r<   r   r   r   rG   Â  s       ÿz%SAMPIntegratedClient.receive_responsec                 C   s   | j j||dd d� d S )NT)Údeclarer   )r   Úbind_receive_message©r   r%   ÚfunctionrH   r   r   r   r   rI   É  s    z)SAMPIntegratedClient.bind_receive_messagec                 C   s   | j  ||||¡ d S rB   )r   Úbind_receive_notificationrJ   r   r   r   rL   Î  s    z.SAMPIntegratedClient.bind_receive_notificationc                 C   s   | j  ||||¡ d S rB   )r   Úbind_receive_callrJ   r   r   r   rM   Ó  s    z&SAMPIntegratedClient.bind_receive_callc                 C   s   | j  ||¡ d S rB   )r   Úbind_receive_response)r   r3   rK   r   r   r   rN   Ø  s    z*SAMPIntegratedClient.bind_receive_responsec                 C   s   | j  ||¡ d S rB   )r   Úunbind_receive_notification©r   r%   rH   r   r   r   rO   Ý  s    z0SAMPIntegratedClient.unbind_receive_notificationc                 C   s   | j  ||¡ d S rB   )r   Úunbind_receive_callrP   r   r   r   rQ   â  s    z(SAMPIntegratedClient.unbind_receive_callc                 C   s   | j  |¡ d S rB   )r   Úunbind_receive_response)r   r3   r   r   r   rR   ç  s    z,SAMPIntegratedClient.unbind_receive_responsec                 C   s   | j  |¡ d S rB   )r   Údeclare_subscriptions)r   Zsubscriptionsr   r   r   rS   ì  s    z*SAMPIntegratedClient.declare_subscriptionsc                 C   s
   | j  ¡ S rB   )r   r    r   r   r   r   r    ñ  s    z$SAMPIntegratedClient.get_private_keyc                 C   s
   | j  ¡ S rB   )r   Úget_public_idr   r   r   r   rT   ö  s    z"SAMPIntegratedClient.get_public_id)NNNNr   T)NNr   )NN)TN)TN)TN)T)T)N)+Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r   r   r   r"   r#   r$   r+   r,   r/   r0   r1   r2   r4   r5   r6   r7   r9   r:   r@   rA   rC   r   rF   rG   rI   rL   rM   rN   rO   rQ   rR   rS   r    rT   r   r   r   r   r      st   $      ù


!&"'	
!

















N)r   r   Z	hub_proxyr   Ú__all__Z__doctest_skip__r   r   r   r   r   Ú<module>   s   