o
    NK&h                     @  sN   d dl mZ d dlZd dlmZ d dlmZ erd dlmZ G dd dZ	dS )    )annotationsN)TYPE_CHECKING)SanicException)Sanicc                   @  s   e Zd ZdZdZd'ddZdd Zd	d
 Zdd Zdd Z	dd Z
d(ddZdd Zdd Zdd Zdd Zdd Zd)d"d#Zd$d% Zd&S )*AsyncioServerz|Wraps an asyncio server with functionality that might be useful to a user who needs to manage the server lifecycle manually.appconnectionsloop
serve_coroserverr   r   c                 C  s"   || _ || _|| _|| _d | _d S )Nr   )selfr   r
   r   r	    r   L/var/www/html/venv/lib/python3.10/site-packages/sanic/server/async_server.py__init__   s
   	
zAsyncioServer.__init__c                 C  s
   | j  S )z'Trigger "startup" operations on the app)r   _startupr   r   r   r   startup"   s   
zAsyncioServer.startupc                 C     |  ddS )z$Trigger "before_server_start" eventsinitbefore_server_eventr   r   r   r   before_start&      zAsyncioServer.before_startc                 C  r   )z#Trigger "after_server_start" eventsr   afterr   r   r   r   r   after_start*   r   zAsyncioServer.after_startc                 C  r   )z#Trigger "before_server_stop" eventsshutdownr   r   r   r   r   r   before_stop.   r   zAsyncioServer.before_stopc                 C  r   )z"Trigger "after_server_stop" eventsr   r   r   r   r   r   r   
after_stop2   r   zAsyncioServer.after_stopreturnboolc                 C     | j r| j  S dS )z6Returns True if the server is running, False otherwiseF)r   
is_servingr   r   r   r   r#   6   s   
zAsyncioServer.is_servingc                 C  r"   )zWait until the server is closedN)r   wait_closedr   r   r   r   r$   <   s   
zAsyncioServer.wait_closedc                 C  s0   | j r| j   |  }tj|| jd}|S dS )zClose the serverr
   N)r   closer$   asyncioensure_futurer
   )r   corotaskr   r   r   r&   A   s   
zAsyncioServer.closec                 C     |  | jjS )zStart serving requests)_server   start_servingr   r   r   r   r-   I      zAsyncioServer.start_servingc                 C  r+   )z*Serve requests until the server is stopped)r,   r   serve_foreverr   r   r   r   r/   M   r.   zAsyncioServer.serve_foreverc                 C  sJ   | j r#| jjjstdz| W S  ty"   |j}td| dw d S )NzDCannot run Sanic server without first running await server.startup()zserver.z4 not available in this version of asyncio or uvloop.)r   r   state
is_startedr   AttributeError__name__NotImplementedError)r   
serve_funcnamer   r   r   r,   Q   s   

zAsyncioServer._serveconcernstractionc                 C  s&   | j jjs	td| j j||| jdS )NzICannot dispatch server event without first running await server.startup()r%   )r   r0   r1   r   r   r
   )r   r7   r9   r   r   r   r   b   s
   
zAsyncioServer._server_eventc                 c  s2    t | j}| sdV  | r| | _| S )zD
        Starts the asyncio server, returns AsyncServerCoro
        N)r'   r(   r   doneresultr   )r   r*   r   r   r   	__await__j   s   
zAsyncioServer.__await__N)r   r   )r    r!   )r7   r8   r9   r8   )r3   
__module____qualname____doc__	__slots__r   r   r   r   r   r   r#   r$   r&   r-   r/   r,   r   r<   r   r   r   r   r      s"    


r   )

__future__r   r'   typingr   sanic.exceptionsr   sanicr   r   r   r   r   r   <module>   s    