o
    ¼>h#  ã                   @   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   s2   dt jv rt t jd 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_reactor© r   ú~/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/autobahn/twisted/choosereactor.pyr   +   s
   
ÿr   Tc                 C   sJ  t  ¡ }tƒ }dtjv stj d¡rN|dkrH|du r;zddlm} | ¡  W n   |j	dt
 ¡ d Y nä| d	¡ nÞ|j	d
|d | rGtƒ ‚nÑ| d¡ nËtjdv r|dkr‰|du r|zddlm} | ¡  W n   |j	dt
 ¡ d Y n£| d¡ n|j	d|d | rˆtƒ ‚n| d¡ nŠtj d¡rÑ|dkrË|du r¾zddlm} | ¡  W n   |j	dt
 ¡ d Y na| d¡ n[|j	d|d | rÊtƒ ‚nN| d¡ nH|dkr|du rzddlm} | ¡  W n   |j	dt
 ¡ tjd Y n!|jdtjd  n|j	d!|tjd" | rtƒ ‚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`).
    ÚbsdÚdarwinÚ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.)Úwin32Ú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.ÚlinuxÚ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.Ú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   Útwisted.internet.iocpreactorr   r   r   ÚconfigÚloop)Úrequire_optimal_reactorÚlogr   r   Úiocpreactorr   r   r   r   r   r   r   6   sx   ÿ
ÿÿ

ÿr   Fc                 C   s°   |st  ¡ }| r/ddlm} |r|jd| d z|| ƒ W n   |jd| d t d¡ Y n|r6| d¡ t|ƒ ddl	m
} |t j_|rVd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"   Útwisted.application.reactorsr0   ÚinfoÚfailurer	   Úexitr   r$   r   r+   r,   Útwisted.python.reflectr   r   )Úexplicit_reactorÚverboser.   r-   r0   r   r   r   r   r   r   ¯   s,   ÿ
r   )T)NFNT)r	   r'   r!   Úuse_twistedÚtwisted.pythonr   Útwisted.internet.errorr   Ú__all__r   r   r   r   r   r   r   Ú<module>   s   
y