σ
ΌS]c           @@ sς   d  d l  m Z m Z d  d l m Z d  d l m Z d  d l m Z m	 Z	 d  d l
 m Z d  d l Z d  d l Z d  d l Z d e	 f d     YZ d	 e	 f d
     YZ d e f d     YZ d e f d     YZ d e f d     YZ d S(   i    (   t   absolute_importt   print_function(   t
   HTTPServer(   t   bind_sockets(   t   Applicationt   RequestHandler(   t   genNt   _DownloadViewc           B@ s#   e  Z d    Z e j d    Z RS(   c         O@ s    t  t |   j | | |  d  S(   N(   t   superR   t   __init__(   t   selft   applicationt   argst   kwargs(    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyR	      s    c         o@ sC  |  j  d  } |  j  d d   } t |  j  d   } t d |  | r_ t t |    } n  |  j d  |  j d t |   d d j	 d	  } | } xx | d
 k r| |  }	 | rΚ | j
 |	  n  | t |	  } |  j |	  y |  j   VWq t k
 r}
 |
  q Xq W| r5| j   |  j j | <n  |  j   d  S(   Nt   idt   hash_algorithmt   lengths   Planning to send %d bytesiΘ   s   Content-Lengtht   abcdefghijklmnopi   s   utf-8i    (   t   get_argumentt   Nonet   intt   printt   getattrt   hashlibt
   set_statust
   set_headert   strt   encodet   updatet   lent   writet   flusht	   Exceptiont	   hexdigestR   t   hashest   finish(   R
   R   R   t   download_idR   R   t   hashert   datat	   remainingt   to_writet   e(    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyt   get   s.    
(   t   __name__t
   __module__R	   R   t	   coroutineR*   (    (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyR      s   	t
   _ErrorViewc           B@ s   e  Z d    Z d   Z RS(   c         O@ s    t  t |   j | | |  d  S(   N(   R   R.   R	   (   R
   R   R   R   (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyR	   8   s    c         O@ s   |  j  d  |  j   d  S(   Ni  (   R   R#   (   R
   R   R   (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyR*   <   s    (   R+   R,   R	   R*   (    (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyR.   7   s   	t   _TestServerApplicationc           B@ s   e  Z d    Z RS(   c         K@ sA   t    |  _ d t f d t f g } t t |   j | |  d  S(   Ns	   /downloads   /error(   t   dictR"   R   R.   R   R/   R	   (   R
   R   t   patterns(    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyR	   B   s    (   R+   R,   R	   (    (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyR/   A   s   t   _TestServerc           B@ sb   e  Z d    Z e d    Z e d    Z d   Z d   Z e d    Z d   Z	 d   Z
 RS(   c         C@ s   t    |  _ t |  j  |  _ t d d  d d  } d  |  _ x6 | D]. } | j t j	 k rC | j
   d |  _ qC qC W|  j d  k	 s t  |  j j |  d  S(   Nt   portt   addresss	   127.0.0.1i   (   R/   t   _applicationR   t   _httpR   R   t   _portt   familyt   sockett   AF_INETt   getsocknamet   AssertionErrort   add_sockets(   R
   t   socketst   s(    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyR	   I   s    	c         C@ s   |  j  S(   N(   R7   (   R
   (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyR3   Y   s    c         C@ s   d |  j  S(   Ns   http://localhost:%d/(   R3   (   R
   (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyt   url]   s    c         C@ s   |  j  j d  d  S(   Ni   (   R6   t   start(   R
   (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyRA   a   s    c         C@ s   |  j  j   |  j  j   d  S(   N(   R6   t   close_all_connectionst   stop(   R
   (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyt   unlistend   s    c         C@ s   |  j  d S(   Nt   error(   R@   (   R
   (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyt	   error_urlh   s    c         C@ sF   |  j  d t t j    d t |  } | rB | d | 7} n  | S(   Ns   download?id=s   &length=s   &hash_algorithm=(   R@   R   t   uuidt   uuid4(   R
   t   download_lengthR   R@   (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyt   new_download_urll   s    +c         C@ sT   | j  d  } | | d d  } | |  j j k rF t d |   n  |  j j | S(   Ns   id=i   i$   s3   It looks like the download from %s did not complete(   t   indexR5   R"   t   RuntimeError(   R
   t   download_urlt   iR$   (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyt'   server_computed_hash_for_downloaded_urlr   s
    (   R+   R,   R	   t   propertyR3   R@   RA   RD   RF   RJ   RO   (    (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyR2   H   s   				t   HttpServerTestContextc           B@ s#   e  Z d    Z d   Z d   Z RS(   c         C@ s   t    |  _ d  S(   N(   R2   t   _server(   R
   (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyR	   {   s    c         C@ s   |  j  j   d  S(   N(   RR   RD   (   R
   t   typet   valuet	   traceback(    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyt   __exit__~   s    c         C@ s   |  j  j   |  j  S(   N(   RR   RA   (   R
   (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyt	   __enter__   s    (   R+   R,   R	   RV   RW   (    (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyRQ   z   s   		(   t
   __future__R    R   t   tornado.httpserverR   t   tornado.netutilR   t   tornado.webR   R   t   tornadoR   RG   R   R9   R   R.   R/   t   objectR2   RQ   (    (    (    sI   lib/python2.7/site-packages/anaconda_project/internal/test/http_server.pyt   <module>   s   $
2