Your IP : 3.129.216.248


Current Path : /opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/__pycache__/selectors.cpython-34.pyo

�
e f�B�@s�dZddlmZmZddlmZmZddlZddlZddl	Z	dZ
d Zdd�Zedd	d
ddg�Z
Gd
d�de�ZGdd�dde�ZGdd�de�ZGdd�de�Zeed�rGdd�de�Zneed�r4Gdd�de�Zneed�r\Gdd�de�Znde�krteZn6de�kr�eZnde�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|���n|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/python34/lib64/python3.4/selectors.py�_fileobj_to_fds		r�SelectorKeyrr�events�datac@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_SelectorMappingz)Mapping of file objects to selector keys.cCs
||_dS)N)�	_selector)�selfZselectorrrr�__init__5sz_SelectorMapping.__init__cCst|jj�S)N)�lenr�
_fd_to_key)rrrr�__len__8sz_SelectorMapping.__len__cCsUy$|jj|�}|jj|SWn*tk
rPtdj|��d�YnXdS)Nz{!r} is not registered)r�_fileobj_lookupr�KeyErrorr
)rrrrrr�__getitem__;s

z_SelectorMapping.__getitem__cCst|jj�S)N)�iterrr)rrrr�__iter__Bsz_SelectorMapping.__iter__N)�__name__�
__module__�__qualname__�__doc__rrrr!rrrrr2s
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�registerUszBaseSelector.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�
unregisterlszBaseSelector.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�modifys
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.closecCs^|j�}y!|dkr$t�n||SWn*tk
rYtdj|��d�YnXdS)zzReturn the key associated to a registered file object.

        Returns:
        SelectorKey for this file object
        Nz{!r} is not registered)�get_maprr
)rr�mappingrrr�get_key�s	
zBaseSelector.get_keycCs
t�dS)z2Return a mapping of file objects to selector keys.N)r')rrrrr.�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-r0r.r1r3rrrrr&Fs
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|���nt||j|�||�}|j|jkr|tdj||j���n||j|j<|S)NzInvalid events: {!r}z"{!r} (FD {}) is already registered)	�
EVENT_READ�EVENT_WRITErr
rrrrr)rrrrr8rrrr(�s	z_BaseSelectorImpl.registercCsPy|jj|j|��}Wn*tk
rKtdj|��d�YnX|S)Nz{!r} is not registered)r�poprrr
)rrr8rrrr)�s

z_BaseSelectorImpl.unregistercCs�y|j|j|�}Wn*tk
rFtdj|��d�YnX||jkr{|j|�|j|||�}n4||jkr�|jd|�}||j|j	<n|S)Nz{!r} is not registeredr)
rrrr
rr)r(r�_replacer)rrrrr8rrrr*�s

z_BaseSelectorImpl.modifycCs|jj�d|_dS)N)r�clearr6)rrrrr-s
z_BaseSelectorImpl.closecCs|jS)N)r6)rrrrr.sz_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_fd
s	
z_BaseSelectorImpl._key_from_fd)r"r#r$r%rrr(r)r*r-r.r>rrrrr5�s
r5cs�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__rrrs
zSelectSelector.__init__Ncs\t�j|||�}|t@r8|jj|j�n|t@rX|jj|j�n|S)N)r@r(r9rB�addrr:rC)rrrrr8)rDrrr(!s

zSelectSelector.registercs<t�j|�}|jj|j�|jj|j�|S)N)r@r)rB�discardrrC)rrr8)rDrrr))szSelectSelector.unregister�win32cCs2tj||||�\}}}|||gfS)N)r,)r�r�w�_r+�xrrr�_select0s!zSelectSelector._selectc	
Cs|dkrdnt|d�}g}y+|j|j|jg|�\}}}Wntk
rj|SYnXt|�}t|�}x|||BD]p}d}||kr�|tO}n||kr�|tO}n|j|�}|r�|j	|||j
@f�q�q�W|S)Nr)�maxrLrBrC�InterruptedErrorrAr9r:r>�appendr)	rr+�readyrHrIrJrrr8rrrr,6s$!+
	

!zSelectSelector.select)r"r#r$r%rr(r)�sys�platformrLr,rr)rDrr?s	r?�pollcs^eZdZdZ�fdd�Zd�fdd�Z�fdd�Zdd	d
�Z�S)�PollSelectorzPoll-based selector.cs t�j�tj�|_dS)N)r@rr,rS�_poll)r)rDrrrQs
zPollSelector.__init__Ncslt�j|||�}d}|t@r8|tjO}n|t@rR|tjO}n|jj|j|�|S)Nr)	r@r(r9r,�POLLINr:�POLLOUTrUr)rrrrr8Zpoll_events)rDrrr(Us

zPollSelector.registercs)t�j|�}|jj|j�|S)N)r@r)rUr)rrr8)rDrrr)_szPollSelector.unregisterc
Cs�|dkrd}n(|dkr*d}ntj|d�}g}y|jj|�}Wntk
rq|SYnXx�|D]z\}}d}|tj@r�|tO}n|tj@r�|t	O}n|j
|�}|ry|j|||j@f�qyqyW|S)Nrg@�@)
�math�ceilrUrSrNr,rVr:rWr9r>rOr)rr+rP�
fd_event_listr�eventrr8rrrr,ds(		
	

!zPollSelector.select)r"r#r$r%rr(r)r,rr)rDrrTNs

rT�epollcs|eZdZdZ�fdd�Zdd�Zd�fdd�Z�fd	d
�Zddd�Z�fd
d�Z	�S)�
EpollSelectorzEpoll-based selector.cs t�j�tj�|_dS)N)r@rr,r\�_epoll)r)rDrrr�s
zEpollSelector.__init__cCs
|jj�S)N)r^r	)rrrrr	�szEpollSelector.filenoNcs�t�j|||�}d}|t@r8|tjO}n|t@rR|tjO}ny|jj|j|�Wn%t	k
r�t�j
|��YnX|S)Nr)r@r(r9r,�EPOLLINr:�EPOLLOUTr^r�
BaseExceptionr))rrrrr8Zepoll_events)rDrrr(�s


zEpollSelector.registercsBt�j|�}y|jj|j�Wntk
r=YnX|S)N)r@r)r^r�OSError)rrr8)rDrrr)�s
zEpollSelector.unregisterc	
Cs|dkrd}n,|dkr*d}ntj|d�d}tt|j�d�}g}y|jj||�}Wntk
r�|SYnXx�|D]z\}}d}|tj	@r�|t
O}n|tj@r�|tO}n|j
|�}|r�|j|||j@f�q�q�W|S)Nrrg@�@g����MbP?���)rXrYrMrrr^rSrNr,r_r:r`r9r>rOr)	rr+�max_evrPrZrr[rr8rrrr,�s*		
	

!zEpollSelector.selectc
s&z|jj�Wdt�j�XdS)N)r^r-r@)r)rDrrr-�szEpollSelector.close)
r"r#r$r%rr	r(r)r,r-rr)rDrr]�s
 r]�kqueuecs|eZdZdZ�fdd�Zdd�Zd�fdd�Z�fd	d
�Zddd�Z�fd
d�Z	�S)�KqueueSelectorzKqueue-based selector.cs t�j�tj�|_dS)N)r@rr,re�_kqueue)r)rDrrr�s
zKqueueSelector.__init__cCs
|jj�S)N)rgr	)rrrrr	�szKqueueSelector.filenoNcs�t�j|||�}y�|t@r_tj|jtjtj�}|jj	|gdd�n|t
@r�tj|jtjtj�}|jj	|gdd�nWn%tk
r�t�j
|��YnX|S)Nr)r@r(r9r,�keventr�KQ_FILTER_READZ	KQ_EV_ADDrg�controlr:�KQ_FILTER_WRITErar))rrrrr8�kev)rDrrr(�s

 
zKqueueSelector.registercs�t�j|�}|jt@rrtj|jtjtj�}y|j	j
|gdd�Wqrtk
rnYqrXn|jt@r�tj|jtj
tj�}y|j	j
|gdd�Wq�tk
r�Yq�Xn|S)Nr)r@r)rr9r,rhrriZKQ_EV_DELETErgrjrbr:rk)rrr8rl)rDrrr)�s 



zKqueueSelector.unregisterc

Cs|dkrdnt|d�}t|j�}g}y|jjd||�}Wntk
rj|SYnXx�|D]�}|j}|j}d}|tj	kr�|t
O}n|tjkr�|tO}n|j
|�}	|	rr|j|	||	j@f�qrqrW|S)Nr)rMrrrgrjrNZident�filterr,rir9rkr:r>rOr)
rr+rdrPZkev_listrlrZflagrr8rrrr,�s&!
	
		

!zKqueueSelector.selectc
s&z|jj�Wdt�j�XdS)N)rgr-r@)r)rDrrr-szKqueueSelector.close)
r"r#r$r%rr	r(r)r,r-rr)rDrrf�srfr�)r%�abcrr�collectionsrrrXr,rQr9r:rrrr&r5r?�hasattrrTr]rf�globalsZDefaultSelectorrrrr�<module>s4~U31IN			

?>