o
    hF                     @   s  d dl 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d dlZd dlZd dl	m
Z
 eejdkp5ejdkdZedejv dZedejv d	Zee d
kdZee dkoeejdkoeejdk dZdd Zee  dZdd Zdd Zdd Ze jdd ZdS )    N)bind_unused_portposixcygwinznon-unix platformTRAVISz!timing tests unreliable on travis
NO_NETWORKznetwork access disabledCPythonzNot CPython implementationPyPy)   )   	   zpypy3 5.8 has buggy ssl modulec                  C   s   t jsdS d } z/zt  t j} | d W n t jy+   Y W | d ur)|   dS dS w W | d ur5|   dS | d ur@|   w w )NF)z::1r   T)sockethas_ipv6AF_INET6binderrorclose)sock r   E/var/www/vscode/kcb/lib/python3.10/site-packages/tornado/test/util.py_detect_ipv6*   s&   
r   zipv6 support not presentc                  C   sT   t  \} }| d t }|d|f |  \}}|  |   |j|d fS )zReturns a local port number that will refuse all connections.

    Return value is (cleanup_func, port); the cleanup function
    must be called to free the port to be reused.
    Tz	127.0.0.1   )r   setblockingr   connectacceptr   )server_socketportclient_socketconnclient_addrr   r   r   refusing_port>   s   


r   c                 C   s*   t | fi |}i }tt||| |S )zExecute ``s`` in a given context and return the result namespace.

    Used to define functions for tests in particular python
    versions that would be syntax errors in older versions.
    )dictexectextwrapdedent)caller_globalscaller_localssglobal_namespacelocal_namespacer   r   r   	exec_testR   s   	r)   c                 O   s:   z| j }W n ty   tdd }Y nw ||i |S )zqCompatibility shim for unittest.TestCase.subTest.

    Usage: ``with tornado.test.util.subTest(self, x=x):``
    c                     s    d V S )Nr   )akwr   r   r   <lambda>i   s    zsubTest.<locals>.<lambda>)subTestAttributeError
contextlibcontextmanager)testargskwargsr-   r   r   r   r-   a   s   
r-   c                   c   sB    t   t dt dV  W d   dS 1 sw   Y  dS )z/Context manager to ignore deprecation warnings.ignoreN)warningscatch_warningssimplefilterDeprecationWarningr   r   r   r   ignore_deprecationm   s
   
"r9   )r/   osplatformr   sysr"   typingunittestr5   tornado.testingr   skipIfnameskipIfNonUnixenvironskipOnTravisskipIfNoNetworkpython_implementationskipNotCPythonversion_infopypy_version_infoskipPypy3V58r   skipIfNoIPv6r   r)   r-   r0   r9   r   r   r   r   <module>   sD    
