a �DOgPL�@s�dZddlmZmZddlmZddlmZddlZddl Z ddl Z dZ dZ 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 ��Zd d �Z d d�Z edd��Z dd�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 �Zdd d �Zd d�Z dd�Z dd�Z dS)�_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 �Z S)�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 dd d �Z �Z S)�_PollLikeSelectorzsN   ~T3Z  .  M