ó
ŒwÛjc           @   s�  d  d l  Z  d  d l m Z d  d l m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 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 d d e ƒZ d „  Z d e  j f d	 „  ƒ  YZ d
 e  j f d „  ƒ  YZ d e  j f d „  ƒ  YZ e  j e
 d k d ƒ d e  j f d „  ƒ  Yƒ Z d e  j f d „  ƒ  YZ d „  Z e d k r‹e ƒ  n  d S(   iÿÿÿÿN(   t   test_support(   t   skip_ftp_test_on_traviss   selfsigned_pythontestdotnet.pemt	   mimetoolst
   deprecatedc         O   sW   xJ t  d ƒ D]< } y |  | | | Ž SWq t k
 r? } q q ‚  q Xq W| ‚ d  S(   Ni   (   t   ranget   IOError(   t   funct   hostt   argst   kwargst   it   last_exc(    (    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_urllibnet.pyt   _open_with_retry   s    t   URLTimeoutTestc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   g      $@c         C   s   t  j |  j ƒ d  S(   N(   t   sockett   setdefaulttimeoutt   TIMEOUT(   t   self(    (    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_urllibnet.pyt   setUp(   s    c         C   s   t  j d  ƒ d  S(   N(   R   R   t   None(   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_urllibnet.pyt   tearDown+   s    c         C   s%   t  t j t j ƒ } | j ƒ  } d  S(   N(   R   t   urllibt   urlopenR    t   TEST_HTTP_URLt   read(   R   t   ft   x(    (    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_urllibnet.pyt   testURLread.   s    (   t   __name__t
   __module__R   R   R   R   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_urllibnet.pyR   $   s   		t   urlopenNetworkTestsc           B   sŒ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 j
 e j d k d ƒ e	 j e e d	 ƒ d
 ƒ d „  ƒ ƒ Z d „  Z RS(   s6  Tests urllib.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.

    setUp is not used for always constructing a connection to
    http://www.example.com/ since there a few tests that don't use that address
    and making a connection is expensive enough to warrant minimizing unneeded
    connections.

    c         G   s   t  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_urllibnet.pyR   A   s    c         C   sl   |  j  t j ƒ } x+ d
 D]# } |  j t | | ƒ d | ƒ q Wz |  j | j ƒ  d	 ƒ Wd  | j ƒ  Xd  S(   NR   t   readlinet	   readlinest   filenot   closet   infot   geturls3   object returned from urlopen lacks the %s attributes   calling 'read' failed(   R   R   R    R!   R"   R#   R$   (   R   R    R   t
   assertTruet   hasattrR   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_urllibnet.pyt
   test_basicD   s    
c         C   sZ   |  j  t j ƒ } z6 |  j | j ƒ  t d ƒ |  j | j ƒ  t d ƒ Wd  | j ƒ  Xd  S(   Ns    readline did not return a strings   readlines did not return a list(	   R   R    R   t   assertIsInstanceR   t
   basestringR    t   listR"   (   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_urllibnet.pyt   test_readlinesP   s    c         C   s`   |  j  t j ƒ } z | j ƒ  } Wd  | j ƒ  |  j | t j d ƒ |  j | j	 ƒ  d ƒ Xd  S(   NsA   object returned by 'info' is not an instance of mimetools.Messaget   html(
   R   R    R   R#   R"   R*   R   t   Messaget   assertEqualt
   getsubtype(   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_urllibnet.pyt	   test_info[   s    
c         C   sG   |  j  t j ƒ } z | j ƒ  } Wd  | j ƒ  X|  j | t j ƒ d  S(   N(   R   R    R   R$   R"   R0   (   R   R'   t
   gotten_url(    (    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_urllibnet.pyt   test_geturlg   s
    c         C   sM   d } t  j ƒ  j | ƒ } z | j ƒ  } Wd  | j ƒ  X|  j | d ƒ d  S(   Ns'   http://www.pythontest.net/XXXinvalidXXXi”  (   R   t   FancyURLopenert   opent   getcodeR"   R0   (   R   t   URLR'   t   code(    (    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_urllibnet.pyt   test_getcodep   s    t   win32s   not appropriate for Windowst   fdopens   os.fdopen not availablec         C   sY   |  j  t j ƒ } | j ƒ  } t j | ƒ } z |  j | j ƒ  d ƒ Wd  | j ƒ  Xd  S(   Ns<   reading from file created using fd returned by fileno failed(	   R   R    R   R!   t   osR=   R%   R   R"   (   R   R'   t   fdt   FILE(    (    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_urllibnet.pyt   test_filenoz   s    c         C   sY   d } y t  j | ƒ Wn t  j k
 r- n X|  j d | ƒ |  j t t j d ƒ d  S(   Ns   sadflkjsasf.i.nvali.ds&   %r should not resolve for test to works   http://sadflkjsasf.i.nvali.d/(   R   t   gethostbynamet   gaierrort   skipTestt   assertRaisesR   R   R   (   R   t   bogus_domain(    (    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_urllibnet.pyt   test_bad_addressˆ   s    	(   R<   (   R   R   t   __doc__R   R)   R-   R3   R5   R;   t   unittestt   skipIft   syst   platformt
   skipUnlessR&   R>   RA   RG   (    (    (    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_urllibnet.pyR   2   s   							
't   urlretrieveNetworkTestsc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s+   Tests urllib.urlretrieve using the network.c         G   s   t  t j | Œ S(   N(   R   R   t   urlretrieve(   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_urllibnet.pyRO       s    c         C   sy   |  j  t j ƒ \ } } |  j t j j | ƒ d ƒ t | ƒ } z |  j | j ƒ  d ƒ Wd  | j	 ƒ  t j
 | ƒ Xd  S(   Ns9   file location returned by urlretrieve is not a valid paths=   reading from the file location returned by urlretrieve failed(   RO   R    R   R%   R>   t   patht   existst   fileR   R"   t   unlink(   R   t   file_locationR#   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_urllibnet.pyR)   £   s    
c         C   s�   |  j  t j t j ƒ \ } } |  j | t j ƒ |  j t j j | ƒ ƒ t	 | ƒ } z |  j | j
 ƒ  d ƒ Wd  | j ƒ  t j | ƒ Xd  S(   Ns"   reading from temporary file failed(   RO   R    R   t   TESTFNR0   R%   R>   RP   RQ   RR   R   R"   RS   (   R   RT   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_urllibnet.pyt   test_specified_path°   s    
c         C   s?   |  j  t j ƒ \ } } t j | ƒ |  j | t j d ƒ d  S(   Ns.   header is not an instance of mimetools.Message(   RO   R    R   R>   RS   R*   R   R/   (   R   RT   t   header(    (    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_urllibnet.pyt   test_header½   s    c         C   s|   t  j } |  j | ƒ \ } } t j | ƒ | j d ƒ } d } y t j | | ƒ Wn! t k
 rw |  j	 d | ƒ n Xd  S(   Nt   Dates   %a, %d %b %Y %H:%M:%S GMTs   Date value not in %r format(
   R    R   RO   R>   RS   t	   getheadert   timet   strptimet
   ValueErrort   fail(   R   t   logoRT   t   fileheaderst	   datevaluet
   dateformat(    (    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_urllibnet.pyt   test_data_headerÄ   s    	(   R   R   RH   RO   R)   RV   RX   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_urllibnet.pyRN   �   s   				s   requires sslt   urlopen_HttpsTestsc           B   s   e  Z d  „  Z RS(   c         C   sA   t  j d t ƒ } t j d d | ƒ} |  j d | j ƒ  ƒ d  S(   Nt   cafiles"   https://self-signed.pythontest.nett   contextt   Python(   t   sslt   create_default_contextt    CERT_selfsigned_pythontestdotnetR   R   t   assertInR   (   R   Rf   t   response(    (    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_urllibnet.pyt   test_context_argumentÓ   s    (   R   R   Rm   (    (    (    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_urllibnet.pyRd   Ð   s   t   urlopen_FTPTestc           B   s2   e  Z d  Z d Z e d „  ƒ Z e d „  ƒ Z RS(   s   ftp://www.pythontest.net/READMEi   c         C   s¥   t  j |  j ƒ �� ya xZ t |  j ƒ D]I } t  j ƒ  �5 } t j ƒ  j |  j t	 j
 j | t | ƒ ƒ ƒ Wd  QXq& WWn$ t k
 rš } |  j d | ƒ n XWd  QXd  S(   NsS   Failed FTP retrieve while accessing ftp url multiple times.
 Error message was : %s(   R    t   transient_internett   FTP_TEST_FILER   t   NUM_FTP_RETRIEVESt   temp_dirR   R6   t   retrieveR>   RP   t   joint   strR   R^   (   R   t   file_numt   tdt   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_urllibnet.pyt   test_multiple_ftp_retrievesÝ   s    *	c      	   C   sª   t  j |  j ƒ �’ g  } zh y= x6 t |  j ƒ D]% } t j |  j ƒ } | j | ƒ q/ WWn$ t k
 r } |  j	 d | ƒ n XWd  x | D] } | j
 ƒ  q‹ WXWd  QXd  S(   Ns2   Failed FTP binary file open. Error message was: %s(   R    Ro   Rp   R   Rq   R   R   t   appendR   R^   R"   (   R   t   ftp_fds_to_closet   _R?   Rx   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_urllibnet.pyt#   test_multiple_ftp_urlopen_same_hostê   s     	(   R   R   Rp   Rq   R   Ry   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_urllibnet.pyRn   Ù   s   c        
   C   sF   t  j d ƒ t  j d t f ƒ � t  j t t t t t	 ƒ Wd  QXd  S(   Nt   networks!   urllib.urlopen.. has been removed(
   R    t   requirest   check_py3k_warningst   DeprecationWarningt   run_unittestR   R   RN   Rd   Rn   (    (    (    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_urllibnet.pyt	   test_mainü   s    	t   __main__(    RI   t   testR    t   test.test_urllib2netR   R   R   RK   R>   R[   Rh   t   ImportErrorR   RP   t   dirnamet   __file__t   hereRt   Rj   t   import_modulet   TrueR   R   t   TestCaseR   R   RN   RJ   Rd   Rn   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_urllibnet.pyt   <module>   s0   
	k3#	
