o
    >h\                     @   s8   d dl mZ ddlmZ ddlmZ G dd deZdS )    )AsyncConsumer   )aclose_old_connections)StopConsumerc                   @   s^   e Zd ZdZdd ZdddddZd	d
ddZdd Zdd Zdd Z	dd Z
dd ZdS )AsyncHttpConsumerzf
    Async HTTP consumer. Provides basic primitives for building asynchronous
    HTTP endpoints.
    c                 O   s
   g | _ d S )N)body)selfargskwargs r   u/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/channels/generic/http.py__init__   s   
zAsyncHttpConsumer.__init__   N)statusheadersc                   sB   |du rg }nt |trt| }| d||dI dH  dS )a?  
        Sets the HTTP response status and headers. Headers may be provided as
        a list of tuples or as a dictionary.

        Note that the ASGI spec requires that the protocol server only starts
        sending the response to the client after ``self.send_body`` has been
        called the first time.
        Nzhttp.response.start)typer   r   )
isinstancedictlistitemssend)r   r   r   r   r   r   send_headers   s   	

zAsyncHttpConsumer.send_headersF)	more_bodyc                   s0   t |ts
J d| d||dI dH  dS )a  
        Sends a response body to the client. The method expects a bytestring.

        Set ``more_body=True`` if you want to send more body content later.
        The default behavior closes the response, and further messages on
        the channel will be ignored.
        zBody is not byteszhttp.response.body)r   r   r   N)r   bytesr   )r   r   r   r   r   r   	send_body"   s
   
zAsyncHttpConsumer.send_bodyc                    s0   | j dd|i|I dH  | |I dH  dS )z
        Sends a response to the client. This is a thin wrapper over
        ``self.send_headers`` and ``self.send_body``, and everything said
        above applies here as well. This method may only be called once.
        r   Nr   )r   r   )r   r   r   r
   r   r   r   send_response/   s   zAsyncHttpConsumer.send_responsec                    s
   t d)z
        Receives the request body as a bytestring. Response may be composed
        using the ``self.send*`` methods; the return value of this method is
        thrown away.
        z?Subclasses of AsyncHttpConsumer must provide a handle() method.)NotImplementedError)r   r   r   r   r   handle8   s   zAsyncHttpConsumer.handlec                    s   dS )zh
        Overrideable place to run disconnect handling. Do not send anything
        from here.
        Nr   )r   r   r   r   
disconnectB   s   zAsyncHttpConsumer.disconnectc                    sh   d|v r| j |d  |ds2z| d| j I dH  W |  I dH  t |  I dH  w dS )z
        Async entrypoint - concatenates body fragments and hands off control
        to ``self.handle`` when the body has been completely received.
        r   r       N)r   appendgetr   joinr   r   r   messager   r   r   http_requestI   s   
zAsyncHttpConsumer.http_requestc                    s"   |   I dH  t I dH  t )zG
        Let the user do their cleanup and close the consumer.
        N)r   r   r   r#   r   r   r   http_disconnectW   s   z!AsyncHttpConsumer.http_disconnect)__name__
__module____qualname____doc__r   r   r   r   r   r   r%   r&   r   r   r   r   r      s    	
r   N)channels.consumerr   dbr   
exceptionsr   r   r   r   r   r   <module>   s    