
    > /i                        d dl Z d dlZd dlZd dlZddlmZmZ ddlmZ ddl	m
Z
 ej                  rd dlmZ d dlmZ  ej                   d	      Zd
ej$                  e   dej$                  e   fdZ G d de      Z G d de
      Zy)    N   )RequestResponse)SyncByteStream   )BaseTransport)
OptExcInfo)WSGIApplication_Tbodyreturnc                 `    t        |       } | D ]  }|st        j                  |g|       c S  g S N)iter	itertoolschain)r   chunks     L/srv/sistema/bot/venv/lib/python3.12/site-packages/httpx/_transports/wsgi.py_skip_leading_empty_chunksr      s7    :D 2??E7D112 I    c                   d    e Zd Zdej                  e   ddfdZdej                  e   fdZddZ	y)WSGIByteStreamresultr   Nc                 H    t        |dd       | _        t        |      | _        y )Nclose)getattr_closer   _result)selfr   s     r   __init__zWSGIByteStream.__init__   s    fgt41&9r   c              #   6   K   | j                   D ]  }|  y wr   )r   )r   parts     r   __iter__zWSGIByteStream.__iter__   s     LL 	DJ	s   c                 >    | j                   | j                          y y r   )r   )r   s    r   r   zWSGIByteStream.close"   s    ;;"KKM #r   )r   N)
__name__
__module____qualname__typingIterablebytesr    Iteratorr#   r    r   r   r   r      s8    :vu5 :$ :&//%0 r   r   c                   x    e Zd ZdZ	 	 	 	 ddddedededej                  ej                     d	dfd
Z	de
d	efdZy)WSGITransporta  
    A custom transport that handles sending requests directly to an WSGI app.
    The simplest way to use this functionality is to use the `app` argument.

    ```
    client = httpx.Client(app=app)
    ```

    Alternatively, you can setup the transport instance explicitly.
    This allows you to include any additional configuration arguments specific
    to the WSGITransport class:

    ```
    transport = httpx.WSGITransport(
        app=app,
        script_name="/submount",
        remote_addr="1.2.3.4"
    )
    client = httpx.Client(transport=transport)
    ```

    Arguments:

    * `app` - The WSGI application.
    * `raise_app_exceptions` - Boolean indicating if exceptions in the application
       should be raised. Default to `True`. Can be set to `False` for use cases
       such as testing the content of a client 500 response.
    * `script_name` - The root path on which the WSGI application should be mounted.
    * `remote_addr` - A string indicating the client IP of incoming requests.
    ```
    Nappr
   raise_app_exceptionsscript_nameremote_addrwsgi_errorsr   c                 J    || _         || _        || _        || _        || _        y r   )r/   r0   r1   r2   r3   )r   r/   r0   r1   r2   r3   s         r   r    zWSGITransport.__init__H   s+     $8!&&&r   requestc                 J   |j                          t        j                  |j                        }|j                  j
                  xs ddd|j                  j                     }d|j                  j                  || j                  xs t        j                  ddd|j                  | j                  |j                  j                  |j                  j                  j                  d      |j                  j                  t!        |      d| j"                  d	}|j$                  j&                  D ]Q  \  }}|j                  d      j)                         j+                  d
d      }|dvrd|z   }|j                  d      ||<   S d d d 	 ddt         dt,        j.                  t,        j0                  t         t         f      dt,        j2                  d   dt,        j4                  t6        gt,        j8                  f   ffd}| j;                  ||      }	t=        |	      }
J J rd   r| j>                  rd   tA        jC                         d         }D cg c]'  \  }}|jE                  d      |jE                  d      f) }}}tG        |||
      S c c}}w )NP   i  )httphttps)r   r   TFasciizHTTP/1.1)zwsgi.versionzwsgi.url_schemez
wsgi.inputzwsgi.errorszwsgi.multithreadzwsgi.multiprocesszwsgi.run_onceREQUEST_METHODSCRIPT_NAME	PATH_INFOQUERY_STRINGSERVER_NAMESERVER_PORTSERVER_PROTOCOLREMOTE_ADDR-_)CONTENT_TYPECONTENT_LENGTHHTTP_statusresponse_headersexc_infor	   r   c                     | ||d S )Nc                      y r   r,   )rD   s    r   <lambda>zFWSGITransport.handle_request.<locals>.start_response.<locals>.<lambda>   s    r   r,   )rH   rI   rJ   seen_exc_infoseen_response_headersseen_statuss      r   start_responsez4WSGITransport.handle_request.<locals>.start_responsev   s     !K$4!$M!!r   r   r   )headersstreamr   )$readioBytesIOcontenturlportschemer3   sysstderrmethodr1   pathquerydecodehoststrr2   rR   rawupperreplacer(   ListTupleOptionalCallabler*   Anyr/   r   r0   intsplitencoder   )r   r5   
wsgi_inputrY   environ
header_keyheader_valuekeyrQ   r   rS   status_codevaluerR   rN   rO   rP   s                 @@@r   handle_requestzWSGITransport.handle_requestV   sh   ZZ0
{{QB#=gkk>P>P#Q"&{{11$++9szz $!&"%nn++ ))#KK--44W=";;++t9)++
" )0(;(; 	8$J##G,224<<S#FC<<m'..w7GCL		8  $
 7;		"		"$kk&,,sCx*@A		" ool3		" __eWfjj01			" '>2'&&&$000]1-$2K2K""+++-a01 4
U ZZ %,,w"78
 

 WVDD
s   ",J)T z	127.0.0.1N)r%   r&   r'   __doc__boolrb   r(   rh   TextIOr    r   r   ru   r,   r   r   r.   r.   '   sx    F &*&6:'' #' 	'
 ' __V]]3' 
':Eg :E( :Er   r.   )rU   r   r[   r(   _modelsr   r   _typesr   baser   TYPE_CHECKING	_typeshedr	   _typeshed.wsgir
   TypeVarr   r)   r   r   r.   r,   r   r   <module>r      sz    	  
  ' # 	$.V^^DV__R%8 V__R=P ^ iEM iEr   