ó
OyTLc           @   sh   d  Z  d d l Z d d l Z d d l m Z d d l m Z d d l m Z d e f d „  ƒ  YZ	 d S(   s?   Basic http server for tests to simulate PyPI or custom indexes
iÿÿÿÿN(   t   Thread(   t
   HTTPServer(   t   SimpleHTTPRequestHandlert   IndexServerc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sY  Basic single-threaded http server simulating a package index

    You can use this server in unittest like this::
        s = IndexServer()
        s.start()
        index_url = s.base_url() + 'mytestindex'
        # do some test requests to the index
        # The index files should be located in setuptools/tests/indexes
        s.stop()
    c         C   s    t  j |  d t ƒ t |  _ d  S(   Nt    i    (   R   i    (   R   t   __init__R   t   Truet   _run(   t   self(    (    s;   /usr/lib/python2.7/dist-packages/setuptools/tests/server.pyR      s    c         C   s(   x! t  r# |  j ƒ  |  j s Pq q Wd  S(   N(   R   t   handle_requestR   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/setuptools/tests/server.pyt   serve   s    	
	 c         C   s&   t  d |  j ƒ |  _ |  j j ƒ  d  S(   Nt   target(   R    R
   t   threadt   start(   R   (    (    s;   /usr/lib/python2.7/dist-packages/setuptools/tests/server.pyR      s    c         C   su   t  |  _ yD t j d k r8 t j d |  j d d ƒ n t j d |  j ƒ Wn t j k
 rc n X|  j	 j
 ƒ  d S(   s.   self.shutdown is not supported on python < 2.6s   2.6s   http://127.0.0.1:%s/i   N(   t   FalseR   t   syst   versiont   urllib2t   urlopent   server_portt   Nonet   URLErrorR   t   join(   R   (    (    s;   /usr/lib/python2.7/dist-packages/setuptools/tests/server.pyt   stop!   s    	c         C   s   |  j  } d | S(   Ns-   http://127.0.0.1:%s/setuptools/tests/indexes/(   R   (   R   t   port(    (    s;   /usr/lib/python2.7/dist-packages/setuptools/tests/server.pyt   base_url.   s    	(   t   __name__t
   __module__t   __doc__R   R
   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/setuptools/tests/server.pyR   	   s   
				(
   R   R   R   t	   threadingR    t   BaseHTTPServerR   t   SimpleHTTPServerR   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/setuptools/tests/server.pyt   <module>   s   