ó
‹wÛjc           @   s#  d  Z  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 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 d d l m Z d d l m Z e j d ƒ Z d	 d# d
 „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d e
 j f d „  ƒ  YZ d e
 j f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d Z  d Z! d Z" e
 j# e$ e d ƒ oÅe j% ƒ  d k d ƒ d e f d „  ƒ  Yƒ Z& d e
 j f d  „  ƒ  YZ' d d! „ Z) e* d" k re) ƒ  n  d S($   s±   Unittests for the various HTTPServer modules.

Written by Cody A.W. Somerville <cody-somerville@ubuntu.com>,
Josip Dzolonga, and Michael Otteneder for the 2007/08 GHOP contest.
iÿÿÿÿN(   t   BaseHTTPRequestHandlert
   HTTPServer(   t   SimpleHTTPRequestHandler(   t   CGIHTTPRequestHandler(   t   StringIO(   t   test_supportt	   threadingt   NoLogRequestHandlerc           B   s   e  Z d  „  Z RS(   c         G   s   d  S(   N(    (   t   selft   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/test_httpservers.pyt   log_message   s    (   t   __name__t
   __module__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/test_httpservers.pyR      s   t   SocketlessRequestHandlerc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s   t  |  _ d |  _ d  S(   Ns   HTTP/1.1(   t   Falset
   get_calledt   protocol_version(   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/test_httpservers.pyt   __init__$   s    	c         C   sD   t  |  _ |  j d ƒ |  j d d ƒ |  j ƒ  |  j j d ƒ d  S(   NiÈ   s   Content-Types	   text/htmls    <html><body>Data</body></html>
(   t   TrueR   t   send_responset   send_headert   end_headerst   wfilet   write(   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/test_httpservers.pyt   do_GET(   s
    	
c         G   s   d  S(   N(    (   R   t   fmtR	   (    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyR
   /   s    (   R   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/test_httpservers.pyR   #   s   		t   TestServerThreadc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s&   t  j j |  ƒ | |  _ | |  _ d  S(   N(   R   t   ThreadR   t   request_handlert   test_object(   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/test_httpservers.pyR   4   s    	c         C   s{   t  d |  j ƒ |  _ |  j j j ƒ  \ |  j _ |  j _ |  j j j	 ƒ  d  |  _ z |  j j d ƒ Wd  |  j j ƒ  Xd  S(   Nt	   localhosti    gš™™™™™©?(   R   i    (   R   R   t   servert   sockett   getsocknameR   t   HOSTt   PORTt   server_startedt   sett   Nonet   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/test_httpservers.pyt   run9   s    $	c         C   s   |  j  j ƒ  |  j ƒ  d  S(   N(   R   t   shutdownt   join(   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/test_httpservers.pyt   stopC   s    (   R   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/test_httpservers.pyR   3   s   		
t   BaseTestCasec           B   s,   e  Z d  „  Z d „  Z d d i  d „ Z RS(   c         C   s`   t  j ƒ  |  _ t  j ƒ  t _ t j ƒ  |  _ t	 |  |  j
 ƒ |  _ |  j j ƒ  |  j j ƒ  d  S(   N(   R   t   threading_setupt   _threadst   EnvironmentVarGuardt   ost   environR   t   EventR$   R   R   t   threadt   startt   wait(   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/test_httpservers.pyt   setUpI   s    c         C   s.   |  j  j ƒ  t j j ƒ  t j |  j Œ  d  S(   N(   R4   R,   R1   R2   t   __exit__R   t   threading_cleanupR/   (   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/test_httpservers.pyt   tearDownQ   s    t   GETc         C   sA   t  j |  j |  j ƒ |  _ |  j j | | | | ƒ |  j j ƒ  S(   N(   t   httplibt   HTTPConnectionR"   R#   t
   connectiont   requestt   getresponse(   R   t   urit   methodt   bodyt   headers(    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyR?   V   s    N(   R   R   R7   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/test_httpservers.pyR-   H   s   		t   BaseHTTPRequestHandlerTestCasec           B   sw   e  Z d  Z e j d ƒ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   sZ   Test the functionality of the BaseHTTPServer focussing on
    BaseHTTPRequestHandler.
    s   HTTP/1.[0-9]+ 200 OKc         C   s   t  ƒ  |  _ d  S(   N(   R   t   handler(   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/test_httpservers.pyR7   b   s    c         C   sQ   t  | ƒ } t  ƒ  } | |  j _ | |  j _ |  j j ƒ  | j d ƒ | j ƒ  S(   Ni    (   R   RF   t   rfileR   t   handle_one_requestt   seekt	   readlines(   R   t   messaget	   input_msgt   output(    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   send_typical_requeste   s    	c         C   s   |  j  |  j j ƒ d  S(   N(   t
   assertTrueRF   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/test_httpservers.pyt   verify_get_calledn   s    c            s;   x4 d D], ‰  |  j  t ‡  f d †  | Dƒ ƒ d ƒ q Wd  S(   Ns   Server: s   Date: s   Content-Type: c         3   s   |  ] } | j  ˆ  ƒ Vq d  S(   N(   t
   startswith(   t   .0t   h(   t	   fieldName(    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pys	   <genexpr>s   s    i   (   s   Server: s   Date: s   Content-Type: (   t   assertEqualt   sum(   R   RD   (    (   RT   s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   verify_expected_headersq   s    c         C   s#   |  j  j | ƒ } |  j | ƒ d  S(   N(   t   HTTPResponseMatcht   searcht   assertIsNotNone(   R   t   responset   match(    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   verify_http_server_responseu   s    c         C   sV   |  j  d ƒ } |  j | d ƒ |  j | d d !ƒ |  j ƒ  |  j | d d ƒ d  S(   Ns   GET / HTTP/1.1

i    i   iÿÿÿÿs    <html><body>Data</body></html>
(   RN   R]   RW   RP   RU   (   R   t   result(    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   test_http_1_1y   s
    
c         C   sV   |  j  d ƒ } |  j | d ƒ |  j | d d !ƒ |  j ƒ  |  j | d d ƒ d  S(   Ns   GET / HTTP/1.0

i    i   iÿÿÿÿs    <html><body>Data</body></html>
(   RN   R]   RW   RP   RU   (   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/test_httpservers.pyt   test_http_1_0€   s
    
c         C   sG   |  j  d ƒ } |  j t | ƒ d ƒ |  j | d d ƒ |  j ƒ  d  S(   Ns   GET / HTTP/0.9

i   i    s    <html><body>Data</body></html>
(   RN   RU   t   lenRP   (   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/test_httpservers.pyt   test_http_0_9‡   s    c         C   sV   |  j  d ƒ } |  j | d ƒ |  j | d d !ƒ |  j ƒ  |  j | d d ƒ d  S(   Ns(   GET / HTTP/1.0
Expect: 100-continue

i    i   iÿÿÿÿs    <html><body>Data</body></html>
(   RN   R]   RW   RP   RU   (   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/test_httpservers.pyt   test_with_continue_1_0�   s
    
c         C   sB   |  j  d d d ƒ } |  j | d d ƒ |  j |  j j ƒ d  S(   Ns   GET t   xi  i    s#   HTTP/1.1 414 Request-URI Too Long
(   RN   RU   t   assertFalseRF   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/test_httpservers.pyt   test_request_length”   s    (   R   R   t   __doc__t   ret   compileRX   R7   RN   RP   RW   R]   R_   R`   Rb   Rc   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/test_httpservers.pyRE   [   s   										t   BaseHTTPServerTestCasec           B   sº   e  Z d  e e f d „  ƒ  YZ 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(   R   c           B   sJ   e  Z d  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s   HTTP/1.1c         C   s;   |  j  d ƒ |  j d d ƒ |  j d d ƒ |  j ƒ  d  S(   NiÌ   s   Content-Types	   text/htmlt
   Connectiont   close(   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/test_httpservers.pyt   do_TEST¡   s    c         C   s;   |  j  d ƒ |  j d d ƒ |  j d d ƒ |  j ƒ  d  S(   NiÌ   s   Content-Types	   text/htmlRk   s
   keep-alive(   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/test_httpservers.pyt   do_KEEP§   s    c         C   s   |  j  d ƒ d  S(   Niç  (   t
   send_error(   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/test_httpservers.pyt   do_KEYERROR­   s    c         C   s;   |  j  d ƒ |  j d d ƒ |  j d d ƒ |  j ƒ  d  S(   Niç  s   Content-Types	   text/htmlRk   Rl   (   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/test_httpservers.pyt	   do_CUSTOM°   s    c         C   s   |  j  t |  j d ƒ ƒ d  S(   Ni   (   Ro   t   intt   path(   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/test_httpservers.pyt   do_SEND_ERROR¶   s    c         C   s   |  j  t |  j d ƒ ƒ d  S(   Ni   (   Ro   Rr   Rs   (   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/test_httpservers.pyt   do_HEAD¹   s    (
   R   R   R   t   default_request_versionRm   Rn   Rp   Rq   Rt   Ru   (    (    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyR   �   s   					c         C   s9   t  j |  ƒ t j |  j |  j ƒ |  _ |  j j ƒ  d  S(   N(   R-   R7   R<   R=   R"   R#   t   cont   connect(   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/test_httpservers.pyR7   ¼   s    c         C   s9   |  j  j d d ƒ |  j  j ƒ  } |  j | j d ƒ d  S(   NR;   t   /iõ  (   Rw   R?   R@   RU   t   status(   R   t   res(    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   test_commandÁ   s    c         C   sR   d |  j  _ |  j  j d d ƒ |  j  j ƒ  |  j  j ƒ  } |  j | j d ƒ d  S(   Ns	   HTTP/1.1
t   XYZBOGUSRy   iõ  (   Rw   t   _http_vsn_strt
   putrequestt
   endheadersR@   RU   Rz   (   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/test_httpservers.pyt   test_request_line_trimmingÆ   s
    c         C   sR   d |  j  _ |  j  j d d ƒ |  j  j ƒ  |  j  j ƒ  } |  j | j d ƒ d  S(   Nt   FUBARR;   Ry   i�  (   Rw   R~   R   R€   R@   RU   Rz   (   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/test_httpservers.pyt   test_version_bogusÍ   s
    c         C   sR   d |  j  _ |  j  j d d ƒ |  j  j ƒ  |  j  j ƒ  } |  j | j d ƒ d  S(   Ns
   HTTP/9.9.9R;   Ry   i�  (   Rw   R~   R   R€   R@   RU   Rz   (   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/test_httpservers.pyt   test_version_digitsÔ   s
    c         C   sR   d |  j  _ |  j  j d d ƒ |  j  j ƒ  |  j  j ƒ  } |  j | j d ƒ d  S(   Nt    R;   Ry   iõ  (   Rw   R~   R   R€   R@   RU   Rz   (   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/test_httpservers.pyt   test_version_none_getÛ   s
    c         C   sR   d |  j  _ |  j  j d d ƒ |  j  j ƒ  |  j  j ƒ  } |  j | j d ƒ d  S(   NR…   t   CUSTOMRy   i�  (   Rw   R~   R   R€   R@   RU   Rz   (   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/test_httpservers.pyt   test_version_noneâ   s
    c         C   s^   d |  j  _ d |  j  _ |  j  j d d ƒ |  j  j ƒ  |  j  j ƒ  } |  j | j d ƒ d  S(   Nic   s   HTTP/9.9R;   Ry   iù  (   Rw   t	   _http_vsnR~   R   R€   R@   RU   Rz   (   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/test_httpservers.pyt   test_version_invalidê   s    c         C   sR   d |  j  _ |  j  j d d ƒ |  j  j ƒ  |  j  j ƒ  } |  j | j d ƒ d  S(   NR…   i�  (   Rw   R~   R   R€   R@   RU   Rz   (   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/test_httpservers.pyt   test_send_blankò   s
    c         C   sY   |  j  j d d ƒ |  j  j d d ƒ |  j  j ƒ  |  j  j ƒ  } |  j | j d ƒ d  S(   NR;   Ry   Rk   Rl   iõ  (   Rw   R   t	   putheaderR€   R@   RU   Rz   (   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/test_httpservers.pyt   test_header_closeù   s
    c         C   se   d |  j  _ |  j  j d d ƒ |  j  j d d ƒ |  j  j ƒ  |  j  j ƒ  } |  j | j d ƒ d  S(   Ns   HTTP/1.1R;   Ry   Rk   s
   keep-aliveiõ  (   Rw   R~   R   RŒ   R€   R@   RU   Rz   (   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/test_httpservers.pyt   test_head_keep_alive   s    c         C   s9   |  j  j d d ƒ |  j  j ƒ  } |  j | j d ƒ d  S(   Nt   TESTRy   iÌ   (   Rw   R?   R@   RU   Rz   (   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/test_httpservers.pyt   test_handler  s    c         C   se   |  j  j d d ƒ |  j  j ƒ  } |  j | j d ƒ d ƒ |  j  j d d ƒ |  j |  j  j ƒ d  S(   Nt   KEEPRy   Rk   s
   keep-aliveR�   (   Rw   R?   R@   RU   t	   getheadert
   addCleanupRl   (   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/test_httpservers.pyt   test_return_header_keep_alive  s
    c         C   s9   |  j  j d d ƒ |  j  j ƒ  } |  j | j d ƒ d  S(   Nt   KEYERRORRy   iç  (   Rw   R?   R@   RU   Rz   (   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/test_httpservers.pyt   test_internal_key_error  s    c         C   s9   |  j  j d d ƒ |  j  j ƒ  } |  j | j d ƒ d  S(   NR‡   Ry   iç  (   Rw   R?   R@   RU   Rz   (   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/test_httpservers.pyt   test_return_custom_status  s    c         C   sÏ   d } xÂ d D]º } |  j  j d d j | ƒ ƒ |  j  j ƒ  } |  j | | j ƒ |  j d  | j d ƒ ƒ |  j d  | j d	 ƒ ƒ | | k r« |  j d  | j d
 ƒ ƒ n  | j ƒ  } |  j d | ƒ q Wd  S(   NiÍ   i0  ie   if   iÌ   t
   SEND_ERRORs   /{}s   Content-Lengths   Content-Types   Transfer-EncodingR…   (   iÍ   i0  (   ie   if   iÌ   iÍ   i0  (	   Rw   R?   t   formatR@   RU   Rz   R&   R’   t   read(   R   t   allow_transfer_encoding_codest   codeR{   t   data(    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   test_send_error  s    c         C   s  d } xd D]û } |  j  j d d j | ƒ ƒ |  j  j ƒ  } |  j | | j ƒ | d k r’ |  j d  | j d ƒ ƒ |  j d	 | j d
 ƒ ƒ n2 |  j d  | j d ƒ ƒ |  j d  | j d
 ƒ ƒ | | k rì |  j d  | j d ƒ ƒ n  | j	 ƒ  } |  j d | ƒ q Wd  S(   NiÍ   i0  ie   iÈ   iÌ   t   HEADs   /{}s   Content-Lengths	   text/htmls   Content-Types   Transfer-EncodingR…   (   iÍ   i0  (   ie   iÈ   iÌ   iÍ   i0  (
   Rw   R?   R™   R@   RU   Rz   R&   R’   t   assertInRš   (   R   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/test_httpservers.pyt   test_head_via_send_error,  s    (   R   R   R   R    R   R7   R|   R�   Rƒ   R„   R†   Rˆ   RŠ   R‹   R�   RŽ   R�   R”   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/test_httpservers.pyRj   œ   s$   																t   SimpleHTTPServerTestCasec           B   sc   e  Z d  e e f d „  ƒ  YZ d „  Z d „  Z d	 d „ Z d „  Z	 d „  Z
 d „  Z d „  Z RS(
   R   c           B   s   e  Z RS(    (   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/test_httpservers.pyR   @  s   c         C   sº   t  j |  ƒ t j ƒ  |  _ t j ƒ  } t j | ƒ d |  _ t j	 d | ƒ |  _
 t j j |  j
 ƒ |  _ d |  j |  _ t t j j |  j
 d ƒ d ƒ } | j |  j ƒ | j ƒ  d  S(   Ns   We are the knights who say Ni!t   dirRy   t   testt   wb(   R-   R7   R1   t   getcwdt   cwdt   tempfilet
   gettempdirt   chdirR�   t   mkdtempt   tempdirRs   t   basenamet   tempdir_namet   base_urlt   openR+   R   Rl   (   R   t   basetempdirt   temp(    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyR7   C  s    	!c         C   sQ   z< t  j |  j ƒ y t j |  j ƒ Wn t k
 r: n XWd  t j |  ƒ Xd  S(   N(	   R1   Rª   R§   t   shutilt   rmtreeR¬   t   OSErrorR-   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/test_httpservers.pyR:   P  s    c         C   sY   | j  ƒ  } |  j | ƒ |  j | j | ƒ |  j | j ƒ | rU |  j | | ƒ n  d  S(   N(   Rš   RO   RU   Rz   RZ   t   reason(   R   R[   Rz   R�   RC   (    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   check_status_and_reasonZ  s    c         C   s  |  j  |  j d ƒ } |  j | d d |  j ƒ|  j  |  j d ƒ } |  j | d ƒ |  j  |  j d ƒ } |  j | d ƒ |  j  |  j ƒ } |  j | d ƒ |  j  |  j d ƒ } |  j | d ƒ |  j  |  j d	 ƒ } |  j | d ƒ |  j | j d
 ƒ |  j d ƒ |  j  d ƒ } |  j | d ƒ |  j  d ƒ } |  j | d ƒ t t j j	 |  j
 d ƒ d ƒ �� } |  j  |  j d ƒ } |  j | d ƒ t j d k rt j ƒ  d k rt j |  j d ƒ |  j  |  j d ƒ } |  j | d ƒ t j |  j d ƒ n  Wd  QXd  S(   Ns   /testiÈ   R�   s   /test/i”  Ry   i-  s   /?hi=2s   ?hi=1t   Locations   /?hi=1s   /ThisDoesNotExistt   ThisDoesNotExists
   index.htmlt   wt   posixi    ií  s   /ThisDoesNotExists   /ThisDoesNotExist/(   R?   R¯   R·   R�   RU   R’   R°   R1   Rs   R+   R®   t   namet   geteuidt   chmodR¬   (   R   R[   t   fp(    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   test_getb  s4    $!c         C   sq   |  j  |  j d d d ƒ} |  j | d ƒ |  j | j d ƒ t t |  j ƒ ƒ ƒ |  j | j d ƒ d ƒ d  S(   Ns   /testRB   RŸ   iÈ   s   content-lengths   content-types   application/octet-stream(   R?   R¯   R·   RU   R’   t   strRa   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/test_httpservers.pyt	   test_head‚  s    c         C   ss   |  j  d d d ƒ} |  j | d ƒ |  j  d d d ƒ} |  j | d ƒ |  j  d d d ƒ} |  j | d ƒ d  S(   NRy   RB   t   FOOiõ  t   customt   GETs(   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/test_httpservers.pyt   test_invalid_requests‹  s    c         C   s  |  j  |  j d ƒ } |  j | d d |  j ƒ|  j  |  j d ƒ } |  j | d ƒ |  j  |  j d ƒ } |  j | d ƒ |  j  |  j ƒ } |  j | d ƒ |  j  |  j d ƒ } |  j | d ƒ |  j  |  j d	 ƒ } |  j | d ƒ |  j | j d
 ƒ |  j d ƒ d  S(   Ns   /testiÈ   R�   s   /test/i”  Ry   i-  s   /?hi=2s   ?hi=1R¸   s   /?hi=1(   R?   R®   R·   R�   RU   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/test_httpservers.pyt   test_path_without_leading_slash”  s    N(   R   R   R   R   R   R7   R:   R&   R·   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/test_httpservers.pyR¢   ?  s   		
	 				s@   #!%s

print "Content-type: text/html"
print
print "Hello World"
sÌ   #!%s
import cgi

print "Content-type: text/html"
print

form = cgi.FieldStorage()
print "%%s, %%s, %%s" %% (form.getfirst("spam"), form.getfirst("eggs"),
                          form.getfirst("bacon"))
sT   #!%s
import os

print("Content-type: text/html")
print("")

print(os.environ["%s"])
R½   i    s7   This test can't be run reliably as root (issue #13308).t   CGIHTTPServerTestCasec           B   sŸ   e  Z d  e e f d „  ƒ  YZ 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(   R   c           B   s   e  Z RS(    (   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/test_httpservers.pyR   Ç  s   c         C   s»  t  j |  ƒ t j ƒ  |  _ t j j |  j d ƒ |  _ t j j |  j d ƒ |  _	 t j
 |  j ƒ t j
 |  j	 ƒ t t d ƒ rµ t j j |  j d ƒ |  _ t j t j |  j ƒ n t j |  _ t j j |  j d ƒ |  _ t |  j d ƒ � } | j t |  j ƒ Wd  QXt j |  j d ƒ t j j |  j d ƒ |  _ t |  j d ƒ � } | j t |  j ƒ Wd  QXt j |  j d ƒ t j j |  j d	 ƒ |  _ t |  j d ƒ � } | j t |  j ƒ Wd  QXt j |  j d ƒ t j j |  j	 d
 ƒ |  _ t |  j d ƒ � } | j t |  j ƒ Wd  QXt j |  j d ƒ t j j |  j d ƒ |  _ t |  j d ƒ �! } | j t |  j d f ƒ Wd  QXt j |  j d ƒ t j ƒ  |  _ t j |  j ƒ d  S(   Ns   cgi-bins	   child-dirt   symlinkt   pythons   nocgi.pyRº   iÿ  s   file1.pys   file2.pys   file3.pys   file4.pyt   QUERY_STRING(   R-   R7   R¨   R«   t
   parent_dirR1   Rs   R+   t   cgi_dirt   cgi_child_dirt   mkdirt   hasattrt	   pythonexeRÉ   t   syst
   executablet
   nocgi_pathR°   R   t	   cgi_file1R¾   t
   file1_patht
   file2_patht	   cgi_file2t
   file3_patht
   file4_patht	   cgi_file4R¦   R§   Rª   (   R   R¿   t   file1t   file2t   file3t   file4(    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyR7   Ê  s@     c         C   sÎ   z¹ t  j |  j ƒ |  j t j k r8 t  j |  j ƒ n  t  j |  j ƒ t  j |  j ƒ t  j |  j	 ƒ t  j |  j
 ƒ t  j |  j ƒ t  j |  j ƒ t  j |  j ƒ t  j |  j ƒ Wd  t j |  ƒ Xd  S(   N(   R1   Rª   R§   RÑ   RÒ   RÓ   t   removeRÔ   RÖ   R×   RÙ   RÚ   t   rmdirRÎ   RÍ   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/test_httpservers.pyR:   ö  s    c      	   C   sT  i d d 6t  d 6t  d 6d d 6d d 6d d 6d d 6d	 d
 6d	 d	 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6t  d 6d d 6d d  6t  d! 6d d" 6d d# 6} xƒ | j ƒ  D]u \ } } t | t ƒ rt | t ƒ r|  j | t j | ƒ q× t j | ƒ } |  j	 | | d$ d% | | | f ƒq× Wd  S(&   Ns   //R…   s   ..s   /.//..Ry   s   //\s   /\s   /.//s   /cgi-bin/file1.pys   cgi-bin/file1.pys   //at   as   /as   ./as   /C:/s   ./C:/s   /a/bs   /a/b/s   /a/b/.s	   /a/b/c/..s   /a/b/ds   /a/b/c/../ds   /a/b/d/fs   /a/b/c/../d/e/../fs   /a/b/fs   /a/b/c/../d/e/../../fs   /a/b/c/../d/e/.././././..//fs   ../a/b/c/../d/e/.././././..//fs   /a/fs   /a/b/c/../d/e/../../../fs   //fs   /a/b/c/../d/e/../../../../fs   /a/b/c/../d/e/../../../../../fs   /a/b/c/../d/e/../../../../f/..s    /a/b/c/../d/e/../../../../f/../.t   msgs   path = %r
Got:    %r
Wanted: %r(
   t
   IndexErrort	   iteritemst
   isinstancet   typet
   issubclasst	   Exceptiont   assertRaisest   CGIHTTPServert   _url_collapse_pathRU   (   R   t   test_vectorsRs   t   expectedt   actual(    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   test_url_collapse_path  sJ    
	c         C   s>   |  j  d ƒ } |  j d | j ƒ  | j d ƒ | j f ƒ d  S(   Ns   /cgi-bin/file1.pys   Hello World
s	   text/htmliÈ   s   Content-type(   s   Hello World
s	   text/htmliÈ   (   R?   RU   Rš   R’   Rz   (   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/test_httpservers.pyt   test_headers_and_content0  s    	c         C   s&   |  j  d ƒ } |  j | j d ƒ d  S(   Ns)   ///////////nocgi.py/../cgi-bin/nothere.shi”  (   R?   RU   Rz   (   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/test_httpservers.pyt   test_issue194355  s    c         C   sc   t  j i d d 6d d 6d d 6ƒ } i d d 6} |  j d	 d
 | | ƒ } |  j | j ƒ  d ƒ d  S(   Ni   t   spamRÊ   t   eggsi@â t   bacons!   application/x-www-form-urlencodeds   Content-types   /cgi-bin/file2.pyt   POSTs   1, python, 123456
(   t   urllibt	   urlencodeR?   RU   Rš   (   R   t   paramsRD   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/test_httpservers.pyt	   test_post9  s    $c         C   s0   |  j  d ƒ } | j ƒ  |  j | j d ƒ d  S(   Ns   /cgi-bin/invalidi”  (   R?   Rš   RU   Rz   (   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/test_httpservers.pyt   test_invaliduri@  s    
c         C   sa   i d t  j d ƒ d 6} |  j d d d | ƒ} |  j d | j ƒ  | j d
 ƒ | j f ƒ d  S(   Ns   Basic %ss   username:passt   Authorizations   /cgi-bin/file1.pyR;   RD   s   Hello World
s	   text/htmliÈ   s   Content-type(   s   Hello World
s	   text/htmliÈ   (   t   base64t	   b64encodeR?   RU   Rš   R’   Rz   (   R   RD   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/test_httpservers.pyt   test_authorizationE  s
    	c         C   s>   |  j  d ƒ } |  j d | j ƒ  | j d ƒ | j f ƒ d  S(   Ns   cgi-bin/file1.pys   Hello World
s	   text/htmliÈ   s   Content-type(   s   Hello World
s	   text/htmliÈ   (   R?   RU   Rš   R’   Rz   (   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/test_httpservers.pyt   test_no_leading_slashL  s    	c         C   sh   d } | t  j d <|  j d ƒ } |  j d | j ƒ  | j d ƒ | j f ƒ |  j t  j d | ƒ d  S(	   Ns   Test CGI Servert   SERVER_SOFTWAREs   /cgi-bin/file1.pys   Hello World
s	   text/htmliÈ   s   Content-type(   s   Hello World
s	   text/htmliÈ   (   R1   R2   R?   RU   Rš   R’   Rz   (   R   t	   signatureR{   (    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   test_os_environ_is_not_alteredR  s    	"c         C   s>   |  j  d ƒ } |  j d | j ƒ  | j d ƒ | j f ƒ d  S(   Ns   /cgi-bin%2ffile1.pys   Hello World
s	   text/htmliÈ   s   Content-type(   s   Hello World
s	   text/htmliÈ   (   R?   RU   Rš   R’   Rz   (   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/test_httpservers.pyt#   test_urlquote_decoding_in_cgi_checkZ  s    	c         C   s>   |  j  d ƒ } |  j d | j ƒ  | j d ƒ | j f ƒ d  S(   Ns   /cgi-bin/child-dir/file3.pys   Hello World
s	   text/htmliÈ   s   Content-type(   s   Hello World
s	   text/htmliÈ   (   R?   RU   Rš   R’   Rz   (   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/test_httpservers.pyt   test_nested_cgi_path_issue21323_  s    	c         C   s>   |  j  d ƒ } |  j d | j ƒ  | j d ƒ | j f ƒ d  S(   Ns   /cgi-bin/file4.py?a=b?c=ds   a=b?c=d
s	   text/htmliÈ   s   Content-type(   s   a=b?c=d
s	   text/htmliÈ   (   R?   RU   Rš   R’   Rz   (   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/test_httpservers.pyt&   test_query_with_multiple_question_markd  s    c         C   s>   |  j  d ƒ } |  j d | j ƒ  | j d ƒ | j f ƒ d  S(   Ns0   /cgi-bin/file4.py?k=aa%2F%2Fbb&//q//p//=//a//b//s   k=aa%2F%2Fbb&//q//p//=//a//b//
s	   text/htmliÈ   s   Content-type(   s   k=aa%2F%2Fbb&//q//p//=//a//b//
s	   text/htmliÈ   (   R?   RU   Rš   R’   Rz   (   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/test_httpservers.pyt"   test_query_with_continuous_slashesj  s
     (   R   R   R   R   R   R7   R:   Rð   Rñ   Rò   Rú   Rû   Rÿ   R   R  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/test_httpservers.pyRÈ   Ä  s   	,		*										t    SimpleHTTPRequestHandlerTestCasec           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s    Test url parsing c         C   s:   t  j ƒ  |  _ t  j j |  j d ƒ |  _ t ƒ  |  _ d  S(   Nt   filename(   R1   R¦   t
   translatedRs   R+   R   RF   (   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/test_httpservers.pyR7   t  s    c         C   ss   |  j  j d ƒ } |  j | |  j ƒ |  j  j d ƒ } |  j | |  j ƒ |  j  j d ƒ } |  j | |  j ƒ d  S(   Ns	   /filenames   /filename?foo=bars   /filename?a=b&spam=eggs#zot(   RF   t   translate_pathRU   R
  (   R   Rs   (    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   test_query_argumentsy  s    c         C   sN   |  j  j d ƒ } |  j | |  j ƒ |  j  j d ƒ } |  j | |  j ƒ d  S(   Ns
   //filenames   //filename?foo=bar(   RF   R  RU   R
  (   R   Rs   (    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   test_start_with_double_slash�  s    c         C   s#  d d  l  } t j | j d t ƒ �ù |  j j d ƒ } | j t j t j ƒ } |  j	 | |  j
 ƒ |  j j d ƒ } | j t j t j ƒ } |  j	 | |  j
 ƒ |  j j d ƒ } | j t j t j ƒ } |  j	 | |  j
 ƒ |  j j d ƒ } | j t j t j ƒ } |  j	 | |  j
 ƒ Wd  QXd  S(   NiÿÿÿÿRs   s   c:c:c:foo/filenames   \c:../filenames   c:\c:..\foo/filenames   c:c:foo\c:c:bar/filename(   t   SimpleHTTPServerR   t	   swap_attrR1   t   ntpathRF   R  t   replacet   sepRU   R
  (   R   R  Rs   (    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt   test_windows_colon‡  s    (   R   R   Rg   R7   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/test_httpservers.pyR  r  s
   			c         C   s>   z) t  j ƒ  } t j t t t t t ƒ Wd  t  j	 | ƒ Xd  S(   N(
   R1   R¦   R   t   run_unittestRE   R  Rj   R¢   RÈ   Rª   (   t   verboseR§   (    (    s‹   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_httpservers.pyt	   test_main›  s    	t   __main__(    (+   Rg   R1   RÒ   Rh   Rý   R  R³   R÷   R<   R¨   t   unittestRë   t   BaseHTTPServerR    R   R  R   R   R   R¤   R   t   import_moduleR   R   R   R   R   t   TestCaseR-   RE   Rj   R¢   RÕ   RØ   RÛ   t   skipIfRÐ   R½   RÈ   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/test_httpservers.pyt   <module>   sD   A£l
$	¬)