ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python37/lib64/python3.7/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python37/lib64/python3.7/__pycache__/selectors.cpython-37.pyc

B

� f�H�@s�dZddlmZmZddlmZddlmZddlZddl	Z	ddl
Z
dZdZdd	�Z
ed
ddd
dg�Zde_e
jdkr�dej_dej_dej_dej_Gdd�de�ZGdd�ded�ZGdd�de�ZGdd�de�ZGdd�de�Zee	d ��rGd!d"�d"e�Zee	d#��r Gd$d%�d%e�Zee	d&��r<Gd'd(�d(e�Zee	d)��rXGd*d+�d+e�Zd+e�k�rjeZn:d%e�k�r|eZn(d(e�k�r�eZnd"e�k�r�eZneZdS),z|Selectors module.

This module allows high-level and efficient I/O multiplexing, built upon the
`select` module primitives.
�)�ABCMeta�abstractmethod)�
namedtuple)�MappingN��c
Csft|t�r|}n<yt|���}Wn*tttfk
rJtd�|��d�YnX|dkrbtd�|���|S)z�Return a file descriptor from a file object.

    Parameters:
    fileobj -- file object or file descriptor

    Returns:
    corresponding file descriptor

    Raises:
    ValueError if the object is invalid
    zInvalid file object: {!r}NrzInvalid file descriptor: {})�
isinstance�int�fileno�AttributeError�	TypeError�
ValueError�format)�fileobj�fd�r�./opt/alt/python37/lib64/python3.7/selectors.py�_fileobj_to_fds
r�SelectorKeyrr�events�dataz�SelectorKey(fileobj, fd, events, data)

    Object used to associate a file object to its backing
    file descriptor, selected event mask, and attached data.
)��zFile object registered.zUnderlying file descriptor.z3Events that must be waited for on this file object.zzOptional opaque data associated to this file object.
    For example, this could be used to store a per-client session ID.c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_SelectorMappingz)Mapping of file objects to selector keys.cCs
||_dS)N)�	_selector)�selfZselectorrrr�__init__?sz_SelectorMapping.__init__cCst|jj�S)N)�lenr�
_fd_to_key)rrrr�__len__Bsz_SelectorMapping.__len__cCsBy|j�|�}|jj|Stk
r<td�|��d�YnXdS)Nz{!r} is not registered)r�_fileobj_lookupr�KeyErrorr)rrrrrr�__getitem__Es
z_SelectorMapping.__getitem__cCst|jj�S)N)�iterrr)rrrr�__iter__Lsz_SelectorMapping.__iter__N)�__name__�
__module__�__qualname__�__doc__rrr"r$rrrrr<s
rc@sneZdZdZeddd��Zedd��Zddd�Zedd	d
��Zdd�Z	d
d�Z
edd��Zdd�Zdd�Z
dS)�BaseSelectora-Selector abstract base class.

    A selector supports registering file objects to be monitored for specific
    I/O events.

    A file object is a file descriptor or any object with a `fileno()` method.
    An arbitrary object can be attached to the file object, which can be used
    for example to store context information, a callback, etc.

    A selector can use various implementations (select(), poll(), epoll()...)
    depending on the platform. The default `Selector` class uses the most
    efficient implementation on the current platform.
    NcCst�dS)a3Register a file object.

        Parameters:
        fileobj -- file object or file descriptor
        events  -- events to monitor (bitwise mask of EVENT_READ|EVENT_WRITE)
        data    -- attached data

        Returns:
        SelectorKey instance

        Raises:
        ValueError if events is invalid
        KeyError if fileobj is already registered
        OSError if fileobj is closed or otherwise is unacceptable to
                the underlying system call (if a system call is made)

        Note:
        OSError may or may not be raised
        N)�NotImplementedError)rrrrrrr�register_szBaseSelector.registercCst�dS)ajUnregister a file object.

        Parameters:
        fileobj -- file object or file descriptor

        Returns:
        SelectorKey instance

        Raises:
        KeyError if fileobj is not registered

        Note:
        If fileobj is registered but has since been closed this does
        *not* raise OSError (even if the wrapped syscall does)
        N)r*)rrrrr�
unregistervszBaseSelector.unregistercCs|�|�|�|||�S)ayChange a registered file object monitored events or attached data.

        Parameters:
        fileobj -- file object or file descriptor
        events  -- events to monitor (bitwise mask of EVENT_READ|EVENT_WRITE)
        data    -- attached data

        Returns:
        SelectorKey instance

        Raises:
        Anything that unregister() or register() raises
        )r,r+)rrrrrrr�modify�s
zBaseSelector.modifycCst�dS)aqPerform the actual selection, until some monitored file objects are
        ready or a timeout expires.

        Parameters:
        timeout -- if timeout > 0, this specifies the maximum wait time, in
                   seconds
                   if timeout <= 0, the select() call won't block, and will
                   report the currently ready file objects
                   if timeout is None, select() will block until a monitored
                   file object becomes ready

        Returns:
        list of (key, events) for ready file objects
        `events` is a bitwise mask of EVENT_READ|EVENT_WRITE
        N)r*)r�timeoutrrr�select�szBaseSelector.selectcCsdS)zmClose the selector.

        This must be called to make sure that any underlying resource is freed.
        Nr)rrrr�close�szBaseSelector.closecCsJ|��}|dkrtd��y||Stk
rDtd�|��d�YnXdS)zzReturn the key associated to a registered file object.

        Returns:
        SelectorKey for this file object
        NzSelector is closedz{!r} is not registered)�get_map�RuntimeErrorr!r)rr�mappingrrr�get_key�szBaseSelector.get_keycCst�dS)z2Return a mapping of file objects to selector keys.N)r*)rrrrr1�szBaseSelector.get_mapcCs|S)Nr)rrrr�	__enter__�szBaseSelector.__enter__cGs|��dS)N)r0)r�argsrrr�__exit__�szBaseSelector.__exit__)N)N)N)r%r&r'r(rr+r,r-r/r0r4r1r5r7rrrrr)Ps

r))�	metaclassc@sTeZdZdZdd�Zdd�Zddd�Zd	d
�Zddd�Zd
d�Z	dd�Z
dd�ZdS)�_BaseSelectorImplzBase selector implementation.cCsi|_t|�|_dS)N)rr�_map)rrrrr�sz_BaseSelectorImpl.__init__cCsHyt|�Stk
rBx"|j��D]}|j|kr$|jSq$W�YnXdS)alReturn a file descriptor from a file object.

        This wraps _fileobj_to_fd() to do an exhaustive search in case
        the object is invalid but we still have it in our map.  This
        is used by unregister() so we can unregister an object that
        was previously registered even if it is closed.  It is also
        used by _SelectorMapping.
        N)rr
r�valuesrr)rr�keyrrrr �s	

z!_BaseSelectorImpl._fileobj_lookupNcCsb|r|ttB@r td�|���t||�|�||�}|j|jkrRtd�||j���||j|j<|S)NzInvalid events: {!r}z"{!r} (FD {}) is already registered)	�
EVENT_READ�EVENT_WRITEr
rrr rrr!)rrrrr<rrrr+�sz_BaseSelectorImpl.registercCs@y|j�|�|��}Wn$tk
r:td�|��d�YnX|S)Nz{!r} is not registered)r�popr r!r)rrr<rrrr,�s
z_BaseSelectorImpl.unregistercCs�y|j|�|�}Wn$tk
r8td�|��d�YnX||jkr^|�|�|�|||�}n"||jkr�|j|d�}||j|j	<|S)Nz{!r} is not registered)r)
rr r!rrr,r+r�_replacer)rrrrr<rrrr-�s


z_BaseSelectorImpl.modifycCs|j��d|_dS)N)r�clearr:)rrrrr0s
z_BaseSelectorImpl.closecCs|jS)N)r:)rrrrr1sz_BaseSelectorImpl.get_mapcCs$y
|j|Stk
rdSXdS)z�Return the key associated to a given file descriptor.

        Parameters:
        fd -- file descriptor

        Returns:
        corresponding key, or None if not found
        N)rr!)rrrrr�_key_from_fds	
z_BaseSelectorImpl._key_from_fd)N)N)r%r&r'r(rr r+r,r-r0r1rBrrrrr9�s


r9cs`eZdZdZ�fdd�Zd�fdd�	Z�fdd�Zejd	krHdd
d�Z	ne
j
Z	ddd
�Z
�ZS)�SelectSelectorzSelect-based selector.cst���t�|_t�|_dS)N)�superr�set�_readers�_writers)r)�	__class__rrr%s
zSelectSelector.__init__Ncs@t��|||�}|t@r&|j�|j�|t@r<|j�|j�|S)N)rDr+r=rF�addrr>rG)rrrrr<)rHrrr+*szSelectSelector.registercs,t��|�}|j�|j�|j�|j�|S)N)rDr,rF�discardrrG)rrr<)rHrrr,2szSelectSelector.unregisterZwin32cCs$t�||||�\}}}|||gfS)N)r/)r�r�w�_r.�xrrr�_select9szSelectSelector._selectc	Cs�|dkrdnt|d�}g}y|�|j|jg|�\}}}Wntk
rL|SXt|�}t|�}xV||BD]J}d}||kr�|tO}||kr�|tO}|�|�}|rh|�	|||j
@f�qhW|S)Nr)�maxrOrFrG�InterruptedErrorrEr=r>rB�appendr)	rr.�readyrKrLrMrrr<rrrr/?s$
zSelectSelector.select)N)N)N)r%r&r'r(rr+r,�sys�platformrOr/�
__classcell__rr)rHrrC"s
rCcs^eZdZdZdZdZdZ�fdd�Zd
�fdd�	Z�fdd�Z	d�fd	d
�	Z
ddd�Z�ZS)�_PollLikeSelectorz<Base class shared between poll, epoll and devpoll selectors.Ncst���|��|_dS)N)rDr�
_selector_clsr)r)rHrrr[s
z_PollLikeSelector.__init__cslt��|||�}d}|t@r&||jO}|t@r8||jO}y|j�|j|�Wnt��|��YnX|S)Nr)	rDr+r=�_EVENT_READr>�_EVENT_WRITErrr,)rrrrr<Z
poller_events)rHrrr+_s

z_PollLikeSelector.registercs8t��|�}y|j�|j�Wntk
r2YnX|S)N)rDr,rr�OSError)rrr<)rHrrr,msz_PollLikeSelector.unregistercs�y|j|�|�}Wn$tk
r8t|�d��d�YnXd}||jkr�d}|t@r^||jO}|t@rp||jO}y|j�	|j
|�Wnt��|��YnXd}||j
kr�d}|r�|j||d�}||j|j
<|S)Nz is not registeredFrT)rr)rr r!rr=rYr>rZrr-rrDr,rr@)rrrrr<ZchangedZselector_events)rHrrr-ws.



z_PollLikeSelector.modifycCs�|dkrd}n|dkrd}nt�|d�}g}y|j�|�}Wntk
rR|SXx^|D]V\}}d}||j@rz|tO}||j@r�|tO}|�	|�}|rZ|�
|||j@f�qZW|S)Nrg@�@)�math�ceilr�pollrQrYr>rZr=rBrRr)rr.rS�
fd_event_listr�eventrr<rrrr/�s(
z_PollLikeSelector.select)N)N)N)
r%r&r'r(rXrYrZrr+r,r-r/rVrr)rHrrWUs
rWr^c@s"eZdZdZejZejZej	Z
dS)�PollSelectorzPoll-based selector.N)r%r&r'r(r/r^rX�POLLINrY�POLLOUTrZrrrrra�sra�epollcsDeZdZdZejZejZej	Z
dd�Zd	dd�Z�fdd�Z�Z
S)
�
EpollSelectorzEpoll-based selector.cCs
|j��S)N)rr
)rrrrr
�szEpollSelector.filenoNc	Cs�|dkrd}n |dkrd}nt�|d�d}tt|j�d�}g}y|j�||�}Wntk
rh|SXx^|D]V\}}d}|tj	@r�|t
O}|tj@r�|tO}|�
|�}|rp|�|||j@f�qpW|S)N���rg@�@g����MbP?r)r\r]rPrrrr^rQr/�EPOLLINr>�EPOLLOUTr=rBrRr)	rr.�max_evrSr_rr`rr<rrrr/�s*
zEpollSelector.selectcs|j��t���dS)N)rr0rD)r)rHrrr0�s
zEpollSelector.close)N)r%r&r'r(r/rdrXrgrYrhrZr
r0rVrr)rHrre�s
 re�devpollcs:eZdZdZejZejZej	Z
dd�Z�fdd�Z�Z
S)�DevpollSelectorzSolaris /dev/poll selector.cCs
|j��S)N)rr
)rrrrr
�szDevpollSelector.filenocs|j��t���dS)N)rr0rD)r)rHrrr0�s
zDevpollSelector.close)r%r&r'r(r/rjrXrbrYrcrZr
r0rVrr)rHrrk�srk�kqueuecsXeZdZdZ�fdd�Zdd�Zd�fdd�	Z�fd	d
�Zddd�Z�fd
d�Z	�Z
S)�KqueueSelectorzKqueue-based selector.cst���t��|_dS)N)rDrr/rlr)r)rHrrr�s
zKqueueSelector.__init__cCs
|j��S)N)rr
)rrrrr
szKqueueSelector.filenoNcs�t��|||�}y`|t@r@t�|jtjtj�}|j�	|gdd�|t
@rnt�|jtjtj�}|j�	|gdd�Wnt��|��YnX|S)Nr)
rDr+r=r/�keventr�KQ_FILTER_READZ	KQ_EV_ADDr�controlr>�KQ_FILTER_WRITEr,)rrrrr<�kev)rHrrr+szKqueueSelector.registercs�t��|�}|jt@rVt�|jtjtj�}y|j	�
|gdd�Wntk
rTYnX|jt@r�t�|jtj
tj�}y|j	�
|gdd�Wntk
r�YnX|S)Nr)rDr,rr=r/rnrroZKQ_EV_DELETErrpr[r>rq)rrr<rr)rHrrr,s 

zKqueueSelector.unregisterc
Cs�|dkrdnt|d�}t|j�}g}y|j�d||�}Wntk
rL|SXxb|D]Z}|j}|j}d}|tj	krz|t
O}|tjkr�|tO}|�
|�}	|	rT|�|	||	j@f�qTW|S)Nr)rPrrrrprQZident�filterr/ror=rqr>rBrRr)
rr.rirSZkev_listrrr�flagrr<rrrr/)s&




zKqueueSelector.selectcs|j��t���dS)N)rr0rD)r)rHrrr0?s
zKqueueSelector.close)N)N)r%r&r'r(rr
r+r,r/r0rVrr)rHrrm�s
rm) r(�abcrr�collectionsrZcollections.abcrr\r/rTr=r>rr�version_inforrrrrr)r9rCrW�hasattrrarerkrm�globalsZDefaultSelectorrrrr�<module>sL
~T3Z.M

Zerion Mini Shell 1.0