
    sih                         S r SSKrSSKrSSKrSSKrSSKrS\S\R                  R                  4S jr
\S:X  a  \
" SS9r\" \5        gg)	af  
HTTP test server for serving local files during tests.

This module provides a local HTTP server that can be used in pytest fixtures
to serve files from a specified directory. The server runs on a random port
and supports both IPv4 and IPv6.

The server is commonly used for testing:
- Mock conda channels with packages and repodata
- Remote environment files (environment.yml)
- Remote configuration files
- Any scenario where conda needs to fetch files from HTTP URLs

Example usage:

    from conda.testing import http_test_server

    def test_something():
        server = http_test_server.run_test_server("/path/to/files")
        host, port = server.socket.getsockname()[:2]
        url = f"http://{host}:{port}/file.txt"

        # Make HTTP requests to url...

        server.shutdown()

For pytest fixtures that wrap this functionality, see:
- `http_test_server` - function-scoped fixture

The fixture can be configured via `@pytest.mark.parametrize("http_test_server", ["<directory>"], indirect=True)`
to specify the directory to serve, or used without parametrize (or with `None`) for dynamic content generation.
    N	directoryreturnc                    ^ ^  " U 4S jS[         R                  R                  5      mU4S jn[        R                  " 5       n[
        R                  " X4SS9R                  5         UR                  SS9$ )zX
Run a test server on a random port. Inspect returned server to get port,
shutdown etc.
c                   B   >^  \ rS rSrSrSrSrU 4S jrU4S jrSr	U =r
$ )(run_test_server.<locals>.DualStackServer1   FT@   c                    > [         R                  " [        5         U R                  R	                  [        R
                  [        R                  S5        S S S 5        [        TU ]!  5       $ ! , (       d  f       N= f)Nr   )	
contextlibsuppress	Exceptionsocket
setsockoptIPPROTO_IPV6IPV6_V6ONLYsuperserver_bind)self	__class__s    >lib/python3.13/site-packages/conda/testing/http_test_server.pyr   4run_test_server.<locals>.DualStackServer.server_bind6   sP    $$Y/&&v':':F<N<NPQR 07&(( 0/s   :A,,
A:c                 (   > U R                  XU TS9  g )Nr   )RequestHandlerClass)r   requestclient_addressr   s      r   finish_request7run_test_server.<locals>.DualStackServer.finish_request<   s    $$Wdi$X     )__name__
__module____qualname____firstlineno__daemon_threadsallow_reuse_addressrequest_queue_sizer   r   __static_attributes____classcell__)r   r   s   @r   DualStackServerr   1   s%    "	)	Y 	Yr   r*   c                   > T" S[         R                  R                  5       nUR                  R	                  5       S S u  p#U R
                  " U5        SU;   a  SU S3OUn[        SU SU SU SU S	3	5         UR                  5         S S S 5        g ! [         a    [        S
5         N f = f! , (       d  f       g = f)N)z	127.0.0.1r      :[]zServing HTTP on z port z	 (http://z/) ...z&
Keyboard interrupt received, exiting.)	httpserverSimpleHTTPRequestHandlerr   getsocknameputprintserve_foreverKeyboardInterrupt)queuehttpdhostporturl_hostr*   s        r   start_server%run_test_server.<locals>.start_server?   s    dkkBB
113BQ7JDIIe&)Tk4&{tH$TF&iz4&PVWXA##%
 
 % A?@A
 
s*   AB0<BB-*B0,B--B00
B>T)targetargsdaemon   )timeout)	r0   r1   ThreadingHTTPServerr8   Queue	threadingThreadstartget)r   r=   startedr*   s   `  @r   run_test_serverrK   +   sZ    Y$++99 YA kkmGLz$GMMO;;q;!!r   __main__.r   )__doc__r   http.serverr0   r8   r   rF   strr1   rD   rK   r!   r5   r    r   r   <module>rQ      sZ   B     %"s %"t{{'F'F %"P zs+F	&M r   