U
    aÊ¹jc	  ã                   @   s‚   d Z ddlZddlZddlZddlZddlZddlZG dd„ dej	j
ƒZG dd„ dej	jƒZG dd„ dej	j
ejƒZdd	d
„ZdS )z>Basic http server for tests to simulate PyPI or custom indexesé    Nc                   @   s:   e Zd ZdZdejjfdd„Zdd„ Zdd„ Z	d	d
„ Z
dS )ÚIndexServeraY  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()
    ©Ú r   c                 C   s   t jj | ||¡ d| _d S ©NT)ÚhttpÚserverÚ
HTTPServerÚ__init__Z_run©ÚselfÚserver_addressÚRequestHandlerClass© r   úV/var/www/html/bwave/python/venv/lib/python3.8/site-packages/setuptools/tests/server.pyr	      s    zIndexServer.__init__c                 C   s   t j| jd�| _| j ¡  d S )N)Útarget)Ú	threadingÚThreadÚserve_foreverÚthreadÚstart©r   r   r   r   r      s    zIndexServer.startc                 C   s*   t  d¡ |  ¡  | j ¡  | j ¡  dS )zStop the servergš™™™™™¹?N)ÚtimeÚsleepÚshutdownr   ÚjoinÚsocketÚcloser   r   r   r   Ústop#   s    

zIndexServer.stopc                 C   s   | j }d| S )Nz-http://127.0.0.1:%s/setuptools/tests/indexes/©Zserver_port)r   Úportr   r   r   Úbase_url-   s    zIndexServer.base_urlN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚSimpleHTTPRequestHandlerr	   r   r   r    r   r   r   r   r      s   ý

r   c                   @   s   e Zd Zdd„ ZdS )ÚRequestRecorderc                 C   s,   t | jƒ dg ¡}| | ¡ |  dd¡ d S )NÚrequestséÈ   ÚOK)Úvarsr   Ú
setdefaultÚappendZsend_response)r   r'   r   r   r   Údo_GET3   s    
zRequestRecorder.do_GETN)r!   r"   r#   r-   r   r   r   r   r&   2   s   r&   c                   @   s>   e Zd ZdZdefdd„Zdd„ Zedd„ ƒZed	d
„ ƒZ	dS )Ú
MockServerzD
    A simple HTTP Server that records the requests made to it.
    r   c                 C   s.   t jj | ||¡ tj | ¡ d| _g | _d S r   )r   r   r   r	   r   r   Údaemonr'   r
   r   r   r   r	   >   s    zMockServer.__init__c                 C   s   |   ¡  d S )N)r   r   r   r   r   ÚrunD   s    zMockServer.runc                 C   s
   d| j  S )Nzlocalhost:%sr   r   r   r   r   ÚnetlocG   s    zMockServer.netlocc                 C   s
   d| j  S )Nz
http://%s/)r1   r   r   r   r   ÚurlK   s    zMockServer.urlN)
r!   r"   r#   r$   r&   r	   r0   Úpropertyr1   r2   r   r   r   r   r.   9   s   
r.   c                 C   sB   t j t j | ¡¡} d}|dk	r,|d| 7 }tj |tj | ¡¡S )zConvert a path to a file: URL.zfile:Nz//)	ÚosÚpathÚnormpathÚabspathÚurllibÚparseÚurljoinÚrequestÚpathname2url)r5   Ú	authorityÚbaser   r   r   Úpath_to_urlP   s
    r?   )N)r$   Zhttp.serverr   r4   r   r   Úurllib.parser8   Úurllib.requestr   r   r   ZBaseHTTPRequestHandlerr&   r   r.   r?   r   r   r   r   Ú<module>   s   '