
    IR-e                         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 G d d	e          Z G d
 de          Zd ZdS )    )parse_qs)urlopen)get_pkg_data_contents   )SAMPSimpleXMLRPCRequestHandlerThreadingXMLRPCServerzdata/crossdomain.xmlzdata/clientaccesspolicy.xmlc                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )WebProfileRequestHandlerzG
    Handler of XMLRPC requests performed through the Web Profile.
    c                 R   | j                             d          | j                             d          }|r| j        dk    r|                     dd           |                     d| j                             d                     |                     d|           |                     dd	           |                     d
d           d S |                     d| j                             d                     |                     dd	           |                     d
d           d S d S )NOriginzAccess-Control-Request-MethodOPTIONSContent-Length0zAccess-Control-Allow-OriginzAccess-Control-Allow-MethodszAccess-Control-Allow-HeadersContent-Typez Access-Control-Allow-Credentialstrue)headersgetcommandsend_header)selfmethods     8lib/python3.11/site-packages/astropy/samp/web_profile.py_send_CORS_headerz*WebProfileRequestHandler._send_CORS_header   sA   <H%%1\%%&EFFF M$,)33  !13777  14<3C3CH3M3M     !?HHH  !?PPP  !CVLLLLL   14<3C3CH3M3M     !?PPP  !CVLLLLL# 21    c                 V    |                                   t          j        |            d S N)r   r   end_headersr   s    r   r   z$WebProfileRequestHandler.end_headers*   s+       &2488888r   c                    d}| j         dk    rt          }|                     dd           |                     dd           |                     dt	          |                      |                                  | j                            |                    d                     | j        	                                 d	}n| j         d
k    rt          }|                     dd           |                     dd           |                     dt	          |                      |                                  | j                            |                    d                     | j        	                                 d	}|S )NF/crossdomain.xml   OKr   ztext/x-cross-domain-policyr   zutf-8T/clientaccesspolicy.xmlztext/xml)pathCROSS_DOMAINsend_responser   lenr   wfilewriteencodeflushCLIENT_ACCESS_POLICY)r   cross_domainresponses      r   _serve_cross_domain_xmlz0WebProfileRequestHandler._serve_cross_domain_xml.   sh   9***#HsD)))^-IJJJ-#h--/ABBBJX__W55666JLLY333+HsD)))^Z888-#h--/ABBBJX__W55666JLr   c                 V    |                                  rd S t          j        |           S r   )r/   r   do_POSTr   s    r   r1   z WebProfileRequestHandler.do_POSTK   s,    '')) 	F-5d;;;r   c                     |                                  s|                                  d S |                                 rd S d S r   )is_http_path_valid
report_404r/   r   s    r   do_HEADz WebProfileRequestHandler.do_HEADQ   sN    &&(( 	OOF'')) 	F	 	r   c                 Z    |                      dd           |                                  d S )Nr!   r"   )r&   r   r   s    r   
do_OPTIONSz#WebProfileRequestHandler.do_OPTIONSY   s0    3%%%r   c                 x   |                                  s|                                  d S | j                            d          }|d         d | j        j        D             v rt          |d                   }	 t          |d         d                   }|                     dd           | 	                                 | j
                            |                                           |                                 n%# t          $ r |                                  Y d S w xY w|                                 rd S d S )N?r   c                     g | ]}d | S z/translator/ .0clids     r   
<listcomp>z3WebProfileRequestHandler.do_GET.<locals>.<listcomp>d   s!    SSSt2D22SSSr   r   refr!   r"   )r3   r4   r$   splitserverclientsr   r   r&   r   r(   r)   readcloseOSErrorr/   )r   
split_pathurlpath	proxyfiles       r   do_GETzWebProfileRequestHandler.do_GET]   s?   &&(( 	OOFY__S))
a=SSt{?RSSSSSz!}--G#GEN1$566	""3---  """
  !1!1222!!!!   !!! '')) 	F	 	s   9BC? ?D! D!c                 |    ddgd | j         j        D             z   }| j                            d          d         |v S )Nr#   r    c                     g | ]}d | S r;   r<   r=   s     r   r@   z?WebProfileRequestHandler.is_http_path_valid.<locals>.<listcomp>u   s4     I
 I
 I
&*!4!!I
 I
 I
r   r9   r   )rC   rD   r$   rB   )r   valid_pathss     r   r3   z+WebProfileRequestHandler.is_http_path_validt   sX    02DE I
 I
.2k.AI
 I
 I
 
 ys##A&+55r   N)__name__
__module____qualname____doc__r   r   r/   r1   r5   r7   rK   r3   r<   r   r   r
   r
      s         M M M(9 9 9  :< < <      .6 6 6 6 6r   r
   c                   0    e Zd ZdZdedddfdZd Zd ZdS )WebProfileXMLRPCServerz8
    XMLRPC server supporting the SAMP Web Profile.
    NTc           	      H    g | _         t          j        | ||||||           d S r   )rD   r   __init__)r   addrlogrequestHandlerlogRequests
allow_noneencodings          r   rV   zWebProfileXMLRPCServer.__init__   s9     &$^[*h	
 	
 	
 	
 	
r   c                 :    | j                             |           d S r   )rD   appendr   	client_ids     r   
add_clientz!WebProfileXMLRPCServer.add_client   s    I&&&&&r   c                 ^    	 | j                             |           d S # t          $ r Y d S w xY wr   )rD   remove
ValueErrorr_   s     r   remove_clientz$WebProfileXMLRPCServer.remove_client   sG    	L	***** 	 	 	 DD		s    
,,)rO   rP   rQ   rR   r
   rV   ra   re   r<   r   r   rT   rT   {   sa          /
 
 
 
' ' '    r   rT   c                    d}t          | d         t                    r	| d         }n| d         d         }d| d| d          d}t          |           t          d          }|                    |                                d	v            d S )
Nunknownr   z	samp.namez.A Web application which declares to be

Name: z	
Origin:    z

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]z>>> )yesy)
isinstancestrprintinputputlower)requestqueue	samp_nametextanswers        r   web_profile_text_dialogrv      s    I'!*c"" ,AJ		AJ{+	
&
& 
& 

& 
& 
&D 
$KKK6]]F	IIfllnn,-----r   N)urllib.parser   urllib.requestr   astropy.utils.datar   standard_profiler   r   __all__r%   r,   r
   rT   rv   r<   r   r   <module>r|      s    " ! ! ! ! ! " " " " " " 4 4 4 4 4 4 S S S S S S S S
$$%;<<,,-JKK g6 g6 g6 g6 g6= g6 g6 g6T    2   @. . . . .r   