ó
ú2ec           @   sê   d  Z  d d l Z d d l Td e f d „  ƒ  YZ d d d d „ Z e d k ræ d d l m	 Z	 d d	 l
 m Z e e ƒ Z d
 e j Z d „  Z d e d ƒ k sª t ‚ d e d ƒ k sÂ t ‚ e j d ƒ e j ƒ  e	 e ƒ n  d S(   s‚   
WSGI Test Server

This builds upon paste.util.baseserver to customize it for regressions
where using raw_interactive won't do.


iÿÿÿÿN(   t   *t   WSGIRegressionServerc           B   sV   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d d	 „ Z
 RS(
   sN  
    A threaded WSGIServer for use in regression testing.  To use this
    module, call serve(application, regression=True), and then call
    server.accept() to let it handle one request.  When finished, use
    server.stop() to shutdown the server. Note that all pending requests
    are processed before the server shuts down.
    i
   c         O   sE   t  j |  | | Ž g  |  _ g  |  _ |  j |  _ |  j j d ƒ d  S(   Ni   (   t
   WSGIServert   __init__t   stoppingt   pendingt   defaulttimeoutt   timeoutt   sockett
   settimeout(   t   selft   argst   kwargs(    (    s@   /usr/local/lib/python2.7/dist-packages/paste/debug/testserver.pyR      s
    		c         C   s0   d d l  m } | d |  j ƒ } | j ƒ  d  S(   Niÿÿÿÿ(   t   Threadt   target(   t	   threadingR   t   serve_pendingt   start(   R
   R   t   thread(    (    s@   /usr/local/lib/python2.7/dist-packages/paste/debug/testserver.pyt   serve_forever    s    c         C   s&   |  j  r" t j ƒ  |  j  |  _ n  d  S(   N(   R   t   timet   expires(   R
   (    (    s@   /usr/local/lib/python2.7/dist-packages/paste/debug/testserver.pyt   reset_expires$   s    	c         O   s.   t  j |  | | Ž |  j j ƒ  |  j ƒ  d  S(   N(   R   t   close_requestR   t   popR   (   R
   R   R   (    (    s@   /usr/local/lib/python2.7/dist-packages/paste/debug/testserver.pyR   '   s    c         C   sx   |  j  ƒ  xg |  j s  |  j rs t j ƒ  } | |  j k rM |  j rM d GHPn  |  j rc |  j ƒ  n  t j d ƒ q Wd  S(   Ns0   
WARNING: WSGIRegressionServer timeout exceeded
gš™™™™™¹?(   R   R   R   R   R   R   t   handle_requestt   sleep(   R
   t   now(    (    s@   /usr/local/lib/python2.7/dist-packages/paste/debug/testserver.pyR   +   s    
	c         C   s   |  j  j t ƒ d S(   s/    stop the server (called from tester's thread) N(   R   t   appendt   True(   R
   (    (    s@   /usr/local/lib/python2.7/dist-packages/paste/debug/testserver.pyt   stop7   s    i   c         C   s=   |  j  s t ‚ g  t | ƒ D] } |  j j t ƒ ^ q d S(   s6    accept another request (called from tester's thread) N(   R   t   AssertionErrort   rangeR   R   R   (   R
   t   countt   x(    (    s@   /usr/local/lib/python2.7/dist-packages/paste/debug/testserver.pyt   accept:   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R#   (    (    (    s@   /usr/local/lib/python2.7/dist-packages/paste/debug/testserver.pyR      s   						c         C   s/   t  |  | | | ƒ } d | j GH| j ƒ  | S(   Ns   serving on %s:%s(   R   t   server_addressR   (   t   applicationt   hostt   portt   handlert   server(    (    s@   /usr/local/lib/python2.7/dist-packages/paste/debug/testserver.pyt   serve?   s    
t   __main__(   t   urlopen(   t   dump_environs   http://%s:%sc         C   s:   t  j d ƒ d d  l } | j d ƒ t t |  ƒ j ƒ  S(   Ni   iÿÿÿÿi   (   R,   R#   R   t   setdefaulttimeoutR/   t   baseurit   read(   t   pathR   (    (    s@   /usr/local/lib/python2.7/dist-packages/paste/debug/testserver.pyt   fetchK   s    s   PATH_INFO: /foos   /foos   PATH_INFO: /wombles   /womblei   (   R&   R   t   paste.httpserverR   R   t   NoneR-   R$   t   six.moves.urllib.requestR/   t   paste.wsgilibR0   R,   R'   R2   R5   R   R#   R   (    (    (    s@   /usr/local/lib/python2.7/dist-packages/paste/debug/testserver.pyt   <module>   s   
/	

