
    IR-e                     ^    d dl Z d dlmZ ddlmZ ddlmZ ddlm	Z	 dgZ
 G d d          ZdS )    N   )SAMPHubError)get_main_running_hub)ServerProxyPoolSAMPHubProxyc                       e Zd ZdZd Zed             ZddZd Ze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   zh
    Proxy class to simplify the client interaction with a SAMP hub (via the
    standard profile).
    c                 "    d | _         d| _        d S )NF)proxy
_connectedselfs    6lib/python3.11/site-packages/astropy/samp/hub_proxy.py__init__zSAMPHubProxy.__init__   s    
    c                     | j         S )zH
        Whether the hub proxy is currently connected to a hub.
        )r   r   s    r   is_connectedzSAMPHubProxy.is_connected   s    
 r   N   c                 .   d| _         i | _        ||t          d          |.||j        st	          d          |j        }nt                      }	 |d                             dd          }t          |t          j
        |d	          | _        |                                  t          j        |          | _        d
| _         dS # t          j        $ r>}|j        dk    rt	          d          t	          d|j         d|j                   d}~ww xY w)a  
        Connect to the current SAMP Hub.

        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.
        FNz&Cannot specify both hub and hub_paramszHub is not runningzsamp.hub.xmlrpc.url\ r   )
allow_noneTi  z=Unauthorized access. Basic Authentication required or failed.zProtocol Error z: )r   lockfile
ValueError
is_runningr   paramsr   replacer   xmlrpcServerProxyr
   pingcopydeepcopyProtocolErrorerrcodeerrmsg)r   hub
hub_params	pool_sizeurlps         r   connectzSAMPHubProxy.connect   s>   $  ?z5EFFF~ ,&';<<<!$JJ133
	N23;;D"EEC(6-sq  DJ IIKKK M*55DM"DOOO# 	N 	N 	NyC"S   ##LQY#L#L!(#L#LMMM	Ns   A2C D9DDc                 p    | j          | j                                          d| _         d| _        i | _        dS )z7
        Disconnect from the current SAMP Hub.
        NF)r
   shutdownr   r   r   s    r   
disconnectzSAMPHubProxy.disconnectU   s9     :!J!!!DJr   c                 $    | j         j        j        S )z
        Property to abstract away the path to the hub, which allows this class
        to be used for other profiles.
        )r
   sampr%   r   s    r   	_samp_hubzSAMPHubProxy._samp_hub_   s     z""r   c                 4    | j                                         S )zL
        Proxy to ``ping`` SAMP Hub method (Standard Profile only).
        )r0   r   r   s    r   r   zSAMPHubProxy.pingg   s     ~""$$$r   c                 8    | j                             ||          S )zY
        Proxy to ``setXmlrpcCallback`` SAMP Hub method (Standard Profile only).
        )r0   setXmlrpcCallback)r   private_keyxmlrpc_addrs      r   set_xmlrpc_callbackz SAMPHubProxy.set_xmlrpc_callbackm   s     ~//[IIIr   c                 6    | j                             |          S )z8
        Proxy to ``register`` SAMP Hub method.
        )r0   register)r   secrets     r   r8   zSAMPHubProxy.registers   s     ~&&v...r   c                 6    | j                             |          S )z:
        Proxy to ``unregister`` SAMP Hub method.
        )r0   
unregisterr   r4   s     r   r;   zSAMPHubProxy.unregistery   s     ~((555r   c                 8    | j                             ||          S )z?
        Proxy to ``declareMetadata`` SAMP Hub method.
        )r0   declareMetadata)r   r4   metadatas      r   declare_metadatazSAMPHubProxy.declare_metadata   s     ~--k8DDDr   c                 8    | j                             ||          S )z;
        Proxy to ``getMetadata`` SAMP Hub method.
        )r0   getMetadatar   r4   	client_ids      r   get_metadatazSAMPHubProxy.get_metadata   s     ~))+yAAAr   c                 8    | j                             ||          S )zD
        Proxy to ``declareSubscriptions`` SAMP Hub method.
        )r0   declareSubscriptions)r   r4   subscriptionss      r   declare_subscriptionsz"SAMPHubProxy.declare_subscriptions   s     ~22;NNNr   c                 8    | j                             ||          S )z@
        Proxy to ``getSubscriptions`` SAMP Hub method.
        )r0   getSubscriptionsrC   s      r   get_subscriptionszSAMPHubProxy.get_subscriptions   s     ~..{IFFFr   c                 6    | j                             |          S )zD
        Proxy to ``getRegisteredClients`` SAMP Hub method.
        )r0   getRegisteredClientsr<   s     r   get_registered_clientsz#SAMPHubProxy.get_registered_clients   s     ~22;???r   c                 8    | j                             ||          S )zD
        Proxy to ``getSubscribedClients`` SAMP Hub method.
        )r0   getSubscribedClients)r   r4   mtypes      r   get_subscribed_clientsz#SAMPHubProxy.get_subscribed_clients   s     ~22;FFFr   c                 :    | j                             |||          S )z6
        Proxy to ``notify`` SAMP Hub method.
        )r0   notify)r   r4   recipient_idmessages       r   rU   zSAMPHubProxy.notify   s     ~$$[,HHHr   c                 8    | j                             ||          S )z9
        Proxy to ``notifyAll`` SAMP Hub method.
        )r0   	notifyAll)r   r4   rW   s      r   
notify_allzSAMPHubProxy.notify_all   s     ~''W===r   c                 <    | j                             ||||          S )z4
        Proxy to ``call`` SAMP Hub method.
        )r0   call)r   r4   rV   msg_tagrW   s        r   r\   zSAMPHubProxy.call   s      ~"";gwOOOr   c                 :    | j                             |||          S )z7
        Proxy to ``callAll`` SAMP Hub method.
        )r0   callAll)r   r4   r]   rW   s       r   call_allzSAMPHubProxy.call_all   s     ~%%k7GDDDr   c                 <    | j                             ||||          S )z;
        Proxy to ``callAndWait`` SAMP Hub method.
        )r0   callAndWait)r   r4   rV   rW   timeouts        r   call_and_waitzSAMPHubProxy.call_and_wait   s      ~))+|WgVVVr   c                 :    | j                             |||          S )z5
        Proxy to ``reply`` SAMP Hub method.
        )r0   reply)r   r4   msg_idresponses       r   rf   zSAMPHubProxy.reply   s     ~##KBBBr   )NNr   )__name__
__module____qualname____doc__r   propertyr   r*   r-   r0   r   r6   r8   r;   r@   rE   rI   rL   rO   rS   rU   rZ   r\   r`   rd   rf    r   r   r   r      s        
        X4N 4N 4N 4Nl   # # X#% % %J J J/ / /6 6 6E E EB B BO O OG G G@ @ @G G GI I I> > >P P PE E EW W WC C C C Cr   )r    xmlrpc.clientclientr   errorsr   lockfile_helpersr   utilsr   __all__r   rn   r   r   <module>ru      s                       2 2 2 2 2 2 " " " " " "
wC wC wC wC wC wC wC wC wC wCr   