
    af#                     n    d dl Z d dlZd dlZ ej                     d dlmZ d dlmZ dZd Z	d
dZ
dd	ZdS )    N)reflect)ReactorAlreadyInstalledError)install_optimal_reactorinstall_reactorcurrent_reactor_klassc                      dt           j        v rCt          j        t           j        d         j                                      d          d         } nd} | S )zK
    Return class name of currently installed Twisted reactor or None.
    ztwisted.internet.reactor.N)sysmodulesr   qual	__class__split)current_reactors    P/var/www/html/env/lib/python3.11/site-packages/autobahn/twisted/choosereactor.pyr   r   +   sM     "S[00!,s{3M'N'XYY__`cddegh    Tc                    t          j                    }t                      }dt          j        v st          j                            d          r|dk    r|b	 ddlm} |                                 |	                    d           n#  |
                    dt          j                    	           Y nxY w|
                    d
|           | rt                      ni|	                    d           nRt          j        dv r|dk    r|b	 ddlm} |                                 |	                    d           n
#  |
                    dt          j                    	           Y nxY w|
                    d|           | rt                      n|	                    d           nt          j                            d          r|dk    r|b	 ddlm} |                                 |	                    d           nA#  |
                    dt          j                    	           Y nxY w|
                    d|           | rt                      n|	                    d           n|dk    r|w	 ddlm} |                                 |	                    dt          j                   n#  |
                    dt          j                    t          j                    Y nWxY w|
                    d!|t          j        "           | rt                      n!|	                    d#t          j                   ddlm} |t           j        _        |S )$a  
    Try to install the optimal Twisted reactor for this platform:

    - Linux:   epoll
    - BSD/OSX: kqueue
    - Windows: iocp
    - Other:   select

    Notes:

    - This function exists, because the reactor types selected based on platform
      in `twisted.internet.default` are different from here.
    - The imports are inlined, because the Twisted code base is notorious for
      importing the reactor as a side-effect of merely importing. Hence we postpone
      all importing.

    See: http://twistedmatrix.com/documents/current/core/howto/choosing-reactor.html#reactor-functionality

    :param require_optimal_reactor: If ``True`` and the desired reactor could not be installed,
        raise ``ReactorAlreadyInstalledError``, else fallback to another reactor.
    :type require_optimal_reactor: bool

    :returns: The Twisted reactor in place (`twisted.internet.reactor`).
    bsddarwinKQueueReactorNr   )	kqreactorzERunning on *BSD or MacOSX and optimal reactor (kqueue) was installed.zJRunning on *BSD or MacOSX, but cannot install kqueue Twisted reactor: {tb})tbz}Running on *BSD or MacOSX, but cannot install kqueue Twisted reactor, because another reactor ({klass}) is already installed.)klasszIRunning on *BSD or MacOSX and optimal reactor (kqueue) already installed.)win32IOCPReactorreactorz<Running on Windows and optimal reactor (ICOP) was installed.zARunning on Windows, but cannot install IOCP Twisted reactor: {tb}ztRunning on Windows, but cannot install IOCP Twisted reactor, because another reactor ({klass}) is already installed.z@Running on Windows and optimal reactor (ICOP) already installed.linuxEPollReactor)epollreactorz;Running on Linux and optimal reactor (epoll) was installed.z@Running on Linux, but cannot install Epoll Twisted reactor: {tb}zsRunning on Linux, but cannot install Epoll Twisted reactor, because another reactor ({klass}) is already installed.z?Running on Linux and optimal reactor (epoll) already installed.SelectReactor)selectreactorzCRunning on "{platform}" and optimal reactor (Select) was installed.)platformzHRunning on "{platform}", but cannot install Select Twisted reactor: {tb})r   r#   z{Running on "{platform}", but cannot install Select Twisted reactor, because another reactor ({klass}) is already installed.)r   r#   zGRunning on "{platform}" and optimal reactor (Select) already installed.)txaiomake_loggerr   r   r#   
startswithtwisted.internetr   installdebugwarn	traceback
format_excr   twisted.internet.iocpreactorr   r    r"   configloop)require_optimal_reactorlogr   r   iocpreactorr    r"   r   s           r   r   r   6   sm   2 


C ,--O  7 7 A A o--&g::::::%%''' IIeffffFHHinw  oC  oE  oEH  F  F  F  F  F   Y  ap  q  q  q* 968889 IIabbbb		"	" m++&^SSSSSS''))) II\]]]]}HH`eneye{e{H|||||   P  Xg  h  h  h* 968889 IIXYYYY		 	 	)	) (x n,,&]====== ((*** II[\\\\|HH_dmdxdzdzH{{{{{   O  Wf  g  g  g* 968889 IIWXXXX o--&|>>>>>>!))+++ IIcnqnzI{{{{[HHglu  mA  mC  mC  NQ  NZH  [  [  [  [  [   W  _n  y|  yE  F  F  F* 968889 II_jmjvIwww((((((ELNs0   B	 	*B6E *E.H
 
*H7J= =5K4Fc                    |st          j                    }| r^ddlm} |r|                    d|            	  ||            nX#  |                    d|            t          j        d           Y n)xY w|r|                    d           t          |           ddl	m
} |t           j        _        |r+ddlm} |                    d	 ||j                             |S )
a  
    Install Twisted reactor.

    :param explicit_reactor: If provided, install this reactor. Else, install
        the optimal reactor.
    :type explicit_reactor: obj

    :param verbose: If ``True``, log (at level "info") the reactor that is
        in place afterwards.
    :type verbose: bool

    :param log: Explicit logging to this txaio logger object.
    :type log: obj

    :param require_optimal_reactor: If ``True`` and the desired reactor could not be installed,
        raise ``ReactorAlreadyInstalledError``, else fallback to another reactor.
    :type require_optimal_reactor: bool

    :returns: The Twisted reactor in place (`twisted.internet.reactor`).
    r   )installReactorzETrying to install explicitly specified Twisted reactor "{reactor}" ..r   z?Could not install Twisted reactor {reactor}
{log_failure.value}   z1Automatically choosing optimal Twisted reactor ..)r   z$Running on Twisted reactor {reactor})r$   r%   twisted.application.reactorsr4   infofailurer   exitr   r'   r   r.   r/   twisted.python.reflectr   r   )explicit_reactorverboser1   r0   r4   r   r   s          r   r   r      s;   *  "!! 9 	@????? 	xHH\fvHwww	N+,,,,	KKZ 0  2 2 2HQKKKKK  	JHHHIII 7888 )(((((EL Z//////7gFWAXAXYYYNs   A -A3)T)NFNT)r   r+   r$   use_twistedtwisted.pythonr   twisted.internet.errorr   __all__r   r   r    r   r   <module>rB      s   6 


           " " " " " " ? ? ? ? ? ?  v v v vr3 3 3 3 3 3r   