Current Dir: /snap/core22/2955/usr/lib/python3/dist-packages/requests_unixsocket/__pycache__/

[FILE] adapters.cpython-310.pyc [ edit | delete | rename ]
[FILE] testutils.cpython-310.pyc [ edit | delete | rename ]
[FILE] __init__.cpython-310.pyc [ edit | delete | rename ]

Viewing: /snap/core22/2955/usr/lib/python3/dist-packages/requests_unixsocket/__pycache__/testutils.cpython-310.pyc

o

��V]�@stdZddlZddlZddlZddlZddlZddlZe�e�Z	Gdd�dej
�ZGdd�d�ZGdd�dej
�Z
dS)	a
Utilities helpful for writing tests

Provides a UnixSocketServerThread that creates a running server, listening on a
newly created unix socket.

Example usage:

.. code-block:: python

    def test_unix_domain_adapter_monkeypatch():
        with UnixSocketServerThread() as usock_thread:
            with requests_unixsocket.monkeypatch('http+unix://'):
                urlencoded_usock = quote_plus(usock_process.usock)
                url = 'http+unix://%s/path/to/page' % urlencoded_usock
                r = requests.get(url)
�Ncs$eZdZ�fdd�Zdd�Z�ZS)�
KillThreadcs tt|�j|i|��||_dS�N)�superr�__init__�server)�selfr�args�kwargs��	__class__��?/usr/lib/python3/dist-packages/requests_unixsocket/testutils.pyrs
zKillThread.__init__cCs$t�d�t�d�|jj��dS)N��Sleeping)�time�sleep�logger�debugr�_map�clear�rrrr
�run#s

zKillThread.run)�__name__�
__module__�__qualname__rr�
__classcell__rrr
r
rsrc@seZdZdZdd�ZdS)�WSGIAppNcCsht�d|d�t�d|�d}dd|dfd|d	fd
|dfg}d}|||�t�d|||�|gS)
Nz WSGIApp.__call__: Invoked for %s�	PATH_INFOzWSGIApp.__call__: environ = %rz200 OK)zX-Transportzunix domain socketz
X-Socket-Path�SERVER_PORTzX-Requested-Query-String�QUERY_STRINGzX-Requested-PathsHello world!zZWSGIApp.__call__: Responding with status_text = %r; response_headers = %r; body_bytes = %r)rr)r�environ�start_response�status_text�response_headers�
body_bytesrrr
�__call__,s


�
�zWSGIApp.__call__)rrrrr%rrrr
r)srcs<eZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Z�ZS)�UnixSocketServerThreadcs4tt|�j|i|��|��|_d|_t��|_dSr)	rr&r�get_tempfile_name�usockr�	threading�Event�server_ready_event)rrr	r
rr
rAs
zUnixSocketServerThread.__init__cCs,t�t�jt��t��jdd�f}d|S)Ni����z/tmp/test_requests.%s_%s_%s)�os�stat�__file__�st_ino�getpid�uuid�uuid4�hex�rrrrr
r'Gs$z(UnixSocketServerThread.get_tempfile_namecCsDt�d|�t�}tj||jd�}||_||_|j��|�	�dS)NzCall waitress.serve in %r ...)�unix_socket)
rrr�waitress�
create_serverr(rr+�setr)r�wsgi_apprrrr
rNs
zUnixSocketServerThread.runcCs0t�d|�|��t�d|�|j��|S)NzStarting %r ...zStarted %r.)rr�startr+�waitrrrr
�	__enter__Ws

z UnixSocketServerThread.__enter__cGs&|j��|jrt|j���dSdSr)r+r;rrr:r4rrr
�__exit__^s
�zUnixSocketServerThread.__exit__)	rrrrr'rr<r=rrrr
r
r&@s	r&)�__doc__�loggingr,r)rr1r6�	getLoggerrr�Threadrrr&rrrr
�<module>s

Upload File: