HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/asynctest/__pycache__/selector.cpython-37.pyc
B

�P�e�-�@s|dZddlZyddlZWn ek
r8ddlmZYnXddlZyddlZWnek
rfdZYnXddlmZddlm	Z	Gdd�de
�Zdd	�Zd
d�Z
Gdd
�d
ej�ZGdd�de�Zer�Gdd�de�Zdd�Zdd�Zdd�ZGdd�dej�Zdd�Zeed��rdd�Zn eejd��r6d d�Znd!d�Zd"d#�Zd$d%�Zd&d'�Zd(e	jd)<ee�e	j	_ ee�e	j	_!dS)*ay
Module ``selector``
-------------------

Mock of :mod:`selectors` and compatible objects performing asynchronous IO.

This module provides classes to mock objects performing IO (files, sockets,
etc). These mocks are compatible with :class:`~asynctest.TestSelector`, which
can simulate the behavior of a selector on the mock objects, or forward actual
work to a real selector.
�N�)�mock)�_fail_oncs,eZdZdZdZ�fdd�Zdd�Z�ZS)�FileDescriptora�
    A subclass of int which allows to identify the virtual file-descriptor of a
    :class:`~asynctest.FileMock`.

    If :class:`~asynctest.FileDescriptor()` without argument, its value will be
    the value of :data:`~FileDescriptor.next_fd`.

    When an object is created, :data:`~FileDescriptor.next_fd` is set to the
    highest value for a :class:`~asynctest.FileDescriptor` object + 1.
    rcsH|s|st��|tj�}nt�j|f|�|�}ttjd|d�t_|S)Nr)�super�__new__r�next_fd�max)�cls�args�kwargs�s)�	__class__��C/opt/alt/python37/lib/python3.7/site-packages/asynctest/selector.pyr.s
zFileDescriptor.__new__cCstd�|��S)Nz__FileDescriptor_{})�hash�format)�selfrrr�__hash__8szFileDescriptor.__hash__)�__name__�
__module__�__qualname__�__doc__rrr�
__classcell__rr)rrr!s

rcCs4yt|t�r|S|��Stk
r.t�YnXdS)a�
    Return the :class:`~asynctest.FileDescriptor` value of ``fileobj``.

    If ``fileobj`` is a :class:`~asynctest.FileDescriptor`, ``fileobj`` is
    returned, else ``fileobj.fileno()``  is returned instead.

    Note that if fileobj is an int, :exc:`ValueError` is raised.

    :raise ValueError: if ``fileobj`` is not a :class:`~asynctest.FileMock`,
                       a file-like object or
                       a :class:`~asynctest.FileDescriptor`.
    N)�
isinstancer�fileno�	Exception�
ValueError)�fileobjrrr�fd>s
rcCs2yt|t�pt|��t�Stk
r,dSXdS)zh
    Return ``True`` if the ``obj`` or ``obj.fileno()`` is
    a :class:`asynctest.FileDescriptor`.
    FN)rrr�AttributeError)�objrrr�
isfilemockQs

r"cs(eZdZdZ�fdd�Zdd�Z�ZS)�FileMockz�
    Mock a file-like object.

    A FileMock is an intelligent mock which can work with TestSelector to
    simulate IO events during tests.

    .. method:: fileno()

        Return a :class:`~asynctest.FileDescriptor` object.
    cst�j||�t�|j_dS)N)r�__init__rr�return_value)rrr)rrrr$iszFileMock.__init__cOstjf|�S)N)r�Mock)rrrrrr�_get_child_mocknszFileMock._get_child_mock)rrrrr$r'rrr)rrr#^s
r#cs0eZdZdZdejddddf�fdd�	Z�ZS)�
SocketMockz?
    Mock a socket.

    See :class:`~asynctest.FileMock`.
    Nc	s(t�jtjf||||||d�|��dS)N)�side_effectr%�wraps�name�spec_set�parent)rr$�socket)rr)r%r*r+r,r-r)rrrr$yszSocketMock.__init__)rrrrr�DEFAULTr$rrr)rrr(ssr(c@s(eZdZdZdejddddfdd�ZdS)�
SSLSocketMockz�
        Mock a socket wrapped by the :mod:`ssl` module.

        See :class:`~asynctest.FileMock`.

        .. versionadded:: 0.5
        Nc	Ks(tj|tjf||||||d�|��dS)N)r)r%r*r+r,r-)r#r$�ssl�	SSLSocket)rr)r%r*r+r,r-rrrrr$�szSSLSocketMock.__init__)rrrrrr/r$rrrrr0�sr0cCs4|j}|�|�}||jkr0|�|j||fg�dS)N)�	_selector�_fileobj_lookup�
_fd_to_key�_process_events)r�loop�event�selectorrrrr�_set_event_ready�s

r:cCs|�t||tj�dS)a�
    Schedule callbacks registered on ``loop`` as if the selector notified that
    data is ready to be read on ``fileobj``.

    :param fileobj: file object or :class:`~asynctest.FileMock` on which the
                    event is mocked.

    :param loop: :class:`asyncio.SelectorEventLoop` watching for events on
                 ``fileobj``.

    ::

        mock = asynctest.SocketMock()
        mock.recv.return_value = b"Data"

        def read_ready(sock):
            print("received:", sock.recv(1024))

        loop.add_reader(mock, read_ready, mock)

        set_read_ready(mock, loop)

        loop.run_forever() # prints received: b"Data"

    .. versionadded:: 0.4
    N)�call_soon_threadsafer:�	selectors�
EVENT_READ)rr7rrr�set_read_ready�sr>cCs|�t||tj�dS)a^
    Schedule callbacks registered on ``loop`` as if the selector notified that
    data can be written to ``fileobj``.

    :param fileobj: file object or  :class:`~asynctest.FileMock` on which th
        event is mocked.
    :param loop: :class:`asyncio.SelectorEventLoop` watching for events on
        ``fileobj``.

    .. versionadded:: 0.4
    N)r;r:r<�EVENT_WRITE)rr7rrr�set_write_ready�sr@csleZdZdZd�fdd�	Z�fdd�Zd�fdd�	Z�fd	d
�Zd�fdd�	Zdd
d�Z	�fdd�Z
�ZS)�TestSelectora�
    A selector which supports IOMock objects.

    It can wrap an actual implementation of a selector, so the selector will
    work both with mocks and real file-like objects.

    A common use case is to patch the selector loop::

        loop._selector = asynctest.TestSelector(loop._selector)

    :param selector: optional, if provided, this selector will be used to work
                     with real file-like objects.
    Ncst���||_dS)N)rr$r3)rr9)rrrr$�s
zTestSelector.__init__cst|�rt|�St��|�S)N)r"rrr4)rr)rrrr4�szTestSelector._fileobj_lookupcsHt|�s|jdkr$t��|||�}n |j�|||�}|rD||j|j<|S)a�
        Register a file object or a :class:`~asynctest.FileMock`.

        If a real selector object has been supplied to the
        :class:`~asynctest.TestSelector` object and ``fileobj`` is not
        a :class:`~asynctest.FileMock` or a :class:`~asynctest.FileDescriptor`
        returned by :meth:`FileMock.fileno()`, the object will be registered to
        the real selector.

        See :meth:`selectors.BaseSelector.register`.
        N)r"r3r�registerr5r)rr�events�data�key)rrrrB�szTestSelector.registercsJt|�s|jdkr t��|�}n&|j�|�}|rF|j|jkrF|j|j=|S)z�
        Unregister a file object or a :class:`~asynctest.FileMock`.

        See :meth:`selectors.BaseSelector.unregister`.
        N)r"r3r�
unregisterrr5)rrrE)rrrrF�s
zTestSelector.unregistercsdt|�s|jdkr$t��|||�}n<|�|�}||jkr@|j|=|j�|||�}|r`||j|j<|S)z�
        Shortcut when calling :meth:`TestSelector.unregister` then
        :meth:`TestSelector.register` to update the registration of a an object
        to the selector.

        See :meth:`selectors.BaseSelector.modify`.
        N)r"r3r�modifyr4r5r)rrrCrDrEr)rrrrGs

zTestSelector.modifycCs|jdkrgS|j�|�S)z�
        Perform the selection.

        This method is a no-op if no actual selector has been supplied.

        See :meth:`selectors.BaseSelector.select`.
        N)r3�select)r�timeoutrrrrH s
zTestSelector.selectcs"|jdk	r|j��t���dS)z�
        Close the selector.

        Close the actual selector if supplied, unregister all mocks.

        See :meth:`selectors.BaseSelector.close`.
        N)r3�closer)r)rrrrJ-s

zTestSelector.close)N)N)N)N)rrrrr$r4rBrFrGrHrJrrr)rrrA�s


rAcCsXg}x|����D]}|�|�qW|jdk	rPx |j����D]}|�|�q>Wt|�S)N)�get_map�values�appendr3�set)r9Zwatched_eventsr8rrr�get_registered_events;s
rO�format_helperscCstj�|j|jd�S)N)�asynciorP�_format_callback�	_callback�_args)�handlerrrrRJs
rR�_format_args_and_kwargscCstj�|j|jd�S)N)rQrCrRrSrT)rUrrrrROscCstj�|j|j�S)N)rQrCrRrSrT)rUrrrrRTscCs\g}|jtj@r.|�d�|jt|jd���|jtj@rX|�d�|jt|jd���|S)Nzadd_reader({}, {})rzadd_writer({}, {})r)	rCr<r=rMrrrRrDr?)r8�	callbacksrrr�
_format_eventXsrXcCst|jj�|_dS)N)rOr7r3�_active_selector_callbacks)�caserrr�-fail_on_before_test_active_selector_callbacksfsr[cCsZ|j}t|jj�}dg}x tt||�D]}|�|�q(Wt|�dkrV|�d�	|��dS)Nz6some events watched during the tests were not removed:rz
 - )
rYrOr7r3�maprX�extend�lenZfail�join)rZZignored_eventsZ
active_events�output�crrr�!fail_on_active_selector_callbacksksrbF�active_selector_callbacks)"rrQr<�ImportErrorZasyncio.selectorsr.r1�rr�intrrr"r&r#r(r0r:r>r@�_BaseSelectorImplrArO�hasattrrRrCrXr[rbZDEFAULTS�staticmethodrcZ%before_test_active_selector_callbacksrrrr�<module>sF

!q