AlkantarClanX12

Your IP : 3.142.40.195


Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/selectors.cpython-35.pyc



��Yf�K�@s*dZddlmZmZddlmZmZddlZddlZddl	Z	d)Z
d*Zdd�Zedd	d
ddg�Z
d
e
_e	jd+kr�de
j_de
j_de
j_de
j_Gdd�de�ZGdd�dde�ZGdd�de�ZGdd�de�Zeed�rQGdd�de�Zeed �rvGd!d"�d"e�Zeed#�r�Gd$d%�d%e�Zeed&�r�Gd'd(�d(e�Zd(e�kr�eZnNd"e�kr�eZn6d%e�kreZnde�kr 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
Cs�t|t�r|}nLyt|j��}Wn3tttfk
rctdj|��d�YnX|dkr�tdj|���|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/python35/lib64/python3.5/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@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_SelectorMappingz)Mapping of file objects to selector keys.cCs
||_dS)N)�	_selector)�selfZselectorrrr�__init__>sz_SelectorMapping.__init__cCst|jj�S)N)�lenr�
_fd_to_key)rrrr�__len__Asz_SelectorMapping.__len__cCsUy$|jj|�}|jj|SWn*tk
rPtdj|��d�YnXdS)Nz{!r} is not registered)r�_fileobj_lookupr�KeyErrorr
)rrrrrr�__getitem__Ds

z_SelectorMapping.__getitem__cCst|jj�S)N)�iterrr)rrrr�__iter__Ksz_SelectorMapping.__iter__N)�__name__�
__module__�__qualname__�__doc__rrr!r#rrrrr;s
rc@s�eZdZdZeddd��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.
    NcCs
t�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.registercCs
t�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�
unregisteruszBaseSelector.unregistercCs |j|�|j|||�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.modifycCs
t�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.closecCsa|j�}|dkr$td��y||SWn*tk
r\tdj|��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�s
zBaseSelector.get_keycCs
t�dS)z2Return a mapping of file objects to selector keys.N)r))rrrrr0�szBaseSelector.get_mapcCs|S)Nr)rrrr�	__enter__�szBaseSelector.__enter__cGs|j�dS)N)r/)r�argsrrr�__exit__�szBaseSelector.__exit__)r$r%r&r'rr*r+r,r.r/r3r0r4r6rrrrr(Os
r(�	metaclassc@s|eZdZdZdd�Zdd�Zddd�Zd	d
�Zddd�Zd
d�Z	dd�Z
dd�ZdS)�_BaseSelectorImplzBase selector implementation.cCsi|_t|�|_dS)N)rr�_map)rrrrr�s	z_BaseSelectorImpl.__init__cCsZyt|�SWnEtk
rUx-|jj�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_lookupNcCs�|s|ttB@r+tdj|���t||j|�||�}|j|jkrvtdj||j���||j|j<|S)NzInvalid events: {!r}z"{!r} (FD {}) is already registered)	�
EVENT_READ�EVENT_WRITErr
rrrrr )rrrrr;rrrr*�s	z_BaseSelectorImpl.registercCsPy|jj|j|��}Wn*tk
rKtdj|��d�YnX|S)Nz{!r} is not registered)r�poprr r
)rrr;rrrr+�s

z_BaseSelectorImpl.unregistercCs�y|j|j|�}Wn*tk
rFtdj|��d�YnX||jkr{|j|�|j|||�}n1||jkr�|jd|�}||j|j	<|S)Nz{!r} is not registeredr)
rrr r
rr+r*r�_replacer)rrrrr;rrrr,�s

z_BaseSelectorImpl.modifycCs|jj�d|_dS)N)r�clearr9)rrrrr/s
z_BaseSelectorImpl.closecCs|jS)N)r9)rrrrr0sz_BaseSelectorImpl.get_mapcCs,y|j|SWntk
r'dSYnXdS)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)r$r%r&r'rrr*r+r,r/r0rArrrrr8�s
r8cs�eZdZdZ�fdd�Zd�fdd�Z�fdd�Zejd	krldd
d�Z	n	e
j
Z	ddd
�Z
�S)�SelectSelectorzSelect-based selector.cs)t�j�t�|_t�|_dS)N)�superr�set�_readers�_writers)r)�	__class__rrr%s
zSelectSelector.__init__NcsVt�j|||�}|t@r5|jj|j�|t@rR|jj|j�|S)N)rCr*r<rE�addrr=rF)rrrrr;)rGrrr**s

zSelectSelector.registercs<t�j|�}|jj|j�|jj|j�|S)N)rCr+rE�discardrrF)rrr;)rGrrr+2szSelectSelector.unregister�win32cCs2tj||||�\}}}|||gfS)N)r.)r�r�w�_r-�xrrr�_select9s!zSelectSelector._selectc	
Cs�|dkrdnt|d�}g}y+|j|j|jg|�\}}}Wntk
rj|SYnXt|�}t|�}xs||BD]g}d}||kr�|tO}||kr�|tO}|j|�}|r�|j	|||j
@f�q�W|S)Nr)�maxrOrErF�InterruptedErrorrDr<r=rA�appendr)	rr-�readyrKrLrMrrr;rrrr.?s$!+
	

zSelectSelector.select)r$r%r&r'rr*r+�sys�platformrOr.rr)rGrrB"s	rB�pollcs^eZdZdZ�fdd�Zd�fdd�Z�fdd�Zdd	d
�Z�S)�PollSelectorzPoll-based selector.cs t�j�tj�|_dS)N)rCrr.rV�_poll)r)rGrrrZs
zPollSelector.__init__Ncsft�j|||�}d}|t@r5|tjO}|t@rL|tjO}|jj|j|�|S)Nr)	rCr*r<r.�POLLINr=�POLLOUTrXr)rrrrr;�poll_events)rGrrr*^s



zPollSelector.registercs)t�j|�}|jj|j�|S)N)rCr+rXr)rrr;)rGrrr+hszPollSelector.unregisterc
Cs�|dkrd}n(|dkr*d}ntj|d�}g}y|jj|�}Wntk
rq|SYnXxy|D]q\}}d}|tj@r�|tO}|tj@r�|t	O}|j
|�}|ry|j|||j@f�qyW|S)Nrg@�@)
�math�ceilrXrVrQr.rYr=rZr<rArRr)rr-rS�
fd_event_listr�eventrr;rrrr.ms(		
	

zPollSelector.select)r$r%r&r'rr*r+r.rr)rGrrWWs

rW�epollcs|eZdZdZ�fdd�Zdd�Zd�fdd�Z�fd	d
�Zddd�Z�fd
d�Z	�S)�
EpollSelectorzEpoll-based selector.cs t�j�tj�|_dS)N)rCrr.r`�_epoll)r)rGrrr�s
zEpollSelector.__init__cCs
|jj�S)N)rbr	)rrrrr	�szEpollSelector.filenoNcs�t�j|||�}d}|t@r5|tjO}|t@rL|tjO}y|jj|j|�Wn%t	k
r�t�j
|��YnX|S)Nr)rCr*r<r.�EPOLLINr=�EPOLLOUTrbr�
BaseExceptionr+)rrrrr;Zepoll_events)rGrrr*�s




zEpollSelector.registercsBt�j|�}y|jj|j�Wntk
r=YnX|S)N)rCr+rbr�OSError)rrr;)rGrrr+�s
zEpollSelector.unregisterc	
Cs|dkrd}n,|dkr*d}ntj|d�d}tt|j�d�}g}y|jj||�}Wntk
r�|SYnXxy|D]q\}}d}|tj	@r�|t
O}|tj@r�|tO}|j
|�}|r�|j|||j@f�q�W|S)Nrrg@�@g����MbP?���)r\r]rPrrrbrVrQr.rcr=rdr<rArRr)	rr-�max_evrSr^rr_rr;rrrr.�s*		
	

zEpollSelector.selectcs|jj�t�j�dS)N)rbr/rC)r)rGrrr/�s
zEpollSelector.close)
r$r%r&r'rr	r*r+r.r/rr)rGrra�s
 ra�devpollcs|eZdZdZ�fdd�Zdd�Zd�fdd�Z�fd	d
�Zddd�Z�fd
d�Z	�S)�DevpollSelectorzSolaris /dev/poll selector.cs t�j�tj�|_dS)N)rCrr.ri�_devpoll)r)rGrrr�s
zDevpollSelector.__init__cCs
|jj�S)N)rkr	)rrrrr	�szDevpollSelector.filenoNcsft�j|||�}d}|t@r5|tjO}|t@rL|tjO}|jj|j|�|S)Nr)	rCr*r<r.rYr=rZrkr)rrrrr;r[)rGrrr*�s



zDevpollSelector.registercs)t�j|�}|jj|j�|S)N)rCr+rkr)rrr;)rGrrr+�szDevpollSelector.unregisterc
Cs�|dkrd}n(|dkr*d}ntj|d�}g}y|jj|�}Wntk
rq|SYnXxy|D]q\}}d}|tj@r�|tO}|tj@r�|t	O}|j
|�}|ry|j|||j@f�qyW|S)Nrg@�@)
r\r]rkrVrQr.rYr=rZr<rArRr)rr-rSr^rr_rr;rrrr.�s(		
	

zDevpollSelector.selectcs|jj�t�j�dS)N)rkr/rC)r)rGrrr/s
zDevpollSelector.close)
r$r%r&r'rr	r*r+r.r/rr)rGrrj�s
rj�kqueuecs|eZdZdZ�fdd�Zdd�Zd�fdd�Z�fd	d
�Zddd�Z�fd
d�Z	�S)�KqueueSelectorzKqueue-based selector.cs t�j�tj�|_dS)N)rCrr.rl�_kqueue)r)rGrrrs
zKqueueSelector.__init__cCs
|jj�S)N)rnr	)rrrrr	szKqueueSelector.filenoNcs�t�j|||�}y�|t@r\tj|jtjtj�}|jj	|gdd�|t
@r�tj|jtjtj�}|jj	|gdd�Wn%tk
r�t�j
|��YnX|S)Nr)rCr*r<r.�keventr�KQ_FILTER_READZ	KQ_EV_ADDrn�controlr=�KQ_FILTER_WRITErer+)rrrrr;�kev)rGrrr*s


zKqueueSelector.registercs�t�j|�}|jt@rotj|jtjtj�}y|j	j
|gdd�Wntk
rnYnX|jt@r�tj|jtj
tj�}y|j	j
|gdd�Wntk
r�YnX|S)Nr)rCr+rr<r.rorrpZKQ_EV_DELETErnrqrfr=rr)rrr;rs)rGrrr+'s 



zKqueueSelector.unregisterc

Cs�|dkrdnt|d�}t|j�}g}y|jjd||�}Wntk
rj|SYnXx�|D]}|j}|j}d}|tj	kr�|t
O}|tjkr�|tO}|j
|�}	|	rr|j|	||	j@f�qrW|S)Nr)rPrrrnrqrQZident�filterr.rpr<rrr=rArRr)
rr-rhrSZkev_listrsrZflagrr;rrrr.<s&!
	
		

zKqueueSelector.selectcs|jj�t�j�dS)N)rnr/rC)r)rGrrr/Rs
zKqueueSelector.close)
r$r%r&r'rr	r*r+r.r/rr)rGrrm
srmr�)rr)r'�abcrr�collectionsrrr\r.rTr<r=rr�version_inforrrrrr(r8rB�hasattrrWrarjrm�globalsZDefaultSelectorrrrr�<module>sH	~U31G8M