σ
ίΘ[c           @` sΟ   d  d l  m Z m Z m Z m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z m Z g  Z e d	  Z e d
  Z d e f d     YZ d e f d     YZ d   Z d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   parse_qs(   t   urlopen(   t   input(   t   get_pkg_data_contentsi   (   t   SAMPSimpleXMLRPCRequestHandlert   ThreadingXMLRPCServeru   data/crossdomain.xmlu   data/clientaccesspolicy.xmlt   WebProfileRequestHandlerc           B` sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   uG   
    Handler of XMLRPC requests performed through the Web Profile.
    c         C` sα   |  j  j d  d  k	 rέ |  j  j d  } | r |  j d k r |  j d d  |  j d |  j  j d   |  j d |  |  j d d	  |  j d
 d  qέ |  j d |  j  j d   |  j d d	  |  j d
 d  n  d  S(   Nu   Originu   Access-Control-Request-Methodu   OPTIONSu   Content-Lengthu   0u   Access-Control-Allow-Originu   Access-Control-Allow-Methodsu   Access-Control-Allow-Headersu   Content-Typeu    Access-Control-Allow-Credentialsu   true(   t   headerst   gett   Nonet   commandt   send_header(   t   selft   method(    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyt   _send_CORS_header   s    		c         C` s   |  j    t j |   d  S(   N(   R   R   t   end_headers(   R   (    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyR   -   s    
c         C` s$  t  } |  j d k r t } |  j d d  |  j d d  |  j d d j t |    |  j   |  j j	 | j
 d   |  j j   t } n |  j d	 k r t } |  j d d  |  j d d
  |  j d d j t |    |  j   |  j j	 | j
 d   |  j j   t } n  | S(   Nu   /crossdomain.xmliΘ   u   OKu   Content-Typeu   text/x-cross-domain-policyu   Content-Lengthu   {0}u   utf-8u   /clientaccesspolicy.xmlu   text/xml(   t   Falset   patht   CROSS_DOMAINt   send_responseR   t   formatt   lenR   t   wfilet   writet   encodet   flusht   Truet   CLIENT_ACCESS_POLICY(   R   t   cross_domaint   response(    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyt   _serve_cross_domain_xml1   s(    
	
	c         C` s   |  j    r d  St j |   S(   N(   R"   R   t   do_POST(   R   (    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyR#   Q   s    c         C` s.   |  j    s |  j   d  S|  j   r* d  Sd  S(   N(   t   is_http_path_validt
   report_404R"   (   R   (    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyt   do_HEADW   s
    
c         C` s   |  j  d d  |  j   d  S(   NiΘ   u   OK(   R   R   (   R   (    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyt
   do_OPTIONS`   s    c         C` sφ   |  j    s |  j   d  S|  j j d  } | d g  |  j j D] } d j |  ^ q@ k rβ t | d  } yR t | d d  } |  j	 d d  |  j
   |  j j | j    | j   Wqβ t k
 rή |  j   d  SXn  |  j   rς d  Sd  S(   Nu   ?i    u   /translator/{}i   u   refiΘ   u   OK(   R$   R%   R   t   splitt   servert   clientsR   R   R   R   R   R   R   t   readt   closet   IOErrorR"   (   R   t
   split_patht   clidt   urlpatht	   proxyfile(    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyt   do_GETe   s"    
2

c         C` sL   d d g g  |  j  j D] } d j |  ^ q } |  j j d  d | k S(   Nu   /clientaccesspolicy.xmlu   /crossdomain.xmlu   /translator/{}u   ?i    (   R)   R*   R   R   R(   (   R   R/   t   valid_paths(    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyR$   }   s    	)(   t   __name__t
   __module__t   __doc__R   R   R"   R#   R&   R'   R2   R$   (    (    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyR
      s   			 					t   WebProfileXMLRPCServerc           B` s8   e  Z d  Z d e e e d d  Z d   Z d   Z RS(   u8   
    XMLRPC server supporting the SAMP Web Profile.
    c         C` s,   g  |  _  t j |  | | | | | |  d  S(   N(   R*   R	   t   __init__(   R   t   addrt   logt   requestHandlert   logRequestst
   allow_nonet   encoding(    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyR8      s    	c         C` s   |  j  j |  d  S(   N(   R*   t   append(   R   t	   client_id(    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyt
   add_client   s    c         C` s,   y |  j  j |  Wn t k
 r' n Xd  S(   N(   R*   t   removet
   ValueError(   R   R@   (    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyt   remove_client   s    N(	   R4   R5   R6   R   R
   R   R8   RA   RD   (    (    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyR7      s
   	c         C` s}   d } t  |  d t  r& |  d } n |  d d } d j | |  d  } t |  t d  } | j | j   d	 k  d  S(
   Nu   unknowni    u	   samp.nameu  A Web application which declares to be

Name: {}
Origin: {}

is requesting to be registered with the SAMP Hub.
Pay attention that if you permit its registration, such
application will acquire all current user privileges, like
file read/write.

Do you give your consent? [yes|no]i   u   >>> u   yesu   y(   u   yesu   y(   t
   isinstancet   strR   t   printR   t   putt   lower(   t   requestt   queuet	   samp_namet   textt   answer(    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyt   web_profile_text_dialog   s    
N(   t
   __future__R    R   R   R   t   extern.six.moves.urllib.parseR   t   extern.six.moves.urllib.requestR   t   extern.six.movesR   t
   utils.dataR   t   standard_profileR   R	   t   __all__R   R   R
   R7   RO   (    (    (    s7   lib/python2.7/site-packages/astropy/samp/web_profile.pyt   <module>   s   "p