a �DOgPL�@s�ddlmZmZddlmZddlmZddlZddlZddl Z dZ dZ dd�Z ed gd ��Z d e _e jd kr�d e j_de j_de j_de j_Gdd�de�ZGdd�ded�ZGdd�de�ZGdd�de�ZGdd�de�Zeed�r�Gdd�de�Zeed��rGd d!�d!e�Zeed"��r2Gd#d$�d$e�Zeed%��rNGd&d'�d'e�Zd(d)�Zed%��rfeZn4ed��rveZn$ed"��r�eZned��r�eZneZdS)*�)�ABCMeta�abstractmethod)� namedtuple)�MappingN��c Csdt|t�r|}n:zt|���}Wn(tttfyHtd�|��d�Yn0|dkr`td�|���|S)NzInvalid file object: {!r}rzInvalid 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@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) �_SelectorMappingcCs ||_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__rr"r'r)rrrrr=src@sjeZdZeddd��Zedd��Zddd�Zeddd ��Zd d �Zd d �Z edd��Z dd�Z dd�Z dS)� BaseSelectorNcCst�dSr��NotImplementedError�rrrrrrr�register`szBaseSelector.registercCst�dSrr.)rrrrr� unregisterwszBaseSelector.unregistercCs|�|�|�|||�Sr)r2r1r0rrr�modify�s zBaseSelector.modifycCst�dSrr.)r�timeoutrrr�select�szBaseSelector.selectcCsdSrrr!rrr�close�szBaseSelector.closecCsJ|��}|durtd��z ||WStyDtd�|��d�Yn0dS)NzSelector is closedr$)�get_map� RuntimeErrorr&r)rr�mappingrrr�get_key�s  zBaseSelector.get_keycCst�dSrr.r!rrrr7�szBaseSelector.get_mapcCs|Srrr!rrr� __enter__�szBaseSelector.__enter__cGs |��dSr)r6)r�argsrrr�__exit__�szBaseSelector.__exit__)N)N)N) r*r+r,rr1r2r3r5r6r:r7r;r=rrrrr-Qs     r-)� metaclassc@sPeZdZdd�Zdd�Zddd�Zdd �Zdd d �Zd d �Zdd�Z dd�Z dS)�_BaseSelectorImplcCsi|_t|�|_dSr)r r�_mapr!rrrr�sz_BaseSelectorImpl.__init__cCsLz t|�WStyF|j��D]}|j|ur"|jYSq"�Yn0dSr)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&�rrrrrCrrrr1�s � z_BaseSelectorImpl.registercCs>z|j�|�|��}Wn"ty8td�|��d�Yn0|Sr#)r �popr%r&rrBrrrr2�s  z_BaseSelectorImpl.unregistercCs�z|j|�|�}Wn"ty6td�|��d�Yn0||jkr\|�|�|�|||�}n"||jkr~|j|d�}||j|j <|S)Nr$)r) r r%r&rrr2r1r�_replacerrFrrrr3�s      z_BaseSelectorImpl.modifycCs|j��d|_dSr)r �clearr@r!rrrr6 s z_BaseSelectorImpl.closecCs|jSr)r@r!rrrr7sz_BaseSelectorImpl.get_mapcCs&z |j|WSty YdS0dSr)r r&)rrrrr� _key_from_fds   z_BaseSelectorImpl._key_from_fd)N)N) r*r+r,rr%r1r2r3r6r7rJrrrrr?�s  r?cs\eZdZ�fdd�Zd �fdd� Z�fdd�ZejdkrDdd d �Zne j Zdd d �Z �Z S)�SelectSelectorcst���t�|_t�|_dSr)�superr�set�_readers�_writersr!�� __class__rrr&s zSelectSelector.__init__Ncs@t��|||�}|t@r&|j�|j�|t@r<|j�|j�|Sr)rLr1rDrN�addrrErOrFrPrrr1+s zSelectSelector.registercs,t��|�}|j�|j�|j�|j�|Sr)rLr2rN�discardrrOrBrPrrr23s zSelectSelector.unregister�win32cCs$t�||||�\}}}|||gfSr)r5)r�r�w�_r4�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) �maxrYrNrO�InterruptedErrorrMrDrErJ�appendr) rr4�readyrUrVrWrrrCrrrr5@s$    zSelectSelector.select)N)N)N) r*r+r,rr1r2�sys�platformrYr5� __classcell__rrrPrrK#s    rKcsZeZdZdZdZdZ�fdd�Zd �fdd� Z�fdd�Zd �fdd � Z dd d �Z �Z S)�_PollLikeSelectorNcst���|��|_dSr)rLr� _selector_clsrr!rPrrr\s z_PollLikeSelector.__init__cslt��|||�}d}|t@r&||jO}|t@r8||jO}z|j�|j|�Wnt��|��Yn0|SrZ) rLr1rD� _EVENT_READrE� _EVENT_WRITErrr2)rrrrrC� poller_eventsrPrrr1`s   z_PollLikeSelector.registercs6t��|�}z|j�|j�Wnty0Yn0|Sr)rLr2rr�OSErrorrBrPrrr2ns   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&rrDrdrErerr3rrLr2rrH)rrrrrC�changed�selector_eventsrPrrr3xs.       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\rdrErerDrJr]r)rr4r^� fd_event_listr�eventrrCrrrr5�s(      z_PollLikeSelector.select)N)N)N) r*r+r,rcrdrerr1r2r3r5rarrrPrrbVs  rbrmc@seZdZejZejZejZ dS)� PollSelectorN) r*r+r,r5rmrc�POLLINrd�POLLOUTrerrrrrp�srp�epollcs@eZdZejZejZejZ dd�Z ddd�Z�fdd�Z �Z S) � EpollSelectorcCs |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�����rrjg����MbP?r)rkrlr[rr rrmr\r5�EPOLLINrE�EPOLLOUTrDrJr]r) rr4�max_evr^rnrrorrCrrrr5�s*      zEpollSelector.selectcs|j��t���dSr�rr6rLr!rPrrr6�s zEpollSelector.close)N) r*r+r,r5rsrcrwrdrxrer r6rarrrPrrt�s  rt�devpollcs6eZdZejZejZejZ dd�Z �fdd�Z �Z S)�DevpollSelectorcCs |j��Srrur!rrrr �szDevpollSelector.filenocs|j��t���dSrrzr!rPrrr6�s zDevpollSelector.close) r*r+r,r5r{rcrqrdrrrer r6rarrrPrr|�s r|�kqueuecsTeZdZ�fdd�Zdd�Zd�fdd� Z�fdd �Zdd d �Z�fd d �Z�Z S)�KqueueSelectorcst���t��|_dSr)rLrr5r}rr!rPrrr�s zKqueueSelector.__init__cCs |j��Srrur!rrrr szKqueueSelector.filenoNcs�t��|||�}z`|t@r@t�|jtjtj�}|j� |gdd�|t @rnt�|jtj tj�}|j� |gdd�Wnt�� |��Yn0|SrZ) rLr1rDr5�keventr�KQ_FILTER_READZ KQ_EV_ADDr�controlrE�KQ_FILTER_WRITEr2)rrrrrC�kevrPrrr1s  � � zKqueueSelector.registercs�t��|�}|jt@rTt�|jtjtj�}z|j � |gdd�Wnt yRYn0|jt @r�t�|jtj tj�}z|j � |gdd�Wnt y�Yn0|SrZ)rLr2rrDr5rrr�Z KQ_EV_DELETErr�rgrEr�)rrrCr�rPrrr2s$   �   � zKqueueSelector.unregisterc Cs�|dur dnt|d�}tt|j�d�}g}z|j�d||�}WntyT|YS0|D]Z}|j}|j}d}|tj kr�|t O}|tj kr�|t O}|� |�} | rZ|�| || j@f�qZ|S)Nrr)r[rr rr�r\�ident�filterr5r�rDr�rErJr]r) rr4ryr^Zkev_listr�r�flagrrCrrrr5*s&     zKqueueSelector.selectcs|j��t���dSrrzr!rPrrr6Cs zKqueueSelector.close)N)N) r*r+r,rr r1r2r5r6rarrrPrr~�s    r~cCsZtt|d�}|durdSz(|�}|dkr4|�d�n|��WdStyTYdS0dS)NFrmrT)�getattrr5rmr6rg)�methodr� selector_objrrr�_can_useHs   r�) �abcrr� collectionsr�collections.abcrrkr5r_rDrErr�__doc__� version_inforrrrrr-r?rKrb�hasattrrprtr|r~r��DefaultSelectorrrrr�sL   ~T3Z  .  M