U
    e»{jš  ã                   @   sP   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„ dƒZdS )é    Né   )ÚSAMPHubError)Úget_main_running_hub)ÚServerProxyPoolÚSAMPHubProxyc                   @   sÂ   e Zd ZdZdd„ Zedd„ ƒZd.dd	„Zd
d„ Ze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S )/r   zh
    Proxy class to simplify the client interaction with a SAMP hub (via the
    standard profile).
    c                 C   s   d | _ d| _d S )NF)ÚproxyÚ
_connected©Úself© r   úU/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/samp/hub_proxy.pyÚ__init__   s    zSAMPHubProxy.__init__c                 C   s   | j S )zH
        Whether the hub proxy is currently connected to a hub.
        )r   r	   r   r   r   Úis_connected   s    zSAMPHubProxy.is_connectedNé   c              
   C   sê   d| _ i | _|dk	r$|dk	r$tdƒ‚|dkrR|dk	rL|jsDtdƒ‚qR|j}ntƒ }zB|d  dd¡}t|t	j
|dd	�| _|  ¡  t |¡| _d
| _ W nP t	jk
rä } z0|jdkr¼tdƒ‚ntd|j› d|j› �ƒ‚W 5 d}~X Y nX dS )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Ú
ValueErrorZ
is_runningr   Úparamsr   Úreplacer   ÚxmlrpcÚServerProxyr   ÚpingÚcopyÚdeepcopyÚProtocolErrorÚerrcodeÚerrmsg)r
   ÚhubZ
hub_paramsZ	pool_sizeÚurlÚpr   r   r   Úconnect   s6    
   ÿ

ÿzSAMPHubProxy.connectc                 C   s*   | j dk	r| j  ¡  d| _ d| _i | _dS )z7
        Disconnect from the current SAMP Hub.
        NF)r   Úshutdownr   r   r	   r   r   r   Ú
disconnectV   s
    

zSAMPHubProxy.disconnectc                 C   s
   | 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   Zsampr   r	   r   r   r   Ú	_samp_hub`   s    zSAMPHubProxy._samp_hubc                 C   s
   | j  ¡ S )zL
        Proxy to ``ping`` SAMP Hub method (Standard Profile only).
        )r%   r   r	   r   r   r   r   h   s    zSAMPHubProxy.pingc                 C   s   | j  ||¡S )zY
        Proxy to ``setXmlrpcCallback`` SAMP Hub method (Standard Profile only).
        )r%   ZsetXmlrpcCallback)r
   Úprivate_keyZxmlrpc_addrr   r   r   Úset_xmlrpc_callbackn   s    z SAMPHubProxy.set_xmlrpc_callbackc                 C   s   | j  |¡S )z8
        Proxy to ``register`` SAMP Hub method.
        )r%   Úregister)r
   Úsecretr   r   r   r(   t   s    zSAMPHubProxy.registerc                 C   s   | j  |¡S )z:
        Proxy to ``unregister`` SAMP Hub method.
        )r%   Ú
unregister©r
   r&   r   r   r   r*   z   s    zSAMPHubProxy.unregisterc                 C   s   | j  ||¡S )z?
        Proxy to ``declareMetadata`` SAMP Hub method.
        )r%   ZdeclareMetadata)r
   r&   Úmetadatar   r   r   Údeclare_metadata€   s    zSAMPHubProxy.declare_metadatac                 C   s   | j  ||¡S )z;
        Proxy to ``getMetadata`` SAMP Hub method.
        )r%   ZgetMetadata©r
   r&   Z	client_idr   r   r   Úget_metadata†   s    zSAMPHubProxy.get_metadatac                 C   s   | j  ||¡S )zD
        Proxy to ``declareSubscriptions`` SAMP Hub method.
        )r%   ZdeclareSubscriptions)r
   r&   Zsubscriptionsr   r   r   Údeclare_subscriptionsŒ   s    z"SAMPHubProxy.declare_subscriptionsc                 C   s   | j  ||¡S )z@
        Proxy to ``getSubscriptions`` SAMP Hub method.
        )r%   ZgetSubscriptionsr.   r   r   r   Úget_subscriptions’   s    zSAMPHubProxy.get_subscriptionsc                 C   s   | j  |¡S )zD
        Proxy to ``getRegisteredClients`` SAMP Hub method.
        )r%   ZgetRegisteredClientsr+   r   r   r   Úget_registered_clients˜   s    z#SAMPHubProxy.get_registered_clientsc                 C   s   | j  ||¡S )zD
        Proxy to ``getSubscribedClients`` SAMP Hub method.
        )r%   ZgetSubscribedClients)r
   r&   Úmtyper   r   r   Úget_subscribed_clientsž   s    z#SAMPHubProxy.get_subscribed_clientsc                 C   s   | j  |||¡S )z6
        Proxy to ``notify`` SAMP Hub method.
        )r%   Únotify)r
   r&   Úrecipient_idÚmessager   r   r   r5   ¤   s    zSAMPHubProxy.notifyc                 C   s   | j  ||¡S )z9
        Proxy to ``notifyAll`` SAMP Hub method.
        )r%   Ú	notifyAll)r
   r&   r7   r   r   r   Ú
notify_allª   s    zSAMPHubProxy.notify_allc                 C   s   | j  ||||¡S )z4
        Proxy to ``call`` SAMP Hub method.
        )r%   Úcall)r
   r&   r6   Úmsg_tagr7   r   r   r   r:   °   s    zSAMPHubProxy.callc                 C   s   | j  |||¡S )z7
        Proxy to ``callAll`` SAMP Hub method.
        )r%   ZcallAll)r
   r&   r;   r7   r   r   r   Úcall_all¶   s    zSAMPHubProxy.call_allc                 C   s   | j  ||||¡S )z;
        Proxy to ``callAndWait`` SAMP Hub method.
        )r%   ZcallAndWait)r
   r&   r6   r7   Útimeoutr   r   r   Úcall_and_wait¼   s    zSAMPHubProxy.call_and_waitc                 C   s   | j  |||¡S )z5
        Proxy to ``reply`` SAMP Hub method.
        )r%   Úreply)r
   r&   Zmsg_idÚresponser   r   r   r?   Â   s    zSAMPHubProxy.reply)NNr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r"   r$   r%   r   r'   r(   r*   r-   r/   r0   r1   r2   r4   r5   r9   r:   r<   r>   r?   r   r   r   r   r      s0   

7

)r   Úxmlrpc.clientÚclientr   Úerrorsr   Zlockfile_helpersr   Úutilsr   Ú__all__r   r   r   r   r   Ú<module>   s   