ó
ŒwÛjc           @   sì  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 e j	 d d e
 ƒZ e j	 d ƒ Z y d  d l Z Wn e k
 r± d Z n Xe  j j e ƒ Z e  j j e d ƒ Z e  j j e d ƒ Z d e j f d	 „  ƒ  YZ d
 e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d d 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 e  f d „  ƒ  YZ$ d „  Z% e& d k rèe% ƒ  n  d S(   iÿÿÿÿN(   t   test_supportt	   mimetoolst
   deprecatedt	   threadings   keycert.pems   keycert2.pemt   LoopbackHttpServerc           B   s    e  Z d  Z d „  Z d „  Z RS(   s^   HTTP server w/ a few modifications that make it useful for
    loopback testing purposes.
    c         C   s*   t  j j |  | | ƒ |  j j d ƒ d  S(   Ngš™™™™™¹?(   t   BaseHTTPServert
   HTTPServert   __init__t   sockett
   settimeout(   t   selft   server_addresst   RequestHandlerClass(    (    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_urllib2_localnet.pyR       s    c         C   s,   |  j  j ƒ  \ } } | j d ƒ | | f S(   s"   BaseHTTPServer method, overridden.g      $@(   R   t   acceptR	   (   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/test_urllib2_localnet.pyt   get_request)   s    (   t   __name__t
   __module__t   __doc__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_urllib2_localnet.pyR      s   		t   LoopbackHttpServerThreadc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s2   Stoppable thread that runs a loopback http server.c         C   sV   t  j j |  ƒ t |  _ t  j ƒ  |  _ d | _ t d | ƒ |  _	 |  j	 j
 |  _ d  S(   Ns   HTTP/1.0s	   127.0.0.1i    (   s	   127.0.0.1i    (   R   t   ThreadR   t   Falset   _stopt   Eventt   readyt   protocol_versionR   t   httpdt   server_portt   port(   R
   t   request_handler(    (    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_urllib2_localnet.pyR   8   s    		c         C   s   t  |  _ |  j ƒ  d S(   s.   Stops the webserver if it's currently running.N(   t   TrueR   t   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_urllib2_localnet.pyt   stopC   s    	c         C   s.   |  j  j ƒ  x |  j s) |  j j ƒ  q Wd  S(   N(   R   t   setR   R   t   handle_request(   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_urllib2_localnet.pyt   runK   s    (   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_urllib2_localnet.pyR   5   s   		t   BasicAuthHandlerc           B   sl   e  Z d  Z d Z d Z d Z d e e f Z e j e ƒ Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z RS(
   s,   Handler for performing Basic Authentication.t   testUsert   testPasst   Tests   %s:%sc         O   s   t  j j |  | | Ž d  S(   N(   R   t   BaseHTTPRequestHandlerR   (   R
   t   argst   kwargs(    (    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_urllib2_localnet.pyR   \   s    c         G   s   d  S(   N(    (   R
   t   formatR*   (    (    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_urllib2_localnet.pyt   log_message_   s    c         C   s+   |  j  d ƒ |  j d d ƒ |  j ƒ  d  S(   NiÈ   s   Content-types	   text/html(   t   send_responset   send_headert   end_headers(   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_urllib2_localnet.pyt   do_HEADc   s    c         C   sB   |  j  d ƒ |  j d d |  j ƒ |  j d d ƒ |  j ƒ  d  S(   Ni‘  s   WWW-Authenticates   Basic realm="%s"s   Content-types	   text/html(   R.   R/   t   REALMR0   (   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_urllib2_localnet.pyt   do_AUTHHEADh   s    c         C   su   |  j  j d ƒ d  k r5 |  j ƒ  |  j j d ƒ n< |  j  j d ƒ d |  j k rg |  j j d ƒ n
 |  j ƒ  d  S(   Nt   Authorizations   No Auth Header Receiveds   Basic s	   It works!(   t   headerst	   getheadert   NoneR3   t   wfilet   writet   ENCODED_AUTH(   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_urllib2_localnet.pyt   do_GETn   s    
	(   R   R   R   t   USERt   PASSWDR2   t   USER_PASSWDt   base64t	   b64encodeR:   R   R-   R1   R3   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_urllib2_localnet.pyR%   S   s   				t   DigestAuthHandlerc           B   s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   s-   Handler for performing digest authentication.c         C   s1   d |  _  g  |  _ i  |  _ d |  _ d |  _ d  S(   Ni    s
   Test Realmt   auth(   t   _request_numt   _noncest   _userst   _realm_namet   _qop(   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_urllib2_localnet.pyR   }   s
    				c         C   s   | |  _  d  S(   N(   RG   (   R
   t   qop(    (    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_urllib2_localnet.pyt   set_qop„   s    c         C   s"   t  | t ƒ s t ‚ | |  _ d  S(   N(   t
   isinstancet   dictt   AssertionErrorRE   (   R
   t   users(    (    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_urllib2_localnet.pyt	   set_users‡   s    c         C   s   | |  _  d  S(   N(   RF   (   R
   t   realm(    (    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_urllib2_localnet.pyt	   set_realm‹   s    c         C   sA   |  j  d 7_  t j t |  j  ƒ ƒ j ƒ  } |  j j | ƒ | S(   Ni   (   RC   t   hashlibt   md5t   strt	   hexdigestRD   t   append(   R
   t   nonce(    (    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_urllib2_localnet.pyt   _generate_nonceŽ   s    c         C   s®   | j  d ƒ } | | d } | j d ƒ } i  } xu | D]m } | j d ƒ \ } } | j ƒ  } | d d k r� | d d k r� | d d !} n | j ƒ  } | | | <q9 W| S(   Nt    i   t   ,t   =i    t   "iÿÿÿÿ(   t   findt   splitt   strip(   R
   t   auth_strt   first_space_indext   partst	   auth_dictt   partt   namet   value(    (    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_urllib2_localnet.pyt   _create_auth_dict”   s     c         C   s°   i  } | j  | ƒ | | d <| | d <| | d <d | } t j | ƒ j ƒ  } d | } t j | ƒ j ƒ  }	 | | d <|	 | d <d | }
 t j |
 ƒ j ƒ  } | | d	 k S(
   Nt   passwordt   methodt   uris#   %(username)s:%(realm)s:%(password)ss   %(method)s:%(uri)st   HA1t   HA2s3   %(HA1)s:%(nonce)s:%(nc)s:%(cnonce)s:%(qop)s:%(HA2)st   response(   t   updateRQ   RR   RT   (   R
   Rb   Rg   Rh   Ri   t
   final_dictt   HA1_strRj   t   HA2_strRk   t   response_strRl   (    (    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_urllib2_localnet.pyt   _validate_auth¥   s    






c         C   sg   | j  d d ƒ | j d d ƒ | j d d |  j |  j |  j ƒ  f ƒ | j ƒ  | j j d ƒ t S(   Ni—  s   Proxy Authentication Requireds   Content-Types	   text/htmls   Proxy-Authenticates(   Digest realm="%s", qop="%s",nonce="%s", s   Proxy Authentication Required.(	   R.   R/   RF   RG   RW   R0   R8   R9   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_urllib2_localnet.pyt   _return_auth_challenge·   s    
c         C   s  t  |  j ƒ d k r t Sd | j k r5 |  j | ƒ S|  j | j d ƒ } | d |  j k rr |  j | d } n |  j | ƒ S| j d ƒ |  j k r¤ |  j | ƒ S|  j j | d ƒ t	 } x> | j
 | j g D]* } |  j | | | j | ƒ rÑ t } qÑ qÑ W| s|  j | ƒ St Sd S(   s  Performs digest authentication on the given HTTP request
        handler.  Returns True if authentication was successful, False
        otherwise.

        If no users have been set, then digest auth is effectively
        disabled and this method will always return True.
        i    s   Proxy-Authorizationt   usernameRV   N(   t   lenRE   R   R5   Rs   Rf   t   getRD   t   removeR   t   patht
   short_pathRr   t   command(   R
   R   Rb   Rg   t   auth_validatedRx   (    (    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_urllib2_localnet.pyR#   Æ   s,    			(   R   R   R   R   RI   RN   RP   RW   Rf   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_urllib2_localnet.pyRA   z   s   								t   FakeProxyHandlerc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sÏ   This is a 'fake proxy' that makes it look like the entire
    internet has gone down due to a sudden zombie invasion.  It main
    utility is in providing us with authentication support for
    testing.
    c         O   s#   | |  _  t j j |  | | Ž d  S(   N(   t   digest_auth_handlerR   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_urllib2_localnet.pyR   û   s    	c         G   s   d  S(   N(    (   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_urllib2_localnet.pyR-     s    c         C   sš   t  j  |  j d ƒ \ } } } } } } | |  _ |  j j |  ƒ r– |  j d d ƒ |  j d d ƒ |  j ƒ  |  j j	 d |  j ƒ |  j j	 d ƒ n  d  S(   Nt   httpiÈ   t   OKs   Content-Types	   text/htmls   You've reached %s!<BR>sF   Our apologies, but our server is down due to a sudden zombie invasion.(
   t   urlparseRx   Ry   R}   R#   R.   R/   R0   R8   R9   (   R
   t   scmt   netlocRx   t   paramst   queryt   fragment(    (    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_urllib2_localnet.pyR;     s    !	
(   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_urllib2_localnet.pyR|   ô   s   		t   BaseTestCasec           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   t  j ƒ  |  _ d  S(   N(   R    t   threading_setupt   _threads(   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_urllib2_localnet.pyt   setUp  s    c         C   s   |  j  ƒ  t j |  j Œ  d  S(   N(   t
   doCleanupsR    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_urllib2_localnet.pyt   tearDown  s    
(   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_urllib2_localnet.pyR†     s   	t   BasicAuthTestsc           B   s;   e  Z d  Z d Z d Z d Z d „  Z d „  Z d „  Z RS(   R&   R'   t	   IncorrectR(   c         C   sr   t  t |  ƒ j ƒ  d „  } t | ƒ |  _ d |  j j |  _ |  j j ƒ  |  j j j	 ƒ  |  j
 |  j j ƒ d  S(   Nc          _   s   t  |  | Ž  S(   N(   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_urllib2_localnet.pyt#   http_server_with_basic_auth_handler&  s    s   http://127.0.0.1:%s(   t   superR�   R‰   R   t   serverR   t
   server_urlt   startR   t   waitt
   addCleanupR!   (   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_urllib2_localnet.pyR‰   #  s    	c         C   s¨   t  j ƒ  } | j |  j |  j |  j |  j ƒ t  j t  j | ƒ ƒ y |  j	 t  j
 |  j ƒ ƒ Wn@ t  j k
 r‹ |  j d |  j ƒ n t k
 r£ } | ‚ n Xd  S(   Ns   Basic Auth Failed for url: %s(   t   urllib2t   HTTPBasicAuthHandlert   add_passwordR2   R’   R<   R=   t   install_openert   build_openert
   assertTruet   urlopent	   HTTPErrort   failt	   Exception(   R
   t   aht   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/test_urllib2_localnet.pyt   test_basic_auth_success.  s    "c         C   sd   t  j ƒ  } | j |  j |  j |  j |  j ƒ t  j t  j | ƒ ƒ |  j	 t  j
 t  j |  j ƒ d  S(   N(   R–   R—   R˜   R2   R’   R<   t   INCORRECT_PASSWDR™   Rš   t   assertRaisesR�   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_urllib2_localnet.pyt   test_basic_auth_httperror9  s
    
(	   R   R   R<   R=   R£   R2   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_urllib2_localnet.pyR�     s   		t   ProxyAuthTestsc           B   sM   e  Z d  Z d Z d Z d Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s   http://localhostt   testert   test123t	   TestRealmc            s*  t  t ˆ  ƒ j ƒ  d „  } ˆ  j | t j j ƒ  ƒ d t j d <d t j d <t ƒ  ˆ  _ ˆ  j j	 i ˆ  j
 ˆ  j 6ƒ ˆ  j j ˆ  j ƒ ‡  f d †  } t | ƒ ˆ  _ ˆ  j j ƒ  ˆ  j j j ƒ  ˆ  j ˆ  j j ƒ d ˆ  j j } t j i | d 6ƒ } t j ƒ  ˆ  _ t j | ˆ  j ƒ ˆ  _ d  S(   Nc         S   s!   t  j j ƒ  t  j j |  ƒ d  S(   N(   t   ost   environt   clearRm   (   t   old_environ(    (    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_urllib2_localnet.pyt   restore_environK  s    t    t   NO_PROXYt   no_proxyc             s   t  ˆ  j |  | Ž S(   N(   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_urllib2_localnet.pyt   create_fake_proxy_handlerV  s    s   http://127.0.0.1:%dR~   (   R�   R¦   R‰   R•   Rª   R«   t   copyRA   R}   RN   R=   R<   RP   R2   R   R‘   R“   R   R”   R!   R   R–   t   ProxyHandlert   ProxyDigestAuthHandlert   proxy_digest_handlerRš   t   opener(   R
   R®   R²   t	   proxy_urlt   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_urllib2_localnet.pyR‰   H  s"    	c         C   s\   |  j  j |  j |  j |  j |  j d ƒ |  j j d ƒ |  j t	 j
 |  j j |  j ƒ d  S(   Nt   badRB   (   R¶   R˜   R2   t   URLR<   R=   R}   RI   R¤   R–   R�   R·   t   open(   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_urllib2_localnet.pyt-   test_proxy_with_bad_password_raises_httperrorb  s    	c         C   s3   |  j  j d ƒ |  j t j |  j j |  j ƒ d  S(   NRB   (   R}   RI   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_urllib2_localnet.pyt,   test_proxy_with_no_password_raises_httperrorj  s    	c         C   sk   |  j  j |  j |  j |  j |  j ƒ |  j j d ƒ |  j j	 |  j ƒ } x | j
 ƒ  r\ qM W| j ƒ  d  S(   NRB   (   R¶   R˜   R2   R»   R<   R=   R}   RI   R·   R¼   t   readt   close(   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_urllib2_localnet.pyt   test_proxy_qop_auth_worksp  s    c         C   s•   |  j  j |  j |  j |  j |  j ƒ |  j j d ƒ y |  j j	 |  j ƒ } Wn t
 j k
 rj d  } n X| r‘ x | j ƒ  rƒ qt W| j ƒ  n  d  S(   Ns   auth-int(   R¶   R˜   R2   R»   R<   R=   R}   RI   R·   R¼   R–   t   URLErrorR7   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_urllib2_localnet.pyt0   test_proxy_qop_auth_int_works_or_throws_urlerrory  s    
(   R   R   R»   R<   R=   R2   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_urllib2_localnet.pyR¦   A  s   					c            s&   d t  j f ‡  ‡ f d †  ƒ  Y‰  ˆ  S(   Nt   FakeHTTPRequestHandlerc              sM   e  Z d  Z g  Z g  Z d Z d „  Z d „  Z ‡  ‡ f d †  Z d „  Z	 RS(   s	   TestHTTP/iP   c         S   s)   |  j  ƒ  } | r% |  j j | ƒ n  d  S(   N(   t	   send_headR8   R9   (   R
   t   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/test_urllib2_localnet.pyR;   “  s    c         S   sC   |  j  d } |  j j t | ƒ ƒ } |  j ƒ  |  j j | ƒ d  S(   Ns   Content-Length(   R5   t   rfileR¿   t   intR;   t   requestsRU   (   R
   t   content_lengtht	   post_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_urllib2_localnet.pyt   do_POST˜  s    
c            s¤   |  j  ˆ  _ |  j j |  j ƒ ˆ j d ƒ \ } } } |  j | ƒ x+ | D]# \ } } |  j | | |  j ƒ qK W| r– |  j d d ƒ |  j	 ƒ  | S|  j	 ƒ  d  S(   Ni    s   Content-types
   text/plain(
   R5   t   headers_receivedRÊ   RU   Rx   t   popR.   R/   R   R0   (   R
   t   response_codeR5   RÇ   t   headerRe   (   RÅ   t	   responses(    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_urllib2_localnet.pyRÆ   ž  s    
c         W   s   d  S(   N(    (   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_urllib2_localnet.pyR-   ­  s    (
   R   R   t   server_versionRÊ   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_urllib2_localnet.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_urllib2_localnet.pyt   GetRequestHandlerŠ  s    "%t   TestUrlopenc           B   s¿   e  Z d  Z d „  Z d d „ Z d „  Z d 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(   sG  Tests urllib2.urlopen using the network.

    These tests are not exhaustive.  Assuming that testing using files does a
    good job overall of some of the basic interface features.  There are no
    tests exercising the optional 'data' and 'proxies' arguments.  No tests
    for transparent redirection have been written.
    c         C   sB   t  j i  ƒ } t  j | ƒ } t  j | ƒ t t |  ƒ j ƒ  d  S(   N(   R–   R´   Rš   R™   R�   RÕ   R‰   (   R
   t   proxy_handlerR·   (    (    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_urllib2_localnet.pyR‰   ½  s    c         K   sŒ   g  } t  j | | | � } zV | j | j d ƒ ƒ | j | j ƒ  ƒ | j | j d ƒ ƒ | j | j ƒ  ƒ Wd  | j ƒ  Xd j | ƒ S(   NiÈ   i   R¯   (	   R–   Rœ   t   extendt	   readlinesRU   t   readlineR¿   RÀ   R    (   R
   t   urlt   dataR+   t   lt   f(    (    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_urllib2_localnet.pyRœ   Ã  s    c         C   sd   t  | ƒ } t | ƒ |  _ |  j j ƒ  |  j j j ƒ  |  j |  j j ƒ |  j j } | | _ | S(   N(	   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_urllib2_localnet.pyt   start_serverÐ  s    	c         K   s�   t  t d ƒ s |  j d ƒ n  d d l m } | d  k rP d g  d f g } n  t | ƒ } | |  d | | �} | j | _ | S(   Nt   HTTPSHandlers   ssl support requirediÿÿÿÿ(   t   make_https_serveriÈ   s   we care a bitt   handler_class(   t   hasattrR–   t   skipTestt   test.ssl_serversRà   R7   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_urllib2_localnet.pyt   start_https_serverÛ  s    c         C   s�   d } d d
 g d f d g  | f g } |  j  | ƒ } t j d | j ƒ } | j ƒ  } | j ƒ  |  j | | ƒ |  j | j d d	 g ƒ d  S(   Ns   We got here...i.  t   Locations"   http://localhost:%s/somewhere_elseR¯   iÈ   s   http://localhost:%s/t   /s   /somewhere_else(   Ræ   s"   http://localhost:%s/somewhere_else(   RÞ   R–   Rœ   R   R¿   RÀ   t   assertEqualRÊ   (   R
   t   expected_responseRÒ   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_urllib2_localnet.pyt   test_redirectionæ  s    
c         C   sŸ   d } |  j  d g  | f g ƒ } y t j d | j ƒ Wn t j k
 rQ } n X|  j d ƒ | j ƒ  } | j ƒ  |  j | | ƒ |  j | j	 d g ƒ d  S(   Ns   Bad bad bad...i”  s   http://localhost:%s/weebles   404 should raise URLErrors   /weeble(
   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_urllib2_localnet.pyt   test_404÷  s    
c         C   sw   d } |  j  d g  | f g ƒ } t j d | j ƒ } | j ƒ  } | j ƒ  |  j | | ƒ |  j | j d g ƒ d  S(   Ns   pycon 2008...iÈ   s   http://localhost:%s/bizarres   /bizarre(   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_urllib2_localnet.pyt   test_200	  s    
c         C   s}   d } |  j  d g  | f g ƒ } t j d | j d ƒ } | j ƒ  } | j ƒ  |  j | | ƒ |  j | j d d g ƒ d  S(   Ns   pycon 2008...iÈ   s   http://localhost:%s/bizarres   get=with_feelings   /bizarre(   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_urllib2_localnet.pyt   test_200_with_parameters  s    
c         C   sN   |  j  ƒ  } t j d t ƒ } |  j d | j d | ƒ} |  j | d ƒ d  S(   Nt   cafiles   https://localhost:%s/bizarret   contexts   we care a bit(   Rå   t   sslt   create_default_contextt   CERT_localhostRœ   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_urllib2_localnet.pyt
   test_https  s    c      	   C   sº   |  j  d t ƒ } |  j d | j d t ƒ} |  j | d ƒ |  j t j ƒ � |  j d | j d t ƒWd  QX|  j  d t ƒ } |  j t	 j
 ƒ � |  j d | j d t ƒWd  QXd  S(   Nt   certfiles   https://localhost:%s/bizarreRî   s   we care a bit(   Rå   Rò   Rœ   R   Rè   R¤   R–   RÃ   t   CERT_fakehostnameRð   t   CertificateError(   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_urllib2_localnet.pyt   test_https_with_cafile%  s    	c         C   sI   |  j  d t ƒ } |  j t j ƒ � |  j d | j d t ƒWd  QXd  S(   NRô   s   https://localhost:%s/bizarret	   cadefault(   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_urllib2_localnet.pyt   test_https_with_cadefault5  s    c            sÈ   t  d  k r |  j d ƒ n  t  j s5 |  j d ƒ n  d  g ‰  ‡  f d †  } t  j t  j ƒ } | j | ƒ |  j d | d t ƒ } t  j	 d t ƒ } |  j
 d | j d | ƒ|  j ˆ  d d	 ƒ d  S(
   Ns   ssl module requireds   SNI support required in OpenSSLc            s   | ˆ  d <d  S(   Ni    (    (   t   ssl_sockt   server_namet   initial_context(   t   sni_name(    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_urllib2_localnet.pyt   cb_sniB  s    Rï   Rô   Rî   s   https://localhost:%si    t	   localhost(   Rð   R7   Rã   t   HAS_SNIt
   SSLContextt   PROTOCOL_TLSt   set_servername_callbackRå   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_urllib2_localnet.pyt   test_https_sni<  s    		c         C   sf   |  j  d g  d f g ƒ } t j d | j d i d d 6ƒ} t j | ƒ |  j | j d d ƒ d  S(   NiÈ   s   we don't cares   http://localhost:%s/R5   s   bytes=20-39t   Range(   RÞ   R–   t   RequestR   Rœ   Rè   RÎ   (   R
   R¹   t   req(    (    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_urllib2_localnet.pyt   test_sending_headersK  s
    c         C   s‹   |  j  d g  d f g ƒ } t j d | j ƒ } x+ d
 D]# } |  j t | | ƒ d | ƒ q8 Wz |  j | j ƒ  d	 ƒ Wd  | j ƒ  Xd  S(   NiÈ   s   we don't cares   http://localhost:%sR¿   RÀ   t   infot   geturls3   object returned from urlopen lacks the %s attributes   calling 'read' failed(   R¿   RÀ   R	  R
  (   RÞ   R–   Rœ   R   R›   Râ   R¿   RÀ   (   R
   R¹   t   open_urlt   attr(    (    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_urllib2_localnet.pyt
   test_basicS  s    c         C   sm   |  j  d g  d f g ƒ } t j d | j ƒ } | j ƒ  } |  j | t j d ƒ |  j | j	 ƒ  d ƒ d  S(   NiÈ   s   we don't cares   http://localhost:%ssA   object returned by 'info' is not an instance of mimetools.Messaget   plain(
   RÞ   R–   Rœ   R   R	  t   assertIsInstanceR   t   MessageRè   t
   getsubtype(   R
   R¹   R  t   info_obj(    (    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_urllib2_localnet.pyt	   test_info_  s    c         C   sX   |  j  d g  d f g ƒ } t j d | j ƒ } | j ƒ  } |  j | d | j ƒ d  S(   NiÈ   s   we don't cares   http://localhost:%s(   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_urllib2_localnet.pyt   test_geturli  s    c         C   s'   t  j d ƒ |  j t t j d ƒ d  S(   Nt   networks   http://sadflkjsasf.i.nvali.d./(   R    t   requiresR¤   t   IOErrorR–   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_urllib2_localnet.pyt   test_bad_addressr  s    	c         C   s\   d } |  j  d g  | f g ƒ } t j d | j ƒ } x | D] } |  j | | ƒ q> Wd  S(   Ns   pycon 2008...iÈ   s   http://localhost:%s(   RÞ   R–   Rœ   R   Rè   (   R
   Ré   R¹   RÛ   t   line(    (    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_urllib2_localnet.pyt   test_iterationŽ  s
    c      	   C   sÉ   d d d d d d g } d j  | ƒ } |  j d g  | f g ƒ } t j d	 | j ƒ } xN t | ƒ D]@ \ } } |  j | | | d
 | t | | ƒ t | ƒ f ƒ qg W|  j | d t | ƒ ƒ d  S(   Ns   We
s   got
s   here
s	   verylong i    s   
R¯   iÈ   s   http://localhost:%ssQ   Fetched line number %s doesn't match expected:
    Expected length was %s, got %si   (   R    RÞ   R–   Rœ   R   t	   enumerateRè   Ru   (   R
   t   linesRé   R¹   RÛ   t   indexR  (    (    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_urllib2_localnet.pyt   ztest_line_iteration–  s    %N(   R   R   R   R‰   R7   Rœ   RÞ   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_urllib2_localnet.pyRÕ   ´  s(   													
				c           C   s   t  j t t t ƒ d  S(   N(   R    t   run_unittestR�   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_urllib2_localnet.pyt	   test_main¢  s    t   __main__(    ('   Rª   R?   R€   R–   R   t   unittestRQ   t   testR    t   import_moduleR   R   R   Rð   t   ImportErrorR7   Rx   t   dirnamet   __file__t   hereR    Rò   Rõ   R   R   R   R   R)   R%   RA   R|   t   TestCaseR†   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_urllib2_localnet.pyt   <module>   s:   
'z 	$I	*î		