U
    •uÄc#  ã                   @   s\   d dl Z d dlZd dlZe ¡  d dlmZ d dlmZ dZdd„ Z	ddd	„Z
ddd„ZdS )é    N)Úreflect)ÚReactorAlreadyInstalledError)Úinstall_optimal_reactorÚinstall_reactorÚcurrent_reactor_klassc                  C   s0   dt jkr(t 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_reactor© r   ú`/var/www/html/NKSPORTS/school/venv/lib/python3.8/site-packages/autobahn/twisted/choosereactor.pyr   +   s    
r   Tc                 C   sf  t  ¡ }tƒ }dtjks$tj d¡r |dkr’|dkrxzddlm} | ¡  W n   |j	dt
 ¡ d� Y q�X | d	¡ qœ|j	d
|d� | rœtƒ ‚n
| d¡ �n®tjdk�r.|dk�r |dk�rzddlm} | ¡  W n   |j	dt
 ¡ d� Y nX | d¡ n|j	d|d� | �r*tƒ ‚n
| d¡ �n tj d¡�r¼|dk�r°|dk�r”zddlm} | ¡  W n   |j	dt
 ¡ d� Y nX | d¡ n|j	d|d� | �rºtƒ ‚n
| d¡ n’|dk�r>|dk�rzddlm} | ¡  W n"   |j	dt
 ¡ tjd� Y nX |jdtjd � n|j	d!|tjd"� | �rNtƒ ‚n|jd#tjd � 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`).
    ZbsdÚdarwinZKQueueReactorNr   )Ú	kqreactorzJRunning on *BSD or MacOSX, but cannot install kqueue Twisted reactor: {tb})ÚtbzERunning on *BSD or MacOSX and optimal reactor (kqueue) was installed.z}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.)Úwin32ZIOCPReactor©ÚreactorzARunning on Windows, but cannot install IOCP Twisted reactor: {tb}z<Running on Windows and optimal reactor (ICOP) was installed.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.ÚlinuxZEPollReactor)Úepollreactorz@Running on Linux, but cannot install Epoll Twisted reactor: {tb}z;Running on Linux and optimal reactor (epoll) was installed.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.ZSelectReactor)ÚselectreactorzHRunning on "{platform}", but cannot install Select Twisted reactor: {tb})r   ÚplatformzCRunning on "{platform}" and optimal reactor (Select) was installed.)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ÚwarnÚ	tracebackÚ
format_excÚdebugr   Ztwisted.internet.iocpreactorr   r   r   ÚconfigÚloop)Úrequire_optimal_reactorÚlogr   r   Ziocpreactorr   r   r   r   r   r   r   6   sp    





r   Fc                 C   s´   |st  ¡ }| rbddlm} |r.|jd| d� z|| ƒ W qx   |jd| d� t d¡ Y qxX n|rp| d¡ t|ƒ ddl	m
} |t j_|r°ddlm} |jd	||jƒd� |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   Ztwisted.application.reactorsr)   ÚinfoZfailurer	   Úexitr   r   r   r%   r&   Ztwisted.python.reflectr   r   )Zexplicit_reactorÚverboser(   r'   r)   r   r   r   r   r   r   ¯   s,    ÿ
r   )T)NFNT)r	   r"   r   Zuse_twistedZtwisted.pythonr   Ztwisted.internet.errorr   Ú__all__r   r   r   r   r   r   r   Ú<module>   s   
y