ó
­«Y]c           @   sf  d  d l  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 „  Z e d k rbe ƒ  n  d S(   iÿÿÿÿN(   t   test_supports   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$   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$   lib/python2.7/test/test_urllibnet.pyt   setUp'   s    c         C   s   t  j d  ƒ d  S(   N(   R   R   t   None(   R   (    (    s$   lib/python2.7/test/test_urllibnet.pyt   tearDown*   s    c         C   s"   t  t j d ƒ } | j ƒ  } d  S(   Ns   http://www.example.com/(   R   t   urllibt   urlopent   read(   R   t   ft   x(    (    s$   lib/python2.7/test/test_urllibnet.pyt   testURLread-   s    (   t   __name__t
   __module__R   R   R   R   (    (    (    s$   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$   lib/python2.7/test/test_urllibnet.pyR   @   s    c         C   si   |  j  d ƒ } x+ d D]# } |  j t | | ƒ d	 | ƒ q Wz |  j | j ƒ  d
 ƒ Wd  | j ƒ  Xd  S(   Ns   http://www.example.com/R   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   t
   assertTruet   hasattrR   R    (   R   t   open_urlt   attr(    (    s$   lib/python2.7/test/test_urllibnet.pyt
   test_basicC   s    
c         C   sW   |  j  d ƒ } z6 |  j | j ƒ  t d ƒ |  j | j ƒ  t d ƒ Wd  | j ƒ  Xd  S(   Ns   http://www.example.com/s    readline did not return a strings   readlines did not return a list(   R   t   assertIsInstanceR   t
   basestringR   t   listR    (   R   R%   (    (    s$   lib/python2.7/test/test_urllibnet.pyt   test_readlinesO   s    c         C   s]   |  j  d ƒ } z | j ƒ  } Wd  | j ƒ  |  j | t j d ƒ |  j | j ƒ  d ƒ Xd  S(   Ns   http://www.example.com/sA   object returned by 'info' is not an instance of mimetools.Messaget   html(   R   R!   R    R(   R   t   Messaget   assertEqualt
   getsubtype(   R   R%   t   info_obj(    (    s$   lib/python2.7/test/test_urllibnet.pyt	   test_infoZ   s    
c         C   sG   d } |  j  | ƒ } z | j ƒ  } Wd  | j ƒ  X|  j | | ƒ d  S(   Ns   http://www.example.com/(   R   R"   R    R.   (   R   t   URLR%   t
   gotten_url(    (    s$   lib/python2.7/test/test_urllibnet.pyt   test_geturlf   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    R.   (   R   R2   R%   t   code(    (    s$   lib/python2.7/test/test_urllibnet.pyt   test_getcodep   s    t   win32s   not appropriate for Windowst   fdopens   os.fdopen not availablec         C   sV   |  j  d ƒ } | j ƒ  } t j | ƒ } z |  j | j ƒ  d ƒ Wd  | j ƒ  Xd  S(   Ns   http://www.example.com/s<   reading from file created using fd returned by fileno failed(   R   R   t   osR;   R#   R   R    (   R   R%   t   fdt   FILE(    (    s$   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$   lib/python2.7/test/test_urllibnet.pyt   test_bad_address‡   s    	(   R:   (   R   R   t   __doc__R   R'   R+   R1   R4   R9   t   unittestt   skipIft   syst   platformt
   skipUnlessR$   R<   R?   RE   (    (    (    s$   lib/python2.7/test/test_urllibnet.pyR   1   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$   lib/python2.7/test/test_urllibnet.pyRM   Ÿ   s    c         C   sv   |  j  d ƒ \ } } |  j t j j | ƒ d ƒ t | ƒ } z |  j | j ƒ  d ƒ Wd  | j ƒ  t j | ƒ Xd  S(   Ns   http://www.example.com/s9   file location returned by urlretrieve is not a valid paths=   reading from the file location returned by urlretrieve failed(	   RM   R#   R<   t   patht   existst   fileR   R    t   unlink(   R   t   file_locationR!   R>   (    (    s$   lib/python2.7/test/test_urllibnet.pyR'   ¢   s    
c         C   sŒ   |  j  d t j ƒ \ } } |  j | t j ƒ |  j t j j | ƒ ƒ t | ƒ } z |  j | j	 ƒ  d ƒ Wd  | j
 ƒ  t j | ƒ Xd  S(   Ns   http://www.example.com/s"   reading from temporary file failed(   RM   R    t   TESTFNR.   R#   R<   RN   RO   RP   R   R    RQ   (   R   RR   R!   R>   (    (    s$   lib/python2.7/test/test_urllibnet.pyt   test_specified_path¯   s    	
c         C   s<   |  j  d ƒ \ } } t j | ƒ |  j | t j d ƒ d  S(   Ns   http://www.example.com/s.   header is not an instance of mimetools.Message(   RM   R<   RQ   R(   R   R-   (   R   RR   t   header(    (    s$   lib/python2.7/test/test_urllibnet.pyt   test_header¼   s    c         C   sy   d } |  j  | ƒ \ } } t j | ƒ | j d ƒ } d } y t j | | ƒ Wn! t k
 rt |  j d | ƒ n Xd  S(   Ns   http://www.example.com/t   Dates   %a, %d %b %Y %H:%M:%S GMTs   Date value not in %r format(   RM   R<   RQ   t	   getheadert   timet   strptimet
   ValueErrort   fail(   R   t   logoRR   t   fileheaderst	   datevaluet
   dateformat(    (    s$   lib/python2.7/test/test_urllibnet.pyt   test_data_headerÃ   s    (   R   R   RF   RM   R'   RT   RV   Ra   (    (    (    s$   lib/python2.7/test/test_urllibnet.pyRL   œ   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   Rd   t   response(    (    s$   lib/python2.7/test/test_urllibnet.pyt   test_context_argumentÒ   s    (   R   R   Rk   (    (    (    s$   lib/python2.7/test/test_urllibnet.pyRb   Ï   s   c        	   C   sC   t  j d ƒ t  j d t f ƒ  t  j t t t t ƒ Wd  QXd  S(   Nt   networks!   urllib.urlopen.. has been removed(	   R    t   requirest   check_py3k_warningst   DeprecationWarningt   run_unittestR   R   RL   Rb   (    (    (    s$   lib/python2.7/test/test_urllibnet.pyt	   test_mainØ   s    	t   __main__(   RG   t   testR    R   R   RI   R<   RY   Rf   t   ImportErrorR   RN   t   dirnamet   __file__t   heret   joinRh   t   import_modulet   TrueR   R   t   TestCaseR   R   RL   RH   Rb   Rq   R   (    (    (    s$   lib/python2.7/test/test_urllibnet.pyt   <module>   s,   
	k3		