Mini Shell

Direktori : /lib64/python3.9/__pycache__/
Upload File :
Current File : //lib64/python3.9/__pycache__/selectors.cpython-39.pyc

a

�DOgPL�@s�dZddlmZmZddlmZddlmZddlZddl	Z	ddl
Z
dZdZdd	�Z
ed
gd��Zde_e
jd
kr�dej_dej_dej_dej_Gdd�de�ZGdd�ded�ZGdd�de�ZGdd�de�ZGdd�de�Zee	d�r�Gdd�de�Zee	d ��rGd!d"�d"e�Zee	d#��r6Gd$d%�d%e�Zee	d&��rRGd'd(�d(e�Zd)d*�Zed&��rjeZn4ed ��rzeZn$ed#��r�eZned��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
Csdt|t�r|}n:zt|���}Wn(tttfyHtd�|��d�Yn0|dkr`td�|���|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�!/usr/lib64/python3.9/selectors.py�_fileobj_to_fds
��r�SelectorKey)rr�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)�self�selectorrrr�__init__@sz_SelectorMapping.__init__cCst|jj�Sr)�lenr�
_fd_to_key�rrrr�__len__Csz_SelectorMapping.__len__cCsBz|j�|�}|jj|WSty<td�|��d�Yn0dS�N�{!r} is not registered)r�_fileobj_lookupr �KeyErrorr)rrrrrr�__getitem__Fs
z_SelectorMapping.__getitem__cCst|jj�Sr)�iterrr r!rrr�__iter__Msz_SelectorMapping.__iter__N)�__name__�
__module__�__qualname__�__doc__rr"r'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)
        Nr/)rrrrr�
unregisterwszBaseSelector.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
        )r3r2r1rrr�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
        Nr/)r�timeoutrrr�select�szBaseSelector.selectcCsdS)zmClose the selector.

        This must be called to make sure that any underlying resource is freed.
        Nrr!rrr�close�szBaseSelector.closecCsJ|��}|durtd��z
||WStyDtd�|��d�Yn0dS)zzReturn the key associated to a registered file object.

        Returns:
        SelectorKey for this file object
        NzSelector is closedr$)�get_map�RuntimeErrorr&r)rr�mappingrrr�get_key�s
zBaseSelector.get_keycCst�dS)z2Return a mapping of file objects to selector keys.Nr/r!rrrr8�szBaseSelector.get_mapcCs|Srrr!rrr�	__enter__�szBaseSelector.__enter__cGs|��dSr)r7)r�argsrrr�__exit__�szBaseSelector.__exit__)N)N)N)r*r+r,r-rr2r3r4r6r7r;r8r<r>rrrrr.Qs


r.)�	metaclassc@sTeZdZdZdd�Zdd�Zddd�Zd	d
�Zddd�Zd
d�Z	dd�Z
dd�ZdS)�_BaseSelectorImplzBase selector implementation.cCsi|_t|�|_dSr)r r�_mapr!rrrr�sz_BaseSelectorImpl.__init__cCsLz
t|�WStyF|j��D]}|j|ur"|jYSq"�Yn0dS)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|jvrRtd�||j���||j|j<|S)NzInvalid events: {!r}z"{!r} (FD {}) is already registered)	�
EVENT_READ�EVENT_WRITEr
rrr%rr r&�rrrrrDrrrr2�s�z_BaseSelectorImpl.registercCs>z|j�|�|��}Wn"ty8td�|��d�Yn0|Sr#)r �popr%r&rrCrrrr3�s
z_BaseSelectorImpl.unregistercCs�z|j|�|�}Wn"ty6td�|��d�Yn0||jkr\|�|�|�|||�}n"||jkr~|j|d�}||j|j	<|S)Nr$)r)
r r%r&rrr3r2r�_replacerrGrrrr4�s


z_BaseSelectorImpl.modifycCs|j��d|_dSr)r �clearrAr!rrrr7
s
z_BaseSelectorImpl.closecCs|jSr)rAr!rrrr8sz_BaseSelectorImpl.get_mapcCs&z|j|WSty YdS0dS)z�Return the key associated to a given file descriptor.

        Parameters:
        fd -- file descriptor

        Returns:
        corresponding key, or None if not found
        N)r r&)rrrrr�_key_from_fds	z_BaseSelectorImpl._key_from_fd)N)N)r*r+r,r-rr%r2r3r4r7r8rKrrrrr@�s


r@cs`eZdZdZ�fdd�Zd�fdd�	Z�fdd�Zejd	krHdd
d�Z	ne
j
Z	ddd
�Z
�ZS)�SelectSelectorzSelect-based selector.cst���t�|_t�|_dSr)�superr�set�_readers�_writersr!��	__class__rrr&s
zSelectSelector.__init__Ncs@t��|||�}|t@r&|j�|j�|t@r<|j�|j�|Sr)rMr2rErO�addrrFrPrGrQrrr2+szSelectSelector.registercs,t��|�}|j�|j�|j�|j�|Sr)rMr3rO�discardrrPrCrQrrr33szSelectSelector.unregister�win32cCs$t�||||�\}}}|||gfSr)r6)r�r�w�_r5�xrrr�_select:szSelectSelector._selectc	Cs�|durdnt|d�}g}z|�|j|jg|�\}}}WntyN|YS0t|�}t|�}||BD]J}d}||vr�|tO}||vr�|tO}|�|�}|rh|�	|||j
@f�qh|S�Nr)�maxrZrOrP�InterruptedErrorrNrErFrK�appendr)	rr5�readyrVrWrXrrrDrrrr6@s$

zSelectSelector.select)N)N)N)r*r+r,r-rr2r3�sys�platformrZr6�
__classcell__rrrQrrL#s
rLcs^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���|��|_dSr)rMr�
_selector_clsrr!rQrrr\s
z_PollLikeSelector.__init__cslt��|||�}d}|t@r&||jO}|t@r8||jO}z|j�|j|�Wnt��|��Yn0|Sr[)	rMr2rE�_EVENT_READrF�_EVENT_WRITErrr3)rrrrrD�
poller_eventsrQrrr2`s

z_PollLikeSelector.registercs6t��|�}z|j�|j�Wnty0Yn0|Sr)rMr3rr�OSErrorrCrQrrr3nsz_PollLikeSelector.unregistercs�z|j|�|�}Wn"ty6t|�d��d�Yn0d}||jkr�d}|t@r\||jO}|t@rn||jO}z|j�	|j
|�Wnt��|��Yn0d}||j
kr�d}|r�|j||d�}||j|j
<|S)Nz is not registeredFrT)rr)r r%r&rrErerFrfrr4rrMr3rrI)rrrrrD�changed�selector_eventsrQrrr4xs.



z_PollLikeSelector.modifycCs�|durd}n|dkrd}nt�|d�}g}z|j�|�}WntyT|YS0|D]V\}}d}||j@rz|tO}||j@r�|tO}|�	|�}|rZ|�
|||j@f�qZ|S)Nr�@�@)�math�ceilr�pollr]rerFrfrErKr^r)rr5r_�
fd_event_listr�eventrrDrrrr6�s(

z_PollLikeSelector.select)N)N)N)
r*r+r,r-rdrerfrr2r3r4r6rbrrrQrrcVs
rcrnc@s"eZdZdZejZejZej	Z
dS)�PollSelectorzPoll-based selector.N)r*r+r,r-r6rnrd�POLLINre�POLLOUTrfrrrrrq�srq�epollcsDeZdZdZejZejZej	Z
dd�Zd	dd�Z�fdd�Z�Z
S)
�
EpollSelectorzEpoll-based selector.cCs
|j��Sr�rr
r!rrrr
�szEpollSelector.filenoNc	Cs�|durd}n |dkrd}nt�|d�d}tt|j�d�}g}z|j�||�}Wntyj|YS0|D]V\}}d}|tj	@r�|t
O}|tj@r�|tO}|�
|�}|rp|�|||j@f�qp|S)N���rrkg����MbP?r)rlrmr\rr rrnr]r6�EPOLLINrF�EPOLLOUTrErKr^r)	rr5�max_evr_rorrprrDrrrr6�s*

zEpollSelector.selectcs|j��t���dSr�rr7rMr!rQrrr7�s
zEpollSelector.close)N)r*r+r,r-r6rtrdrxreryrfr
r7rbrrrQrru�s
 ru�devpollcs:eZdZdZejZejZej	Z
dd�Z�fdd�Z�Z
S)�DevpollSelectorzSolaris /dev/poll selector.cCs
|j��Srrvr!rrrr
�szDevpollSelector.filenocs|j��t���dSrr{r!rQrrr7�s
zDevpollSelector.close)r*r+r,r-r6r|rdrrrersrfr
r7rbrrrQrr}�sr}�kqueuecsXeZdZdZ�fdd�Zdd�Zd�fdd�	Z�fd	d
�Zddd�Z�fd
d�Z	�Z
S)�KqueueSelectorzKqueue-based selector.cst���t��|_dSr)rMrr6r~rr!rQrrr�s
zKqueueSelector.__init__cCs
|j��Srrvr!rrrr
szKqueueSelector.filenoNcs�t��|||�}z`|t@r@t�|jtjtj�}|j�	|gdd�|t
@rnt�|jtjtj�}|j�	|gdd�Wnt��|��Yn0|Sr[)
rMr2rEr6�keventr�KQ_FILTER_READZ	KQ_EV_ADDr�controlrF�KQ_FILTER_WRITEr3)rrrrrD�kevrQrrr2s ��zKqueueSelector.registercs�t��|�}|jt@rTt�|jtjtj�}z|j	�
|gdd�WntyRYn0|jt@r�t�|jtj
tj�}z|j	�
|gdd�Wnty�Yn0|Sr[)rMr3rrEr6r�rr�ZKQ_EV_DELETErr�rhrFr�)rrrDr�rQrrr3s$
�
�zKqueueSelector.unregisterc
Cs�|durdnt|d�}tt|j�d�}g}z|j�d||�}WntyT|YS0|D]Z}|j}|j}d}|tj	kr�|t
O}|tjkr�|tO}|�
|�}	|	rZ|�|	||	j@f�qZ|S)Nrr)r\rr rr�r]�ident�filterr6r�rEr�rFrKr^r)
rr5rzr_Zkev_listr�r�flagrrDrrrr6*s&



zKqueueSelector.selectcs|j��t���dSrr{r!rQrrr7Cs
zKqueueSelector.close)N)N)r*r+r,r-rr
r2r3r6r7rbrrrQrr�s
rcCsZtt|d�}|durdSz(|�}|dkr4|�d�n|��WdStyTYdS0dS)zJCheck if we can use the selector depending upon the
    operating system. NFrnrT)�getattrr6rnr7rh)�methodr�selector_objrrr�_can_useHsr�) r-�abcrr�collectionsr�collections.abcrrlr6r`rErFrr�version_inforrrrrr.r@rLrc�hasattrrqrur}rr��DefaultSelectorrrrr�<module>sN
~T3Z
.M





Zerion Mini Shell 1.0