m
fIc           @   s  d  k  Z  d k l Z d  k Z d  k Z d  k Z d  k Z d k l Z l Z d e  i	 f d     YZ
 d f  d     YZ d f  d     YZ d	 e f d
     YZ d e i f d     YZ d f  d     YZ d f  d     YZ d f  d     YZ d   Z d e  i	 f d     YZ d   Z d e  i	 f d     YZ d e  i	 f d     YZ d e  i	 f d     YZ e d  Z e d j o e d e  n d  S(    N(   s   test_support(   s   Requests   OpenerDirectort   TrivialTestsc           B   s   t  Z d   Z d   Z RS(   Nc         C   s   |  i t t i d  t i i t i  i	 d d  } | d d !d j o | d } n t i d j o d | i	 d d  } nH t i d j o7 d  k } t i |  } | i | i d	 d
   } n d | } t i |  } | i   } | i   d  S(   Ns	   bogus urls   \t   /i   i   t   :t   mact   riscoss   /.s   ./s	   file://%s(   t   selft   assertRaisest
   ValueErrort   urllib2t   urlopent   ost   patht   abspatht   __file__t   replacet   fnamet   namet   stringt   expandt	   translatet	   maketranst   file_urlt   ft   readt   buft   close(   R   R   R   R   R   R   (    (    t.   /mit/python/lib/python2.4/test/test_urllib2.pyt   test_trivial   s    !	
c      
   C   s   d d d d g f d d d g f d d d d	 d
 d d d g f d d d d g f g } x- | D]% \ } } |  i t i |  |  q^ Wd  S(   Ns   a,b,ct   at   bt   cs   path"o,l"og"i"cal, examples   path"o,l"og"i"calt   examples   a, b, "c", "d", "e,f", g, hs   "c"s   "d"s   "e,f"t   gt   hs   a="b\"c", d="e\,f", g="h\\i"s   a="b"c"s   d="e,f"s   g="h\i"(   t   testsR   t   listR   t   assertEqualsR   t   parse_http_list(   R   R#   R"   R   (    (    R   t   test_parse_http_list,   s    W (   t   __name__t
   __module__R   R&   (    (    (    R   R       s   	t
   MockOpenerc           B   s#   t  Z g  Z d  d  Z d   Z RS(   Nc         C   s   | | |  _  |  _ d  S(   N(   t   reqt   dataR   (   R   R*   R+   (    (    R   t   open7   s    c         G   s   | | |  _  |  _ d  S(   N(   t   protot   argsR   (   R   R-   R.   (    (    R   t   error9   s    (   R'   R(   t
   addheaderst   NoneR,   R/   (    (    (    R   R)   5   s   t   MockFilec           B   s)   t  Z d  d  Z d  d  Z d   Z RS(   Nc         C   s   d  S(   N(    (   R   t   count(    (    R   R   =   s    c         C   s   d  S(   N(    (   R   R3   (    (    R   t   readline>   s    c         C   s   d  S(   N(    (   R   (    (    R   R   ?   s    (   R'   R(   R1   R   R4   R   (    (    (    R   R2   <   s   t   MockHeadersc           B   s   t  Z d   Z RS(   Nc         C   s
   |  i   S(   N(   R   t   values(   R   R   (    (    R   t
   getheadersB   s    (   R'   R(   R7   (    (    (    R   R5   A   s   t   MockResponsec           B   s&   t  Z d  d  Z d   Z d   Z RS(   Nc         C   sA   t  i  i |  |  | | | | f \ |  _ |  _ |  _ |  _ d  S(   N(   t   StringIOt   __init__R   R+   t   codet   msgt   headerst   url(   R   R;   R<   R=   R+   R>   (    (    R   R:   F   s    c         C   s   |  i S(   N(   R   R=   (   R   (    (    R   t   infoI   s    c         C   s   |  i S(   N(   R   R>   (   R   (    (    R   t   geturlK   s    (   R'   R(   R1   R:   R?   R@   (    (    (    R   R8   E   s   	t   MockCookieJarc           B   s   t  Z d   Z d   Z RS(   Nc         C   s   | |  _ d  S(   N(   t   requestR   t   ach_req(   R   RB   (    (    R   t   add_cookie_headerO   s    c         C   s   | | |  _ |  _ d  S(   N(   RB   t   responseR   t   ec_reqt   ec_r(   R   RE   RB   (    (    R   t   extract_cookiesQ   s    (   R'   R(   RD   RH   (    (    (    R   RA   N   s   	t
   FakeMethodc           B   s   t  Z d   Z d   Z RS(   Nc         C   s   | |  _  | |  _ | |  _ d  S(   N(   t	   meth_nameR   t   handlet   action(   R   RJ   RL   RK   (    (    R   R:   U   s    		c         G   s   |  i |  i |  i |  S(   N(   R   RK   RJ   RL   R.   (   R   R.   (    (    R   t   __call__Y   s    (   R'   R(   R:   RM   (    (    (    R   RI   T   s   	t   MockHandlerc           B   s>   t  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   Nc         C   s   |  i |  d  S(   N(   R   t   _define_methodst   methods(   R   RP   (    (    R   R:   ]   s    c         C   sm   xf | D]^ } t |  d j o | \ } } n | d  } } t | | |  i  } t
 |  i | |  q Wd  S(   Ni   (   RP   t   spect   lenR   RL   R1   RI   R   RK   t   metht   setattrt	   __class__(   R   RP   R   RL   RS   RQ   (    (    R   RO   _   s      c         O   sI  |  i i i |  | | | f  | d  j o d  Sn| d j o |  Sn | d j o t	 d d h  d  } | Sn | d j o t d  Sn | i d  oy | | i d	  d
 } y t |  } Wn t j
 o n Xt	 d d h  d  } |  i i d | d | | d h   Sn! | d j o t i d   n t p t  d  S(   Ns   return selfs   return responsei   t   OKt    s   return requests   http://blah/R/   t    i   t   httpi    t   raiset   blah(   R   t   parentt   callst   appendt   fn_nameR.   t   kwdsRL   R1   R8   t   rest   Requestt
   startswitht   rfindR;   t   intR   R/   R   t   URLErrort   Falset   AssertionError(   R   R_   RL   R.   R`   R;   Ra   (    (    R   RK   e   s*    'c         C   s   d  S(   N(    (   R   (    (    R   R   {   s    c         C   s   | |  _  g  |  i  _ d  S(   N(   R\   R   R]   (   R   R\   (    (    R   t
   add_parent|   s    	c         C   s(   t  | d  p t Sn |  i | i j  S(   Nt   handler_order(   t   hasattrt   othert   TrueR   Rj   (   R   Rl   (    (    R   t   __lt__   s    (   R'   R(   R:   RO   RK   R   Ri   Rn   (    (    (    R   RN   \   s   					c         C   s}   g  } d } xj | D]b } d t f d     Y} | |  } | | _ | i |   | d } | i
 |  |  i |  q W| S(   s  Create MockHandlers and add them to an OpenerDirector.

    meth_spec: list of lists of tuples and strings defining methods to define
    on handlers.  eg:

    [["http_error", "ftp_open"], ["http_open"]]

    defines methods .http_error() and .ftp_open() on one handler, and
    .http_open() on another.  These methods just record their arguments and
    return None.  Using a tuple instead of a string causes the method to
    perform some action (see MockHandler.handle()), eg:

    [["http_error"], [("http_open", "return request")]]

    defines .http_error() on one handler (which simply returns None), and
    .http_open() on another handler, which returns a Request object.

    i    t   MockHandlerSubclassc           B   s   t  Z RS(   N(   R'   R(   (    (    (    R   Ro      s    i   N(   t   handlersR3   t	   meth_spect   methsRN   Ro   R!   Rj   Ri   t   openerR^   t   add_handler(   Rs   Rq   R3   Rp   R!   Rr   Ro   (    (    R   t   add_ordered_mock_handlers   s      	
t   OpenerDirectorTestsc           B   s5   t  Z d   Z d   Z d   Z d   Z d   Z RS(   Nc         C   s   t    } d d d g d g d g d	 g g } t | |  } t d  } | i |  }	 |  i
 |	 | d  | d d f | d d f g } x[ t | | i  D]G \ }
 } | \ } } } } |  i
 | | f |
  |  i
 | | f  q Wd  S(
   Nt	   http_opent   ftp_opent   http_error_302s   return selfs   http://example.com/i   i    (   s	   http_opens   return self(   s	   http_opens   return self(   t   OpenerDirectort   oRq   Ru   Rp   Rb   R*   R,   t   rR   t   assertEqualR]   t   zipt   expectedt   gott   handlerR   R.   R`   (   R   R.   R]   Rp   R   R*   R{   R`   Rq   R|   R   R   R   (    (    R   t   test_handled   s    	$  c         C   s   t    } g  } xq d	 g d f d g d f g D]Q \ } } d t f d     Y} | |  } | | _ | i |  | i	 |  q. W| i
 d  } |  i | i d d | d  |  i | i d d | d  d  S(
   NRw   s   return selfi  i    Ro   c           B   s   t  Z RS(   N(   R'   R(   (    (    (    R   Ro      s    s   http://example.com/i   (   s	   http_opens   return self(   Rz   R{   Rp   Rr   Rj   RN   Ro   R!   R^   Rt   R,   R|   R   R}   R]   (   R   Rj   Rp   R!   Rr   R{   Ro   R|   (    (    R   t   test_handler_order   s    	 	c         C   s|   t    } d g d g g } t | |  } t d  } |  i t	 i
 | i |  |  i | i | d d | f h  f g  d  S(   NRw   RZ   s   return selfs   http://example.com/i    (   s	   http_opens   raise(   s	   http_opens   return self(   Rz   R{   Rq   Ru   Rp   Rb   R*   R   R   R   Rf   R,   R}   R]   (   R   Rp   R*   R{   Rq   (    (    R   t
   test_raise   s    	c         C   s)  t    } d g d d g d d d g d g g }	 t | |	  } d	 f  d
     Y} t d  } | i |  }
 t
 | i  d j p t  | d d | f f | d d | |   d d h  f f g } x] t | | i  D]I \ } } | \ } } } |  i | | f | d   |  i | | d  q Wd  S(   NRw   s	   error 302t   http_error_400RZ   Ry   s   return responset   http_error_303t
   http_errort   Unknownc           B   s   t  Z d   Z RS(   Nc         C   s   t  S(   N(   Rm   (   R   Rl   (    (    R   t   __eq__   s    (   R'   R(   R   (    (    (    R   R      s   s   http://example.com/i   i    i.  RW   (   s	   http_opens	   error 302(   R   s   raise(   s   http_error_302s   return response(   Rz   R{   Rq   Ru   Rp   R   Rb   R*   R,   R|   RR   R]   Rh   R~   R   R   R   t   method_nameR.   R   R}   (   R   R.   R]   Rp   R   R   R*   R{   R   Rq   R|   R   R   (    (    R   t   test_http_error   s    	'; c         C   s  t    } d	 d
 g d d g g }	 t | |	  } t d  } | i |  }
 | d d f | d d f | d d f | d d f g } x t
 | i	  D] \ } \ } } } } | d j  oN |  i | | f | |  |  i t |  d  |  i t | d t   q |  i | | f | |  |  i t |  d  |  i t | d t   |  i | d d  j p t | d t   q Wd  S(   Nt   http_requests   return requestt   http_responses   return responses   http://example.com/i    i   i   (   R   s   return request(   R   s   return response(   R   s   return request(   R   s   return response(   Rz   R{   Rq   Ru   Rp   Rb   R*   R,   R|   R]   t	   enumeratet   iR   R   R.   R`   R   R}   RR   t   assert_t
   isinstanceR1   R8   (   R   R.   R   R]   Rp   R   R   R*   R{   Rq   R|   R`   (    (    R   t   test_processors   s     	: (   R'   R(   R   R   R   R   R   (    (    (    R   Rv      s
   				c         C   sJ   d  k  } | i |   } t i d j o | i d  o | d } n | S(   Nt   nts   ///i   (   t   urllibt   pathname2urlR   t   urlpathR
   R   Rc   (   R   R   R   (    (    R   t   sanepathname2url"  s
    	 t   HandlerTestsc           B   sG   t  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   Nc      	      s  d f  d     Y  d t i f   d     Y} d  k } d  k }
 d } | |  } t   } | _
 xod d | i d d	 d
 g d d f d d d d d	 d
 g d d  f d d | i d g  d d  f g D]\ } } } } } } }	 | i t |   } |  i | i | i j o
 d j n  |  i | i |
 i |   |  i | i |  |  i | i |  |  i | i i |  |  i | i i |  | i   } |  i | i! d  |	  |  i t" | d  t# |   q Wd  S(   Nt   MockFTPWrapperc           B   s   t  Z d   Z d   Z RS(   Nc         C   s   | |  _  d  S(   N(   R+   R   (   R   R+   (    (    R   R:   .  s    c         C   s2   | | |  _  |  _ t i |  i  t |  i  f S(   N(   t   filenamet   filetypeR   R9   R+   RR   (   R   R   R   (    (    R   t   retrfile/  s    (   R'   R(   R:   R   (    (    (    R   R   -  s   	t   NullFTPHandlerc              s   t  Z d   Z   d   Z RS(   Nc         C   s   | |  _  d  S(   N(   R+   R   (   R   R+   (    (    R   R:   4  s    c            sH   | | |  _  |  _ | | |  _ |  _ | |  _   |  i  |  _ |  i S(   N(	   t   usert   passwdR   t   hostt   portt   dirsR   R+   t
   ftpwrapper(   R   R   R   R   R   R   (   R   (    R   t   connect_ftp5  s
    	(   R'   R(   R:   R   (    (   R   (    R   R   3  s   	s   rheum rhaponicums    ftp://localhost/foo/bar/baz.htmlt	   localhostt   It   foot   bars   baz.htmls	   text/htmls   ftp://localhost:80/foo/bar/iP   t   DRW   s   ftp://localhost/baz.gif;type=at   As   baz.gifs   Content-types   Content-length($   R   R   t
   FTPHandlerR   t   ftplibt   socketR+   R!   R)   R{   R\   t   FTP_PORTR1   R>   R   R   t   type_R   R   t   mimetypeRx   Rb   R|   R   R   R   R   R}   t   gethostbynameR   R   R?   R=   t   getRe   RR   (   R   R   R   R   R   R   R   R   R+   R   R   R>   R!   R{   R=   R   R|   (    (   R   R   t   test_ftp,  s$    	a *c         C   s  d  k  } d  k } d  k }
 t i   } t   } | _ t	 i
 }	 t t i i |	   } d } xId | d | d |
 i d  | f d |
 i |
 i    | f g D]} t |	 d  } z z | i |  Wd  | i   X| i t |   } z( | i   } | i   } | i   } Wd  | i   Xt i! |	  } | i# | i$  } Wd  t i& |	  X|  i( | |  |  i( | d d  |  i( | d	 d
  |  i( | d |  q Wxw d | g D]h } zQ t |	 d  } z | i |  Wd  | i   X|  i) t i* | i t |   Wd  t i& |	  XqWt i   } t   } | _ x d t+ f d t, f d t, f g D] \ } } t |  } y | i |  Wn* t i* t/ f j
 o |  i0 |  qbX|  i0 | i. | j  |  i( | i1 d  qbWd  S(   Ns   hello, world
s   file://localhost%ss	   file://%ss   file://%s%sR   t   wbs   Content-types
   text/plains   Content-lengtht   13s   Last-modifieds   file://localhost:80%ss   file://ftp.example.com//foo.txts    file://ftp.example.com///foo.txts   file://ftp.example.com/foo.txtt   ftp(2   t   timet   rfc822R   R   t   FileHandlerR!   R)   R{   R\   t   test_supportt   TESTFNR   R
   R   R   R   t   towriteR   t   gethostnameR>   R,   R   t   writeR   t	   file_openRb   R|   R   R+   R?   R=   R@   t   newurlt   statt   statst
   formatdatet   st_mtimet   modifiedt   removeR   R}   R   Rf   Rm   Rg   R   R*   t   OSErrorR   t   type(   R   R   R   R   R   R*   R   R   R+   R   R   R   R>   R!   R   R{   R=   R|   R   (    (    R   t	   test_fileX  sh    	G       " c            sK  d f  d     Y  d f    d     Y} t i   } t   } | _ d } x@d d g D]2\ } }
 t | |
 h  d	 d
 < } | i d d  |   } | i | |  }	 |	 i |	 i |	 i |	 i |	 i |	 i d j d f |	 i   } | i | i |  i |	 i   |  |  i | i d  |  i | i d  |  i | i
 |  |  i | i d  |  i | i  d d d  g  |  i | i |
  qX Wt! | _" |  i# t i$ | i | |  d! g | _% xd" D]}}
 t d |
  } t& d d h  d  }	 | i' |  } |
 d  j o0 |  i) d | i* j  |  i) d | i* j  n/ |  i | i* d d  |  i | i* d d  |  i | i* d d  |  i | i* d d  | i d d  | i d d
  | i d d  | i d d  | i' |  } |  i | i* d d  |  i | i* d d
  |  i | i* d d  |  i | i* d d  qWd  S(#   Nt   MockHTTPResponsec           B   s   t  Z d   Z d   Z RS(   Nc         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   t   fpR   R<   t   statust   reason(   R   R   R<   R   R   (    (    R   R:     s    			c         C   s   d S(   NRW   (    (   R   (    (    R   R     s    (   R'   R(   R:   R   (    (    (    R   R     s   	t   MockHTTPClassc              s>   t  Z d   Z d   Z d   Z d  h  d  Z   d   Z RS(   Nc         C   s   g  |  _ d  |  _ t |  _ d  S(   N(   R   t   req_headersR1   R+   Rg   t   raise_on_endheaders(   R   (    (    R   R:     s    		c         C   s   | |  _  |  S(   N(   R   R   (   R   R   (    (    R   RM     s    	c         C   s   | |  _  d  S(   N(   t   levelR   (   R   R   (    (    R   t   set_debuglevel  s    c         C   so   | |  _  | |  _ |  i | i   7_ |  i i   | o | |  _	 n |  i
 o d  k } | i    n d  S(   N(   t   methodR   R>   t   selectorR   R=   t   itemst   sortt   bodyR+   R   R   R/   (   R   R   R>   R   R=   R   (    (    R   RB     s    		
	c            s     t   h  d d  S(   Ni   RV   (   R   R2   (   R   (   R   (    R   t   getresponse  s    (   R'   R(   R:   RM   R   R1   RB   R   (    (   R   (    R   R     s
   			
s   http://example.com/t   GETt   POSTR[   t   FooR   t   Spamt   eggsi   RV   s   example.comi    R   t
   ConnectionR   RW   s   Content-lengths   Content-typet   0s!   application/x-www-form-urlencodedt   HostR   t   baz(   R   N(   R   s   blah(   R   s   close(   R   s   bar(   R   R   (   R   R   (   RW   N(+   R   R   R   t   AbstractHTTPHandlerR!   R)   R{   R\   R>   R1   R   R+   Rb   R*   t   add_unredirected_headerRY   t   do_openR|   R   R4   R?   R@   R;   R<   t   hdrsR   t   has_keyR   R}   R   R   R   R   Rm   R   R   Rf   R0   R8   t   do_request_t   newreqR   t   unredirected_hdrs(   R   R   RY   R   R>   R!   R*   R{   R   R|   R+   R   R   (    (   R   R   t	   test_http  sb     		 c         C   s   t  i   } t   } | _ d } t |  } t	 d d h  d |  } | i | |  } |  i | | j  |  i t | d   t	 d d h  d |  } |  i | i | |  d  j  |  i | i d  |  i | i | | d d h  f  d  S(	   Ns   http://example.com/i   RV   RW   R-   i   t   CreatedRY   (   R   t   HTTPErrorProcessorR!   R)   R{   R\   R>   Rb   R*   R8   R|   R   t   newrR   R   Rk   R1   R}   R-   R.   (   R   R>   R!   R*   R{   R|   R   (    (    R   t   test_errors  s    c         C   s   t    } t i |  } t   } | _ t d  } t
 d d h  d  } | i |  } |  i | i | j o
 | j n  |  i | i   d  |  i | i    | i | |  } |  i | i | j  |  i | i | j o
 | j n  d  S(   Ns   http://example.com/i   RV   RW   s   example.com(   RA   t   cjR   t   HTTPCookieProcessorR!   R)   R{   R\   Rb   R*   R8   R|   R   R   R   R   RC   R$   t   get_origin_req_hostt   is_unverifiableR   R   RF   RG   (   R   R   R   R!   R*   R{   R|   R   (    (    R   t   test_cookies  s    	'c         C   s  d } d }
 t i   } t   } | _ xud D]m} xdd D]\} t | d |  }	 t | |  } | i d	 d
  | i d d  y, |	 | t   | d t h  d |
 <  Wn6 t i j
 o' |  i | d j o
 | d  j	  n X|  i | i i   |
  y |  i | i i   d  Wn* t j
 o |  i | i i    n X|  i | i i d	 d
  |  i d | i i j  |  i d | i i j  q< Wq/ Wt |  } |
 d  } t | d d } d } y& x | | | d  | d } qWWn, t i j
 o |  i | t i i  n Xt | d d } d } y* x# | | | d |  | d } qCWWn, t i j
 o |  i | t i i   n Xd  S(   Ns   http://example.com/a.htmls   http://example.com/b.htmli-  i.  i/  i3  s
   blah
blah
s   http_error_%st   Nonsenses   viking=withholdR   t   spamt   Blaht   locationR   c      
   C   s/   |  i | t   d d t h  d | <  d  S(   Ni.  R   R   (   R!   Ry   R*   R2   R5   R>   (   R!   R*   R>   (    (    R   t   redirectE  s    t   origin_req_hosts   example.comi    i   s   http://example.com/s   http://example.com/%d(   i-  i.  i/  i3  (   Ns
   blah
blah
(!   t   from_urlt   to_urlR   t   HTTPRedirectHandlerR!   R)   R{   R\   R;   R1   R+   t   getattrR   Rb   R*   t
   add_headerR   R2   R5   t	   HTTPErrorR   R   R}   t   get_full_urlt
   get_methodt   AttributeErrort   has_dataR=   R   R   R3   t   max_repeatst   max_redirections(   R   R   R;   R3   R!   R*   R{   R   R+   R   R   (    (    R   t   test_redirect&  s^      %!    	c         C   s   d t  i f d     Y}
 d k l } d k  l } l } l }	 l } d k l	 } |   } | | d d  |
   } | |  } | | |  } | i d  |  i | i i d   d  S(	   Nt   MockHTTPHandlerc           B   s   t  Z d   Z d   Z RS(   Nc         C   s   d |  _ d  S(   Ni    (   R   t   _count(   R   (    (    R   R:   c  s    c         C   s   d  k  } d k l } |  i d j oK |  i d |  _ | i | d   } |  i i d | t	   d d |  Sn; | |  _ | i | d   } t
 d	 d
 | d | i    Sd  S(   N(   s   StringIOi    i   s%   Location: http://www.cracker.com/

RY   i.  t   Founds   

i   RV   RW   (   t	   mimetoolsR9   R   R  t   MessageR<   R\   R/   R*   R2   R8   R   (   R   R*   R
  R9   R<   (    (    R   Rw   d  s    	&	(   R'   R(   R:   Rw   (    (    (    R   R  b  s   	(   s	   CookieJar(   s   build_openers   HTTPHandlers	   HTTPErrors   HTTPCookieProcessor(   s   interact_netscapes   http://www.example.com/s	   spam=eggst   Cookie(   R   t   HTTPHandlerR  t	   cookielibt	   CookieJart   build_openerR   R   t   test_cookielibt   interact_netscapeR   t   hht   cpR{   R,   R   R   R*   t
   has_header(   R   R   R  R  R  R{   R   R  R  R   R  R  (    (    R   t   test_cookie_redirecta  s    		(	   R'   R(   R   R   R   R   R   R  R  (    (    (    R   R   *  s   	,	S	[			;t	   MiscTestsc           B   s   t  Z d   Z d   Z RS(   Nc         C   s8  d t  i f d     Y} d t  i f d     Y} d t  i f d     Y} t  i } | | |  } |  i	 | |  |  i	 | |  | | |    } |  i	 | |  |  i	 | |  | |  } |  i	 | |  |   } |  i	 | t  i  | t  i  } |  i	 | t  i  | t  i    } |  i	 | t  i  d  S(   Nt   MyHTTPHandlerc           B   s   t  Z RS(   N(   R'   R(   (    (    (    R   R    s    t
   FooHandlerc           B   s   t  Z d   Z RS(   Nc         C   s   d  S(   N(    (   R   (    (    R   t   foo_open  s    (   R'   R(   R  (    (    (    R   R    s   t
   BarHandlerc           B   s   t  Z d   Z RS(   Nc         C   s   d  S(   N(    (   R   (    (    R   t   bar_open  s    (   R'   R(   R  (    (    (    R   R    s   (
   R   R  R  t   BaseHandlerR  R  R  R{   R   t   opener_has_handler(   R   R  R  R{   R  R  (    (    R   t   test_build_opener  s$    		c         C   s:   x3 | i D] } | i | j o Pq
 q
 W|  i t  d  S(   N(   Rs   Rp   R!   RU   t   handler_classR   R   Rg   (   R   Rs   R   R!   (    (    R   R    s
    
 	(   R'   R(   R  R  (    (    (    R   R    s   	t   NetworkTestsc           B   sP   t  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(	   Nc         C   s   d  S(   N(    (   R   (    (    R   t   setUp  s    c         C   sS   t  i d d h  d d <} t  i |  } | i   } |  i t	 |  d  d  S(   Ns   http://www.python.orgR=   t   Ranges   bytes=20-39i   (
   R   Rb   R*   R	   t   resultR   R+   R   R}   RR   (   R   R*   R$  R+   (    (    R   t
   test_range  s
    	c         C   s)   d d d g } |  i | |  i    d  S(   Ns-   ftp://www.python.org/pub/python/misc/sousa.aus!   ftp://www.python.org/pub/tmp/blats[   ftp://gatekeeper.research.compaq.com/pub/DEC/SRC/research-reports/00README-Legal-Rules-Regs(   t   urlsR   t
   _test_urlst   _extra_handlers(   R   R&  (    (    R   R     s    c         C   s&   d d g } |  i | |  i    d  S(   Ns3   gopher://gopher.lib.ncsu.edu/11/library/stacks/Alexs"   gopher://gopher.vt.edu:10010/10/33(   R&  R   R'  R(  (   R   R&  (    (    R   t   test_gopher  s    c         C   s   t  i } t | d  } ze | i d  | i   d t t i i	 |   d d  t t i f f g } |  i | |  i    Wd  t i |  Xd  S(   Nt   ws	   hi there
s   file:s   file://nonsensename/etc/passwd(   R   R   R,   R   R   R   R   R
   R   R   R1   R   R   R/   R&  R   R'  R(  R   (   R   R   R&  R   (    (    R   R     s    	
4 c         C   s,   d d d d g } |  i | |  i    d  S(   Ns   http://www.espn.com/s)   http://www.python.org/Spanish/Inquistion/s%   http://www.python.org/cgi-bin/faqw.pys:   query=pythonistas&querytype=simple&casefold=yes&req=searchs   http://www.python.org/(   s%   http://www.python.org/cgi-bin/faqw.pys:   query=pythonistas&querytype=simple&casefold=yes&req=searchN(   R1   R&  R   R'  R(  (   R   R&  (    (    R   R     s    c         C   s5  d  k  } d  k }
 d  k } | i d  i } t i t i |    x | D] } t | t  o | \ } } } n d  } } | |  y t i | |  } WnL t | i t f j
 o4 }	 | |	  | o |  i t |	 |   qn, X| i   } | i   | d t |   | d  |
 i d  qJ Wd  S(   Nt   test_urllib2s   read %d bytess   ******** next url coming up...f0.10000000000000001(   R   R   t   loggingt	   getLoggert   debugR   t   install_openerR  Rp   R&  R>   R   t   tupleR*   t   expected_errR1   R	   R   t   IOErrorR/   R   t   errR   R   R   R   R   RR   t   sleep(   R   R&  Rp   R1  R*   R,  R   R   R>   R3  R   R.  R   (    (    R   R'    s,    			 




c         C   s@   g  } | i t i  t i   } | i d  | i |  | S(   Ni   (   Rp   R^   R   t   GopherHandlert   CacheFTPHandlert   cfht
   setTimeout(   R   R7  Rp   (    (    R   R(    s    (
   R'   R(   R"  R%  R   R)  R   R   R'  R(  (    (    (    R   R!    s   		
					&	c         C   sD   t  t t t f } t i d  o | t f 7} n t i |   d  S(   Nt   network(	   R    Rv   R   R  R"   R   t   is_resource_enabledR!  t   run_unittest(   t   verboseR"   (    (    R   t	   test_main3  s    t   __main__R<  (   t   unittestt   testR   R
   R   R9   R   Rb   Rz   t   TestCaseR    R)   R2   t   dictR5   R8   RA   RI   RN   Ru   Rv   R   R   R  R!  R1   R=  R'   Rm   (   R   R!  R?  R5   Rv   R8   RI   RA   R   R=  RN   Rb   R   R2   Rz   R   Ru   R   R    R9   R  R)   R
   (    (    R   t   ?   s.   			"	)	~	 X(	