
    Yf<S                        d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZ ddlmZmZ dd	lmZmZ dd
lm Z m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z'  e	j(        d          Z)	 ddl*m+Z, e,Z+n# e-$ r dZ+Y nw xY w	 ddlm.Z/ e/Z.n# e-$ r dZ.Y nw xY we!dk    Z0dZ1e0r
ddlm2Z2m3Z3 dZ1 e j4                    r	 ddl5Z5dZ1n# e-$ r dZ5Y nw xY w G d d          Z6 eeee           G d de6e                      Z7 G d d          Z8 ee           G d de8e6                      Z9e+e. ee7e           e0r ee7ee           e1r ee7e            e:edd           ee7e           dgZ;dS )z
Posix reactor base class
    N)Sequence)classImplementsimplementer)errortcpudp)ReactorBase)
IHalfCloseableDescriptorIReactorFDSetIReactorMulticastIReactorProcessIReactorSocketIReactorSSLIReactorTCPIReactorUDPIReactorUNIXIReactorUNIXDatagram)CONNECTION_DONECONNECTION_LOST)failurelog)platformplatformType   )SignalHandling_ChildSignalHandling_IWaker_MultiSignalHandling_WakerzFile descriptor lost)tls)sslposixF)processunixTc                       e Zd ZdZej         ej         ej                              ej         ej         ej                              ifdZ	dS )_DisconnectSelectableMixinz>
    Mixin providing the C{_disconnectSelectable} method.
    c                    |                      |           |                    |j                  }|rn|r@|j        t          j        k    r+t          j        |          r|                    |           dS |                     |           |	                    |           dS |                     |           |	                    t          j        |                     dS )z
        Utility function for disconnecting a selectable.

        Supports half-close notification, isRead should be boolean indicating
        whether error resulted from doRead().
        N)removeReaderget	__class__r   ConnectionDoner
   
providedByreadConnectionLostremoveWriterconnectionLostr   Failure)self
selectablewhyisReadfaildictfs         L/var/www/html/env/lib/python3.11/site-packages/twisted/internet/posixbase.py_disconnectSelectablez0_DisconnectSelectableMixin._disconnectSelectableR   s      	*%%%LL'' 	<-MU%999,7
CC : --a00000!!*---))!,,,,,j)))%%goc&:&:;;;;;    N)
__name__
__module____qualname____doc__r   r+   r   r0   ConnectionLostr8    r9   r7   r&   r&   M   sy           /'/2F%2F2H2H"I"I /'/2F%2F2H2H"I"I
< < < < < <r9   r&   c                   2    e Zd ZU dZdZdefdZd Zdef fdZ	di dddddfd	Z
ddZ	 d dZd!dZd"dZd#dZ	 d$dZer%ej        ej        ej        fZeej                 ed<   nej        ej        fZd Zd Z	 d%dZd&dZd'dZ	 d'dZd&dZ d Z! xZ"S )(PosixReactorBasez
    A basis for reactors that use file descriptors.

    @ivar _childWaker: L{None} or a reference to the L{_SIGCHLDWaker}
        which is used to properly notice child process termination.
    Nreturnc                     t                      S N)r   r1   s    r7   _wakerFactoryzPosixReactorBase._wakerFactory   s    xxr9   c                     | j         sT|                                 | _         | j                            | j                    |                     | j                    dS dS )z
        Install a `waker' to allow threads and signals to wake up the IO thread.

        We use the self-pipe trick (http://cr.yp.to/docs/selfpipe.html) to wake
        the reactor. On Windows we use a pair of sockets.
        N)wakerrF   _internalReadersadd	addReaderrE   s    r7   installWakerzPosixReactorBase.installWaker   s^     z 	'++--DJ!%%dj111NN4:&&&&&	' 	'r9   c                     t                                                      }t          dk    r)t          |t	          | j        | j                  f          S |S )zj
        Customize reactor signal handling to support child processes on POSIX
        platforms.
        r"   )super_signalsFactoryr   r   r   _addInternalReader_removeInternalReader)r1   baseHandlingr*   s     r7   rO   z PosixReactorBase._signalsFactory   sb    
 ww..007""' !(/2 	
 
 
 r9   r?   r   c
                    t           dk    rK|r-|	t          d          t          j        | ||||||||	  	        S t          j        | ||||||||		  	        S t           dk    rp|t          d          |t          d          |rt          d          |	rt          d          t
          rdd	lm}
  |
| |||||          S t          d
          t          d          )Nr"   z1Using childFDs is not supported with usePTY=True.win32z,Setting UID is unsupported on this platform.z,Setting GID is unsupported on this platform.z1The usePTY parameter is not supported on Windows.z1Customizing childFDs is not supported on Windows.r   )Processz:spawnProcess not available since pywin32 is not installed.z0spawnProcess only available on Windows or POSIX.)r   
ValueErrorr#   
PTYProcessrU   win32processtwisted.internet._dumbwin32procNotImplementedError)r1   processProtocol
executableargsenvpathuidgidusePTYchildFDsrU   s              r7   spawnProcesszPosixReactorBase.spawnProcess   sS    7"" '$K   )*dCSRX   #
 
 
 W$$ !OPPP !OPPP V !TUUU V !TUUU CCCCCCwt_j$TRRR)P   &B  r9        c                 ^    t          j        |||||           }|                                 |S )zConnects a given L{DatagramProtocol} to the given numeric UDP port.

        @returns: object conforming to L{IListeningPort}.
        )r   PortstartListening)r1   portprotocol	interfacemaxPacketSizeps         r7   	listenUDPzPosixReactorBase.listenUDP   s2    
 HT8YtDD	r9   Fc                 `    t          j        ||||| |          }|                                 |S )zConnects a given DatagramProtocol to the given numeric UDP port.

        EXPERIMENTAL.

        @returns: object conforming to IListeningPort.
        )r   MulticastPortri   )r1   rj   rk   rl   rm   listenMultiplern   s          r7   listenMulticastz PosixReactorBase.listenMulticast   s<     (I}dN
 
 	
r9      c                     t           s
J d            t          j        |||| |          }|                                 |S NUNIX support is not present)unixEnabledr$   	Connectorconnect)r1   addressfactorytimeoutcheckPIDcs         r7   connectUNIXzPosixReactorBase.connectUNIX   s?    99999{N7GWdHEE			r9   2     c                     t           s
J d            t          j        ||||| |          }|                                 |S rv   )rx   r$   rh   ri   )r1   r{   r|   backlogmodewantPIDrn   s          r7   
listenUNIXzPosixReactorBase.listenUNIX  sF    99999{IgwtWEE	r9   c                     t           s
J d            t          j        |||||           }|                                 |S )z
        Connects a given L{DatagramProtocol} to the given path.

        EXPERIMENTAL.

        @returns: object conforming to L{IListeningPort}.
        rw   )rx   r$   DatagramPortri   )r1   r{   rk   rm   r   rn   s         r7   listenUNIXDatagramz#PosixReactorBase.listenUNIXDatagram  sG     99999{gxdKK	r9   c                     t           s
J d            t          j        ||||||           }|                                 |S )zd
        Connects a L{ConnectedDatagramProtocol} instance to a path.

        EXPERIMENTAL.
        rw   )rx   r$   ConnectedDatagramPortri   )r1   r{   rk   rm   r   bindAddressrn   s          r7   connectUNIXDatagramz$PosixReactorBase.connectUNIXDatagram  sP     99999{&X}dK
 
 	
r9   _supportedAddressFamiliesc                    || j         vrt          j        |          t          r2|t          j        k    r"t          j                            | ||          }n"t          j                            | |||          }|
                                 |S )a0  
        Create a new L{IListeningPort} from an already-initialized socket.

        This just dispatches to a suitable port implementation (eg from
        L{IReactorTCP}, etc) based on the specified C{addressFamily}.

        @see: L{twisted.internet.interfaces.IReactorSocket.adoptStreamPort}
        )r   r   UnsupportedAddressFamilyrx   socketAF_UNIXr$   rh   _fromListeningDescriptorr   ri   )r1   fileDescriptoraddressFamilyr|   rn   s        r7   adoptStreamPortz PosixReactorBase.adoptStreamPort7  s      >>>0??? 	=FN::	224QQAA11nmW A 	
r9   c                     || j         vrt          j        |          t          r1|t          j        k    r!t          j                            |||           S t          j                            ||||           S )zg
        @see:
            L{twisted.internet.interfaces.IReactorSocket.adoptStreamConnection}
        )
r   r   r   rx   r   r   r$   Server_fromConnectedSocketr   )r1   r   r   r|   s       r7   adoptStreamConnectionz&PosixReactorBase.adoptStreamConnectionL  st    
  >>>0??? 	=FN::;33NGTRRR:22w  r9   c                     |t           j        t           j        fvrt          j        |          t
          j                            | ||||          }|                                 |S )N)rm   )	r   AF_INETAF_INET6r   r   r   rh   r   ri   )r1   r   r   rk   rm   rn   s         r7   adoptDatagramPortz"PosixReactorBase.adoptDatagramPort[  si      AAA0???H--.- . 
 
 	
r9   c                 ^    t          j        |||||           }|                                 |S rD   )r   rh   ri   )r1   rj   r|   r   rl   rn   s         r7   	listenTCPzPosixReactorBase.listenTCPi  s0    HT7GY==	r9   c                 `    t          j        ||||||           }|                                 |S rD   )r   ry   rz   )r1   hostrj   r|   r}   r   r   s          r7   
connectTCPzPosixReactorBase.connectTCPn  s-    M$gwTJJ			r9   c           	         t           5t                               |d|          }|                     |||||          S t          6t                              |||||||           }|                                 |S J d            )NTFSSL support is not present)r    TLSMemoryBIOFactoryr   r!   ry   rz   )	r1   r   rj   r|   contextFactoryr}   r   
tlsFactoryr   s	            r7   
connectSSLzPosixReactorBase.connectSSLu  s     ?00wOOJ??4z7KPPP_dG^Wk4 A IIKKKH66665r9   c                    t           =t                               |d|          }|                     ||||          }d|_        |S t          5t                              ||||||           }|                                 |S J d            )NFTLSr   )r    r   r   _typer!   rh   ri   )r1   rj   r|   r   r   rl   r   rn   s           r7   	listenSSLzPosixReactorBase.listenSSL  s    ?00PPJ>>$
GYGGDDJK_wDQQAH66665r9   c                     t          |          | j        z
  }|D ]}|                     |           t          |          }|D ]}|                     |           t	          ||z            S )ag  
        Remove all readers and writers, and list of removed L{IReadDescriptor}s
        and L{IWriteDescriptor}s.

        Meant for calling from subclasses, to implement removeAll, like::

          def removeAll(self):
              return self._removeAll(self._reads, self._writes)

        where C{self._reads} and C{self._writes} are iterables.
        )setrI   r(   r.   list)r1   readerswritersremovedReadersreaderremovedWriterswriters          r7   
_removeAllzPosixReactorBase._removeAll  s     W(==$ 	& 	&Ff%%%%W$ 	& 	&Ff%%%%N^3444r9   )re   rf   )re   rf   F)rt   r   )r   r   r   )rf   r   )rf   r   N)rf   )r   re   )rt   N)#r:   r;   r<   r=   _childWakerr   rF   rL   r   rO   rd   ro   rs   r   r   r   r   rx   r   r   r   r   r   r   AddressFamily__annotations__r   r   r   r   r   r   r   r   __classcell__)r*   s   @r7   rA   rA   s   s&          Kw    
' 
' 
'      < 6 6 6 6t    PU   "          NR   "  

NONE
!8F,@#A 	
 	
 	
 	
 NO%
!
  *    FJ
 
 
 
   
    LP7 7 7 77 7 7 75 5 5 5 5 5 5r9   rA   c                       e Zd ZdZd ZdS )_PollLikeMixina  
    Mixin for poll-like reactors.

    Subclasses must define the following attributes::

      - _POLL_DISCONNECTED - Bitmask for events indicating a connection was
        lost.
      - _POLL_IN - Bitmask for events indicating there is input to read.
      - _POLL_OUT - Bitmask for events indicating output can be written.

    Must be mixed in to a subclass of PosixReactorBase (for
    _disconnectSelectable).
    c                    d}d}|| j         z  r%|| j        z  s|| j        v r
d}t          }nt          }n	 |                                dk    rt          }nB|| j        z  r|                                }d}|s || j        z  r|	                                }d}n<# t          $ r/ t          j                    d         }t          j                     Y nw xY w|r|                     |||           dS dS )zg
        fd is available for read or write, do the work and raise errors if
        necessary.
        NFTr   )_POLL_DISCONNECTED_POLL_IN_readsr   r   fileno_NO_FILEDESCdoRead	_POLL_OUTdoWriteBaseExceptionsysexc_infor   errr8   )r1   r2   fdeventr3   inReads         r7   _doReadOrWritez_PollLikeMixin._doReadOrWrite  s>   
 4** .	EDM4I .	 T[  
 % & $$&&",, 'CCt}, &(//11!% '54>#9 ' )0022!&     lnnQ'						
  	@&&z3?????	@ 	@s   A"B 6CCN)r:   r;   r<   r=   r   r?   r9   r7   r   r     s2         7@ 7@ 7@ 7@ 7@r9   r   c                   f    e Zd ZdZdZdZdZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd ZdS )_ContinuousPollinga  
    Schedule reads and writes based on the passage of time, rather than
    notification.

    This is useful for supporting polling filesystem files, which C{epoll(7)}
    does not support.

    The implementation uses L{_PollLikeMixin}, which is a bit hacky, but
    re-implementing and testing the relevant code yet again is unappealing.

    @ivar _reactor: The L{EPollReactor} that is using this instance.

    @ivar _loop: A C{LoopingCall} that drives the polling, or L{None}.

    @ivar _readers: A C{set} of C{FileDescriptor} objects that should be read
        from.

    @ivar _writers: A C{set} of C{FileDescriptor} objects that should be
        written to.
    r         c                 n    || _         d | _        t                      | _        t                      | _        d S rD   )_reactor_loopr   _readers_writers)r1   reactors     r7   __init__z_ContinuousPolling.__init__  s*    
r9   c                    | j         s| j        rU| j        Lddlm}m}  || j                  | _        | j        | j        _        | j        	                    |d           dS dS | j        r"| j        
                                 d| _        dS dS )zh
        Start or stop a C{LoopingCall} based on whether there are readers and
        writers.
        Nr   )_EPSILONLoopingCallF)now)r   r   r   twisted.internet.taskr   r   iterater   clockstartstop)r1   r   r   s      r7   
_checkLoopz_ContinuousPolling._checkLoop  s    
 = 	DM 	z!GGGGGGGG([66
#'=
  
  u 55555 "! Z 	JOODJJJ	 	r9   c                     t          | j                  D ]}|                     ||| j                   t          | j                  D ]}|                     ||| j                   dS )zX
        Call C{doRead} and C{doWrite} on all readers and writers respectively.
        N)r   r   r   r   r   r   )r1   r   r   s      r7   r   z_ContinuousPolling.iterate%  s~     4=)) 	? 	?F>>>>4=)) 	@ 	@F????	@ 	@r9   c                 b    | j                             |           |                                  dS )zU
        Add a C{FileDescriptor} for notification of data available to read.
        N)r   rJ   r   r1   r   s     r7   rK   z_ContinuousPolling.addReader.  0     	&!!!r9   c                 b    | j                             |           |                                  dS )zV
        Add a C{FileDescriptor} for notification of data available to write.
        N)r   rJ   r   r1   r   s     r7   	addWriterz_ContinuousPolling.addWriter5  r   r9   c                     	 | j                             |           n# t          $ r Y dS w xY w|                                  dS )zY
        Remove a C{FileDescriptor} from notification of data available to read.
        N)r   removeKeyErrorr   r   s     r7   r(   z_ContinuousPolling.removeReader<  sX    	M  (((( 	 	 	FF	    
++c                     	 | j                             |           n# t          $ r Y dS w xY w|                                  dS )zb
        Remove a C{FileDescriptor} from notification of data available to
        write.
        N)r   r   r   r   r   s     r7   r.   z_ContinuousPolling.removeWriterF  sX    
	M  (((( 	 	 	FF	r   c                     t          | j        | j        z            }| j                                         | j                                         |S )z1
        Remove all readers and writers.
        )r   r   r   clear)r1   results     r7   	removeAllz_ContinuousPolling.removeAllQ  sI     dmdm344 	r9   c                 *    t          | j                  S )z/
        Return a list of the readers.
        )r   r   rE   s    r7   
getReadersz_ContinuousPolling.getReaders\       DM"""r9   c                 *    t          | j                  S )z/
        Return a list of the writers.
        )r   r   rE   s    r7   
getWritersz_ContinuousPolling.getWritersb  r   r9   c                     || j         v S )aj  
        Checks if the file descriptor is currently being observed for read
        readiness.

        @param fd: The file descriptor being checked.
        @type fd: L{twisted.internet.abstract.FileDescriptor}
        @return: C{True} if the file descriptor is being observed for read
            readiness, C{False} otherwise.
        @rtype: C{bool}
        )r   r1   r   s     r7   	isReadingz_ContinuousPolling.isReadingh       T]""r9   c                     || j         v S )al  
        Checks if the file descriptor is currently being observed for write
        readiness.

        @param fd: The file descriptor being checked.
        @type fd: L{twisted.internet.abstract.FileDescriptor}
        @return: C{True} if the file descriptor is being observed for write
            readiness, C{False} otherwise.
        @rtype: C{bool}
        )r   r   s     r7   	isWritingz_ContinuousPolling.isWritingu  r   r9   N)r:   r;   r<   r=   r   r   r   r   r   r   rK   r   r(   r.   r   r   r   r   r   r?   r9   r7   r   r     s         , HI    $@ @ @      	 	 		 	 	# # ## # ## # ## # # # #r9   r   fromfd)<r=   r   r   typingr   zope.interfacer   r   twisted.internetr   r   r   twisted.internet.baser	   twisted.internet.interfacesr
   r   r   r   r   r   r   r   r   r   twisted.internet.mainr   r   twisted.pythonr   r   twisted.python.runtimer   r   _signalsr   r   r   r   r   ConnectionFdescWentAwayr   twisted.protocolsr    _tlsImportErrorr!   _sslrx   processEnabledr#   r$   	isWindowsrX   r&   rA   r   r   getattr__all__r?   r9   r7   <module>r     s:  
 
  



       7 7 7 7 7 7 7 7 , , , , , , , , , , - - - - - -                        C B B B B B B B ' ' ' ' ' ' ' ' 9 9 9 9 9 9 9 9              -u,-CDD------ CC    
CCC
,,,,,, CC    
CCC
 g% ........N 8    #< #< #< #< #< #< #< #<L [+'899q5 q5 q5 q5 q51; q5 q5 :9q5h	F@ F@ F@ F@ F@ F@ F@ F@R ]N# N# N# N# N#)C N# N# N#b ?coO$k222 JO$l4HIII 7O$o666
768T"".O$n555
s6   8B B
BB B"!B"	C CC