ó
ŠwÛjc           @   s0  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z m	 Z	 d  d l
 m Z d  d l m Z e j d ƒ Z e  j j e ƒ Z e j Z e  j j e d ƒ Z d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e	 f d „  ƒ  YZ d e j f d „  ƒ  YZ d e e d d „ Z e d k r,d  d l  Z  e  j! d d ƒ Z" e" j# d d d e$ d d d d ƒe" j# d d d d d e% d d d d  ƒe" j# d! d" d d# d e& d d$ d d% ƒe" j# d& d d' d e' d d( d d) ƒe" j# d* d d+ d e' d d, ƒe" j# d- d d. d e' d d( d d/ ƒe" j( ƒ  Z) e) j* e _* e) j+ r\e Z, n e Z, e  j- ƒ  e, _. e j/ e j0 j1 ƒ Z2 e2 j3 e ƒ e) j4 r¯e2 j5 e) j4 ƒ n  e) j6 rËe2 j7 e) j6 ƒ n  e) j8 rçe2 j9 e) j8 ƒ n  e d0 e) j: f e, e2 ƒ Z; e) j* rd1 j< e) ƒ GHn  e; j= d2 ƒ n  d S(3   iÿÿÿÿN(   t
   HTTPServert   BaseHTTPRequestHandler(   t   SimpleHTTPRequestHandler(   t   test_supportt	   threadings   keycert.pemt   HTTPSServerc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s    t  j |  | | ƒ | |  _ d  S(   N(   t   _HTTPServert   __init__t   context(   t   selft   server_addresst   handler_classR   (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyR      s    c         C   s   d |  j  j |  j |  j f S(   Ns
   <%s %s:%s>(   t	   __class__t   __name__t   server_namet   server_port(   R	   (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyt   __str__   s    	c         C   st   y1 |  j  j ƒ  \ } } |  j j | d t ƒ} Wn6 t k
 ri } t j rc t j	 j
 d | ƒ n  ‚  n X| | f S(   Nt   server_sides   Got an error:
%s
(   t   sockett   acceptR   t   wrap_sockett   Truet   OSErrort   supportt   verboset   syst   stderrt   write(   R	   t   sockt   addrt   sslconnt   e(    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyt   get_request!   s    	c         C   s#   t  j r t j |  | | ƒ n  d S(   s&   Suppose noisy error output by default.N(   R   R   R   t   handle_error(   R	   t   requestt   client_address(    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyR!   -   s    	(   R   t
   __module__R   R   R    R!   (    (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyR      s   			t   RootedHTTPRequestHandlerc           B   s,   e  Z d  Z e Z d Z d „  Z d „  Z RS(   s   TestHTTPS/1.0i   c         C   s¯   t  j  | ƒ d } t j j t j | ƒ ƒ } | j d ƒ } t d | ƒ } |  j	 } xS | D]K } t j j
 | ƒ \ } } t j j | ƒ \ } } t j j | | ƒ } q\ W| S(   sñ   Translate a /-separated PATH to the local filename syntax.

        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        i   t   /N(   t   urlparset   ost   patht   normpatht   urllibt   unquotet   splitt   filtert   Nonet   roott
   splitdrivet   join(   R	   R)   t   wordst   wordt   drivet   head(    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyt   translate_path<   s    		c         G   sR   t  j rN t j j d |  j j |  j j |  j j	 ƒ  |  j
 ƒ  | | f ƒ n  d  S(   Ns    server (%s:%d %s):
   [%s] %s
(   R   R   R   t   stdoutR   t   serverR
   R   R"   t   ciphert   log_date_time_string(   R	   t   formatt   args(    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyt   log_messageP   s    				(   R   R$   t   server_versiont   hereR0   t   timeoutR7   R>   (    (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyR%   2   s
   	t   StatsRequestHandlerc           B   s2   e  Z d  Z d Z e d „ Z d „  Z d „  Z RS(   sS   Example HTTP request handler which returns SSL statistics on GET
    requests.
    s   StatsHTTPS/1.0c         C   sÃ   |  j  j j } | j } i | j ƒ  d 6| j ƒ  d 6| j ƒ  d 6} t j | ƒ } | j	 d ƒ } |  j
 d ƒ |  j d d ƒ |  j d t t | ƒ ƒ ƒ |  j ƒ  | r¿ |  j j | ƒ n  d	 S(
   s   Serve a GET request.t   session_cacheR:   t   compressions   utf-8iÈ   s   Content-types   text/plain; charset=utf-8s   Content-LengthN(   t   rfilet   rawt   _sockR   t   session_statsR:   RD   t   pprintt   pformatt   encodet   send_responset   send_headert   strt   lent   end_headerst   wfileR   (   R	   t	   send_bodyR   R   t   statst   body(    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyt   do_GETb   s    	
c         C   s   |  j  d t ƒ d S(   s   Serve a HEAD request.RR   N(   RU   t   False(   R	   (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyt   do_HEADt   s    c         G   s#   t  j r t j |  | | Œ n  d  S(   N(   R   R   R   t   log_request(   R	   R<   R=   (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyRX   x   s    	(   R   R$   t   __doc__R?   R   RU   RW   RX   (    (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyRB   [   s
   	t   HTTPSServerThreadc           B   s>   e  Z e d d  „ Z d „  Z d d „ Z d „  Z d „  Z RS(   c         C   sV   d  |  _ t | d f | p t | ƒ |  _ |  j j |  _ t j j	 |  ƒ t
 |  _ d  S(   Ni    (   R/   t   flagR   R%   R9   R   t   portR   t   ThreadR   R   t   daemon(   R	   R   t   hostR   (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyR      s    		c         C   s   d |  j  j |  j f S(   Ns   <%s %s>(   R   R   R9   (   R	   (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyR   ˆ   s    c         C   s   | |  _  t j j |  ƒ d  S(   N(   R[   R   R]   t   start(   R	   R[   (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyR`   ‹   s    	c         C   sB   |  j  r |  j  j ƒ  n  z |  j j d ƒ Wd  |  j j ƒ  Xd  S(   Ngš™™™™™©?(   R[   t   setR9   t   serve_forevert   server_close(   R	   (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyt   run�   s
    	c         C   s   |  j  j ƒ  d  S(   N(   R9   t   shutdown(   R	   (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyt   stop—   s    N(	   R   R$   t   HOSTR/   R   R   R`   Rd   Rf   (    (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyRZ   }   s
   			c            s†   | d  k r$ t j t j j ƒ } n  | j | ƒ t | | | ƒ ‰  t j ƒ  } ˆ  j	 | ƒ | j
 ƒ  ‡  f d †  } |  j | ƒ ˆ  S(   Nc              sP   t  j r t j j d ƒ n  ˆ  j ƒ  t  j rB t j j d ƒ n  ˆ  j ƒ  d  S(   Ns   stopping HTTPS server
s   joining HTTPS thread
(   R   R   R   R8   R   Rf   R2   (    (   R9   (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyt   cleanup¥   s    	
	(   R/   t   sslt   create_default_contextt   Purposet   CLIENT_AUTHt   load_cert_chainRZ   R   t   EventR`   t   waitt
   addCleanup(   t   caseR   t   certfileR_   R   R[   Rh   (    (   R9   s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyt   make_https_server›   s    
t   __main__t   descriptionsE   Run a test HTTPS server. By default, the current directory is served.s   -ps   --portt   typet   defaultiQ  t   helps(   port to listen on (default: %(default)s)s   -qs   --quiett   destR   t   actiont   store_falses   be less verboses   -ss   --statst   use_stats_handlert
   store_trues   always return stats pages   --curve-namet
   curve_namet   stores&   curve name for EC-based Diffie-Hellmans	   --cipherst   cipherss   allowed cipher lists   --dht   dh_files!   PEM file containing DH parameterst    s'   Listening on https://localhost:{0.port}gš™™™™™¹?(>   R(   R   Ri   RI   R+   R'   t   BaseHTTPServerR    R   R   t   SimpleHTTPServerR   t   testR   R   t   import_moduleR   R)   t   dirnamet   __file__R@   Rg   R2   t   CERTFILER   R%   RB   R]   RZ   R/   Rs   R   t   argparset   ArgumentParsert   parsert   add_argumentt   intR   RV   RN   t
   parse_argsR=   R   R|   R   t   getcwdR0   Rj   Rk   Rl   R   Rm   R~   t   set_ecdh_curveR�   t   load_dh_paramsR€   t   set_ciphersR\   R9   R<   Rb   (    (    (    s†   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/ssl_servers.pyt   <module>   sj   	)"								