o
    >i]	                     @   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___runselfserver_addressRequestHandlerClass r   f/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/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| dS )Nzhttp://127.0.0.1:z/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:r   r   r   r   r   netlocG   s   zMockServer.netlocc                 C   s   d| j  dS )Nzhttp:///)r3   r   r   r   r   urlK   s   zMockServer.urlN)
r"   r#   r$   r%   r'   r	   r2   propertyr3   r5   r   r   r   r   r/   9   s    
r/   c                 C   sB   t jt j| } d}|du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)r8   	authoritybaser   r   r   path_to_urlP   s
   rB   r1   )r%   Zhttp.serverr   r7   r   r   urllib.parser;   urllib.requestr   r   r   ZBaseHTTPRequestHandlerr'   r   r/   rB   r   r   r   r   <module>   s    '