
    h#                     p    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y)
    N)reflect)ReactorAlreadyInstalledError)install_optimal_reactorinstall_reactorcurrent_reactor_klassc                      dt         j                  v rDt        j                  t         j                  d   j                        j                  d      d   } | S 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    Z/var/www/Befach/backend/env/lib/python3.12/site-packages/autobahn/twisted/choosereactor.pyr   r   +   sU     "S[[0!,,s{{3M'N'X'XY__`cdegh      c                 *   t        j                         }t               }dt        j                  v st        j                  j                  d      rd|dk7  rL|*	 ddlm} |j                          |j                  d       n|j                  d	|
       | rt               |j                  d       nt        j                  dv rd|dk7  rL|*	 ddlm} |j                          |j                  d       nB|j                  d|
       | r,t               |j                  d       nt        j                  j                  d      ra|dk7  rJ|)	 ddlm} |j                          |j                  d       n|j                  d|
       | rt               |j                  d       n|dk7  ri|9	 ddlm} |j                          |j                  dt        j                         nO|j                  d |t        j                  !       | r+t               |j                  d"t        j                         ddlm} |t         j$                  _        |S #  |j                  dt        j                                Y FxY w#  |j                  dt        j                                Y rxY w#  |j                  dt        j                                Y xY w#  |j                  dt        j                         t        j                         Y xY w)#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KQueueReactorr   )	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   s   2 


C ,-O  7 7 A o-&g:%%' IIef  Y  ap  q*688IIab		" m+&^S'') II\]  P  Xg  h*688IIXY		 	 	) n,&]= ((* II[\  O  Wf  g*688IIWX o-&|>!))+ IIcnqnznzI{  W  _n  y|  yE  yE  F*688II_jmjvjvIw(ELLNYFHHinw  oC  oC  oEH  F&}HH`eneyeye{H|&|HH_dmdxdxdzH{*[HHglu  mA  mA  mC  NQ  NZ  NZH  [s0   I J J. 2K 'I?'J+.'K6Lc                    |st        j                         }| r%ddlm} |r|j	                  d|        	  ||        n|r|j	                  d       t        |       ddl	m
} |t         j                  _        |r)ddlm} |j	                  d	 ||j                               |S #  |j                  d|        t        j                  d       Y txY w)
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    * ! 	@HH\fvHw	+, HHHI 78 )ELL/7gFWFWAXYN'	KKZ 0  2HHQKs   B$ $*C)T)NFNT)r   r+   r$   use_twistedtwisted.pythonr   twisted.internet.errorr   __all__r   r   r    r   r   <module>rB      s<   6        " ?vr3r   