
    h\                     >    d dl mZ ddlmZ ddlmZ  G d de      Zy)    )AsyncConsumer   )aclose_old_connections)StopConsumerc                   N    e Zd ZdZd ZddddZddd	Zd
 Zd Zd Z	d Z
d Zy)AsyncHttpConsumerzf
    Async HTTP consumer. Provides basic primitives for building asynchronous
    HTTP endpoints.
    c                     g | _         y )N)body)selfargskwargss      Q/var/www/Befach/backend/env/lib/python3.12/site-packages/channels/generic/http.py__init__zAsyncHttpConsumer.__init__   s	    	       N)statusheadersc                   K   |g }n)t        |t              rt        |j                               }| j	                  d||d       d{    y7 w)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   s      r   send_headerszAsyncHttpConsumer.send_headers   sL      ?G&7==?+Gii*fQ
 	
 	
s   AA	A
AF)	more_bodyc                x   K   t        |t              sJ d       | j                  d||d       d{    y7 w)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   s      r   	send_bodyzAsyncHttpConsumer.send_body"   s>      $&;(;;&ii)4iP
 	
 	
s   0:8:c                 ~   K    | j                   dd|i| d{    | j                  |       d{    y7 7 w)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   N )r   r   )r   r   r
   r   s       r   send_responsezAsyncHttpConsumer.send_response/   sA       d8v8888nnT""" 	9"s   =9=;==c                     K   t        d      w)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
   s     r   handlezAsyncHttpConsumer.handle8   s      "M
 	
s   c                    K   yw)zh
        Overrideable place to run disconnect handling. Do not send anything
        from here.
        Nr!   )r   s    r   
disconnectzAsyncHttpConsumer.disconnectB   s     
 	s   c                 `  K   d|v r| j                   j                  |d          |j                  d      sU	 | j                  dj	                  | j                                d{    | j                          d{    t               y7 '7 # | j                          d{  7   w xY ww)z
        Async entrypoint - concatenates body fragments and hands off control
        to ``self.handle`` when the body has been completely received.
        r
   r   r   N)r
   appendgetr%   joinr'   r   r   messages     r   http_requestzAsyncHttpConsumer.http_requestI   s     
 WIIWV_-{{;'(kk#((499"5666oo'''.  (6'doo'''sL   4B.-B $B%B )B.<B=B.B B.B+$B'%B++B.c                 z   K   | j                          d{    t                d{    t               7  7 w)zG
        Let the user do their cleanup and close the consumer.
        N)r'   r   r   r,   s     r   http_disconnectz!AsyncHttpConsumer.http_disconnectW   s5      oo$&&&n 	 &s   ;7;9;;)__name__
__module____qualname____doc__r   r   r   r"   r%   r'   r.   r0   r!   r   r   r   r      s;    
 ,/ 
$ 27 
#
!r   r   N)channels.consumerr   dbr   
exceptionsr   r   r!   r   r   <module>r8      s    + ' %V Vr   