ó
Œ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   | |  _  d  S(   N(   RE   (   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   updateRN   RO   RQ   (   R
   R_   Rd   Re   Rf   t
   final_dictt   HA1_strRg   t   HA2_strRh   t   response_strRi   (    (    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   RT   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   usernameRS   N(   t   lenRE   R   R5   Rp   Rc   t   getRD   t   removeR   t   patht
   short_pathRo   t   command(   R
   R   R_   Rd   t   auth_validatedRu   (    (    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   RK   RM   RT   Rc   Ro   Rp   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
   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_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   urlparseRu   Rv   Rz   R#   R.   R/   R0   R8   R9   (   R
   t   scmt   netlocRu   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.pyRy   ô   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   clearRj   (   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(   Ry   Rz   (   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   Rz   RK   R=   R<   RM   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=   Rz   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   (   Rz   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=   Rz   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=   Rz   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   requestsRR   (   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Ç   RR   Ru   t   popR.   R/   R   R0   (   R
   t   response_codeR5   RÄ   t   headerRb   (   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	   readlinesRR   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å   Rr   (   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   unittestRN   t   testR    t   import_moduleR   R   R   Rí   t   ImportErrorR7   Ru   t   dirnamet   __file__t   hereR    Rï   Rò   R   R   R   R   R)   R%   RA   Ry   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	*î		