
[c           @` s   d  d l  m Z m Z m Z m Z 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 d
 e f d     YZ d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   xmlrpc_clienti   (   t   SAMPHubError(   t   ServerProxyPool(   t   get_main_running_hubu   SAMPHubProxyt   SAMPHubProxyc           B` s   e  Z d  Z d   Z e d    Z d d d d  Z 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 RS(   uh   
    Proxy class to simplify the client interaction with a SAMP hub (via the
    standard profile).
    c         C` s   d  |  _ t |  _ d  S(   N(   t   Nonet   proxyt   Falset
   _connected(   t   self(    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   __init__   s    	c         C` s   |  j  S(   uH   
        Whether the hub proxy is currently connected to a hub.
        (   R   (   R   (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   is_connected   s    i   c         C` s7  t  |  _ i  |  _ | d k	 r9 | d k	 r9 t d   n  | d k r | d k	 ru | j si t d   q~ | j } q t   } n  y] | d j	 d d  } t
 | t j | d d |  _ |  j   t j |  |  _ t |  _ WnR t j k
 r2} | j d k rt d	   q3t d
 j | j | j    n Xd S(   u  
        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.
        u&   Cannot specify both hub and hub_paramsu   Hub is not runningu   samp.hub.xmlrpc.urlu   \u    t
   allow_nonei   i  u=   Unauthorized access. Basic Authentication required or failed.u   Protocol Error {}: {}N(   R   R   t   lockfileR	   t
   ValueErrort
   is_runningR   t   paramsR   t   replaceR   t   xmlrpct   ServerProxyR
   t   pingt   copyt   deepcopyt   Truet   ProtocolErrort   errcodet   formatt   errmsg(   R   t   hubt
   hub_paramst	   pool_sizet   urlt   p(    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   connect#   s,    			
c         C` s   d |  _ t |  _ i  |  _ d S(   u7   
        Disconnect from the current SAMP Hub.
        N(   R	   R
   R   R   R   (   R   (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt
   disconnect[   s    		c         C` s   |  j  j   d  S(   N(   R
   t   server_close(   R   (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyR'   c   s    c         C` s   |  j  j j S(   u   
        Property to abstract away the path to the hub, which allows this class
        to be used for other profiles.
        (   R
   t   sampR    (   R   (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt	   _samp_hubf   s    c         C` s   |  j  j   S(   uL   
        Proxy to ``ping`` SAMP Hub method (Standard Profile only).
        (   R)   R   (   R   (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyR   n   s    c         C` s   |  j  j | |  S(   uY   
        Proxy to ``setXmlrpcCallback`` SAMP Hub method (Standard Profile only).
        (   R)   t   setXmlrpcCallback(   R   t   private_keyt   xmlrpc_addr(    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   set_xmlrpc_callbackt   s    c         C` s   |  j  j |  S(   u8   
        Proxy to ``register`` SAMP Hub method.
        (   R)   t   register(   R   t   secret(    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyR.   z   s    c         C` s   |  j  j |  S(   u:   
        Proxy to ``unregister`` SAMP Hub method.
        (   R)   t
   unregister(   R   R+   (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyR0      s    c         C` s   |  j  j | |  S(   u?   
        Proxy to ``declareMetadata`` SAMP Hub method.
        (   R)   t   declareMetadata(   R   R+   t   metadata(    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   declare_metadata   s    c         C` s   |  j  j | |  S(   u;   
        Proxy to ``getMetadata`` SAMP Hub method.
        (   R)   t   getMetadata(   R   R+   t	   client_id(    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   get_metadata   s    c         C` s   |  j  j | |  S(   uD   
        Proxy to ``declareSubscriptions`` SAMP Hub method.
        (   R)   t   declareSubscriptions(   R   R+   t   subscriptions(    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   declare_subscriptions   s    c         C` s   |  j  j | |  S(   u@   
        Proxy to ``getSubscriptions`` SAMP Hub method.
        (   R)   t   getSubscriptions(   R   R+   R5   (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   get_subscriptions   s    c         C` s   |  j  j |  S(   uD   
        Proxy to ``getRegisteredClients`` SAMP Hub method.
        (   R)   t   getRegisteredClients(   R   R+   (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   get_registered_clients   s    c         C` s   |  j  j | |  S(   uD   
        Proxy to ``getSubscribedClients`` SAMP Hub method.
        (   R)   t   getSubscribedClients(   R   R+   t   mtype(    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   get_subscribed_clients   s    c         C` s   |  j  j | | |  S(   u6   
        Proxy to ``notify`` SAMP Hub method.
        (   R)   t   notify(   R   R+   t   recipient_idt   message(    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyRA      s    c         C` s   |  j  j | |  S(   u9   
        Proxy to ``notifyAll`` SAMP Hub method.
        (   R)   t	   notifyAll(   R   R+   RC   (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt
   notify_all   s    c         C` s   |  j  j | | | |  S(   u4   
        Proxy to ``call`` SAMP Hub method.
        (   R)   t   call(   R   R+   RB   t   msg_tagRC   (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyRF      s    c         C` s   |  j  j | | |  S(   u7   
        Proxy to ``callAll`` SAMP Hub method.
        (   R)   t   callAll(   R   R+   RG   RC   (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   call_all   s    c         C` s   |  j  j | | | |  S(   u;   
        Proxy to ``callAndWait`` SAMP Hub method.
        (   R)   t   callAndWait(   R   R+   RB   RC   t   timeout(    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   call_and_wait   s    c         C` s   |  j  j | | |  S(   u5   
        Proxy to ``reply`` SAMP Hub method.
        (   R)   t   reply(   R   R+   t   msg_idt   response(    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyRM      s    N(   t   __name__t
   __module__t   __doc__R   t   propertyR   R	   R%   R&   R'   R)   R   R-   R.   R0   R3   R6   R9   R;   R=   R@   RA   RE   RF   RI   RL   RM   (    (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyR      s.   	8																	(   t
   __future__R    R   R   R   R   t   extern.six.movesR   R   t   errorsR   t   utilsR   t   lockfile_helpersR   t   __all__t   objectR   (    (    (    s5   lib/python2.7/site-packages/astropy/samp/hub_proxy.pyt   <module>   s   "	