https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/asgiref/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/asgiref/__pycache__/server.cpython-310.pyc
o

�6�au�@sHddlZddlZddlZddlZddlmZe�e�ZGdd�d�Z	dS)�N�)�guarantee_single_callablec@s^eZdZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�StatelessServerax
    Base server class that handles basic concepts like application instance
    creation/pooling, exception handling, and similar, for stateless protocols
    (i.e. ones without actual incoming connections to the process)

    Your code should override the handle() method, doing whatever it needs to,
    and calling get_or_create_application_instance with a unique `scope_id`
    and `scope` for the scope it wants to get.

    If an application instance is found with the same `scope_id`, you are
    given its input queue, otherwise one is made for you with the scope provided
    and you are given that fresh new input queue. Either way, you should do
    something like:

    input_queue = self.get_or_create_application_instance(
        "user-123456",
        {"type": "testprotocol", "user_id": "123456", "username": "andrew"},
    )
    input_queue.put_nowait(message)

    If you try and create an application instance and there are already
    `max_application` instances, the oldest/least recently used one will be
    reclaimed and shut down to make space.

    Application coroutines that error will be found periodically (every 100ms
    by default) and have their exceptions printed to the console. Override
    application_exception() if you want to do more when this happens.

    If you override run(), make sure you handle things like launching the
    application checker.
    g�������?��cCs||_||_i|_dS�N)�application�max_applications�application_instances)�selfrr�r�0/usr/lib/python3/dist-packages/asgiref/server.py�__init__.s
zStatelessServer.__init__cCsJt��}t�|���z
|�|���WdSty$t�d�YdSw)zD
        Runs the asyncio event loop with our handler loop.
        zExiting due to Ctrl-C/interruptN)	�asyncio�get_event_loop�
ensure_future�application_checker�run_until_complete�handle�KeyboardInterrupt�logger�info)r
�
event_looprrr�run7s�zStatelessServer.runc��
�td��)NzYou must implement handle()��NotImplementedError)r
rrrrBs�zStatelessServer.handlec�r)zM
        Receives outbound sends from applications and handles them.
        z%You must implement application_send()r)r
�scope�messagerrr�application_sendEs�z StatelessServer.application_sendcs�|�jvrt���j|d<�j|dSt�j��jkr)���t�j��jkst��}t�j�}t�	|�|j
��fdd�d��}||�t��d��j|<|S)zH
        Creates an application instance and returns its queue.
        �	last_used�input_queuecs���|�Sr)r)r�rr
rr�<lambda>_szDStatelessServer.get_or_create_application_instance.<locals>.<lambda>)r�receive�send)r �futurerr)r	�time�lenr�"delete_oldest_application_instancer�Queuerrr�get)r
�scope_idrr �application_instancer%rr!r�"get_or_create_application_instanceMs*
�
���z2StatelessServer.get_or_create_application_instancecCsLtdd�|j��D��}|j��D]\}}|d|kr#|�|�dSqdS)zC
        Finds and deletes the oldest application instance
        css�|]}|dVqdS)rNr)�.0�detailsrrr�	<genexpr>ns�
�zEStatelessServer.delete_oldest_application_instance.<locals>.<genexpr>rN)�minr	�values�items�delete_application_instance)r
�oldest_timer+r/rrrr(js�
��z2StatelessServer.delete_oldest_application_instancecCs2|j|}|j|=|d��s|d��dSdS)z�
        Removes an application instance (makes sure its task is stopped,
        then removes it from the current set)
        r%N)r	�done�cancel)r
r+r/rrrr4xs

�z+StatelessServer.delete_application_instancec	�s~�	t�|j�IdHt|j���D]+\}}|d��r=|d��}|r-|�||�IdHz|j|=Wqt	y<Yqwqq)z�
        Goes through the set of current application instance Futures and cleans up
        any that are done/prints exceptions for any that errored.
        TNr%)
r�sleep�application_checker_interval�listr	r3r6�	exception�application_exception�KeyError)r
r+r/r;rrrr�s����z#StatelessServer.application_checkerc	�s*�t�d|d�t�|j��d|���dS)zL
        Called whenever an application coroutine has an exception.
        z%Exception inside application: %s
%s%s�z  N)�logging�error�join�	traceback�	format_tb�
__traceback__)r
r;�application_detailsrrrr<�s��z%StatelessServer.application_exceptionN)r)�__name__�
__module__�__qualname__�__doc__r9r
rrrr-r(r4rr<rrrrrs 
	
r)
rr?r&rB�
compatibilityr�	getLoggerrFrrrrrr�<module>s


https://t.me/RX1948 - 2025