
    h                     J   S r SSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
Jr  SSKrSSKrSSKJr  SSKrSSKrSSKJrJrJrJr  SSKJrJrJrJr  SSKJrJr  \  SSK r SS	K J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+  \ RX                  (       a,  SS
K J-r-  SSK.J/r/  SSK0r0\Rb                  Rd                  \3\34   r4O\Rb                  Rd                  r4Sr5\Rl                  " S5      r7 " S S5      r8\	" S5      S\3S\34S j5       r9 " S S\45      r: " S S5      r; " S S\<5      r= " S S\<5      r> " S S5      r? " S S5      r@ " S  S!5      rAS"\3S#\'S\&\3\34   \#\!\3\34      \!\!\3\34   S$4   4   S\34S% jrB " S& S'\5      rCS(\3S\(\!\(\D   \(\D   4      4S) jrES*\(\D   S+\(\D   S,\DS\34S- jrFS.\3S\(\D   4S/ jrG SWS0\3S1\HS2\&\3\#\H   4   S3\&\3\#\C   4   S4\(\:   SS4S5 jjrIS6\HS7\HS2\&\3\#\H   4   S3\&\3\#\C   4   SS4
S8 jrJS9\'\D\K\L\R                  \R
                  4   S\34S: jrN " S; S<\ R                  5      rPS=\3S\P4S> jrQ " S? S@\ R                  5      rRS=\3S\R4SA jrSSB\3S\*\3SS4   4SC jrTS=\3S\!\3\&\3\34   4   4SD jrUSE\3SF\&\3\34   S\34SG jrVSH\'\3\H4   SI\'\3\H4   S\H4SJ jrWSK rX\Rl                  " SL5      rYSM\3S\!\3\(\D   4   4SN jrZSO\&\3\#\+   4   S\"\!\3\+4      4SP jr[\Rl                  " SQ5      R                  r]SR\R                  S\34SS jr_SB\3S\34ST jr`SU\3S\&\3\34   4SV jrag)XzHTTP utility code shared by clients and servers.

This module also defines the `HTTPServerRequest` class which is exposed
via `tornado.web.RequestHandler.request`.
    N)	lru_cache)	responses)SSLError)	urlencodeurlparse
urlunparse	parse_qsl)
native_strparse_qs_bytesutf8
to_unicode)
ObjectDictunicode_type)TupleIterableListMappingIteratorDictUnionOptional	Awaitable	GeneratorAnyStr)Deque)Futurez 	z [\x00-\x08\x0B\x0C\x0E-\x1F\x7F]c            
          \ rS rSrSr\R                  " S5      r\R                  " S5      r\R                  " S5      r	\R                  " S\R                   S\R                   S\	R                   S35      r\R                  " S	5      r\R                  " S
5      r\R                  " S5      r\R                  " S\R                   S\R                   S35      r\R                  " S\R                   S\R                   S\R                   S\R                   35      r\R                  " S5      r\R                  " \R                   S35      r\r\r\R                  " S\R                   S\R                   S35      r\R                  " S5      r\R                  " S\R                   S\R                   S35      r\R                  " \R                   S35      r\R                  " S\R                   S\R                   S\R                   S35      r\R                  " S5      r\R                  " S\R                   S\R                   S\R                   S35      rSrg)_ABNFN   ai  Class that holds a subset of ABNF rules from RFC 9110 and friends.

Class attributes are re.Pattern objects, with the same name as in the RFC
(with hyphens changed to underscores). Currently contains only the subset
we use (which is why this class is not public). Unfortunately the fields
cannot be alphabetized as they are in the RFCs because of dependencies.
z[A-Za-z0-9\-._~]z[!$&'()*+,;=]z%[0-9A-Fa-f]{2}z(?:[\[\]:]||z)*z[0-9]*z[\x21-\x7E]z[\x80-\xFF]z(?:)z| |\t)*z[!#$%&'*+\-.^_`|~0-9A-Za-z]+z)(?::z)?zHTTP/[0-9]\.[0-9]z	(?:[\t ]|z)+(z) (z[0-9]{3} N)__name__
__module____qualname____firstlineno____doc__recompileuri_unreserveduri_sub_delimsuri_pct_encodedpatternuri_hosturi_portVCHARobs_textfield_vcharfield_valuetchartoken
field_namemethodhostHTTP_versionreason_phraserequest_targetrequest_linestatus_codestatus_line__static_attributes__r$       cC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\tornado/httputil.pyr   r   N   sQ    ZZ 34NZZ 01Njj!34Ozz~--.a0F0F/GqI`I`HaacdH zz)$H JJ~&E zz.)H**EMM?!H4D4D3EQGHK**  K$7$7#8@S@S?T	VK
 JJ56EJJ5==/+,EJF::X--.eH4D4D3ERHID ::23LJJ)EMM?!H<L<L;MRPQM ZZK$7$7#8 :;N::V^^C 6 67s<;O;O:PPQRL **[)K**\!!"#k&9&9%:#m>S>S=TTVWKrB   r   i  namereturnc                     SR                  U R                  S5       Vs/ s H  oR                  5       PM     sn5      $ s  snf )z]Map a header name to Http-Header-Case.

>>> _normalize_header("coNtent-TYPE")
'Content-Type'
-)joinsplit
capitalize)rD   ws     rC   _normalize_headerrL      s1     88TZZ_=_\\^_=>>=s   ?c            	       T   \ rS rSrSr\R                  S\\\	\   4   SS4S j5       r
\R                  S\\\4   SS4S j5       r
\R                  S\\\4   SS4S	 j5       r
\R                  S
\SS4S j5       r
S\R                  S
\SS4S jr
SS.S\S\S\SS4S jjrS\S\	\   4S jrS\\\\4      4S jrSS.S\S\SS4S jjr\SS.S\S\SS 4S jj5       rS\S\SS4S jrS\S\4S jrS\SS4S jrS\4S jrS\\R                     4S jrS!S jr\rS\4S jr\rS r g)"HTTPHeaders   a  A dictionary that maintains ``Http-Header-Case`` for all keys.

Supports multiple values per key via a pair of new methods,
`add()` and `get_list()`.  The regular dictionary interface
returns a single value per key, with multiple values joined by a
comma.

>>> h = HTTPHeaders({"content-type": "text/html"})
>>> list(h.keys())
['Content-Type']
>>> h["Content-Type"]
'text/html'

>>> h.add("Set-Cookie", "A=B")
>>> h.add("Set-Cookie", "C=D")
>>> h["set-cookie"]
'A=B,C=D'
>>> h.get_list("set-cookie")
['A=B', 'C=D']

>>> for (k,v) in sorted(h.get_all()):
...    print('%s: %s' % (k,v))
...
Content-Type: text/html
Set-Cookie: A=B
Set-Cookie: C=D
_HTTPHeaders__argrE   Nc                     g Nr$   selfrP   s     rC   __init__HTTPHeaders.__init__       rB   c                     g rR   r$   rS   s     rC   rU   rV      rW   rB   argsc                     g rR   r$   )rT   rY   s     rC   rU   rV      rW   rB   kwargsc                     g rR   r$   )rT   r[   s     rC   rU   rV      rW   rB   c                    0 U l         0 U l        S U l        [        U5      S:X  aU  [        U5      S:X  aF  [	        US   [
        5      (       a.  US   R                  5        H  u  p4U R                  X45        M     g U R                  " U0 UD6  g )N   r   )	_dict_as_list	_last_keylen
isinstancerN   get_alladdupdate)rT   rY   r[   kvs        rC   rU   rV      sr    
t9>c&kQ.:d1g{3S3SQ) * KK((rB   T_chars_are_bytesrD   valuerj   c                   [         R                  R                  U5      (       d  [        SU-  5      eU(       a<  [         R                  R                  [        U5      5      (       d  [        SU-  5      eO([        R                  U5      (       a  [        SU-  5      e[        U5      nX@l	        X@;   aH  [        X   5      S-   [        U5      -   U R                  U'   U R                  U   R                  U5        gX U'   g)z#Adds a new value for the given key.zInvalid header name %rInvalid header value %r,N)r   r8   	fullmatchHTTPInputErrorr5   r   _FORBIDDEN_HEADER_CHARS_REsearchrL   ra   r
   r_   r`   append)rT   rD   rk   rj   	norm_names        rC   re   HTTPHeaders.add   s    ))$// !9D!@AA$$..z%/@AA %%>%FGG B
 *0077$%>%FGG%d+	"4?+c1Ju4EE JJy! MM)$++E2#OrB   c                 P    [        U5      nU R                  R                  U/ 5      $ )z2Returns all values for the given header as a list.)rL   r`   getrT   rD   rt   s      rC   get_listHTTPHeaders.get_list   s#    %d+	}}  B//rB   c              #   n   #    U R                   R                  5        H  u  pU H  nX4v   M
     M     g7f)zReturns an iterable of all (name, value) pairs.

If a header has multiple values, multiple pairs will be
returned with the same name.
N)r`   items)rT   rD   valuesrk   s       rC   rd   HTTPHeaders.get_all   s2      !MM//1LDm#   2s   35linec                   [         R                  " SU5      =n(       a  USUR                  5        nU(       d  gUS   [        ;   a  U R                  c  [        S5      eSUR                  [        5      -   nU(       a6  [        R                  R                  USS 5      (       d  [        SU-  5      eO([        R                  U5      (       a  [        SU-  5      eU R                  U R                     S	==   U-  ss'   U R                  U R                  ==   U-  ss'   g UR                  S
S5      u  pVU R                  XVR                  [        5      US9  g! [         a    [        S5      ef = f)af  Updates the dictionary with a single header line.

>>> h = HTTPHeaders()
>>> h.parse_line("Content-Type: text/html")
>>> h.get('content-type')
'text/html'
>>> h.parse_line("Content-Length: 42\r\n")
>>> h.get('content-type')
'text/html'

.. versionchanged:: 6.5
    Now supports lines with or without the trailing CRLF, making it possible
    to pass lines from AsyncHTTPClient's header_callback directly to this method.

.. deprecated:: 6.5
   In Tornado 7.0, certain deprecated features of HTTP will become errors.
   Specifically, line folding and the use of LF (with CR) as a line separator
   will be removed.
z\r?\n$Nr   z.first header line cannot start with whitespace r^   zInvalid header continuation %rrm   :zno colon in header lineri   )r*   rr   startHTTP_WHITESPACEra   rp   stripr   r5   ro   rq   r`   r_   rI   
ValueErrorre   )rT   r   rj   mnew_partrD   rk   s          rC   
parse_lineHTTPHeaders.parse_line   sT   ( 		)T**1* !'')$D7o% ~~%$%UVVTZZ88H((228AB<@@()IH)TUU A .44X>>()BX)MNNMM$..)"-9-JJt~~&(2&@"jja0 HHkk/2EU    @$%>??@s   #E E1headersc                    U " 5       nSn UR                  SU5      nUS:X  a  UR                  XS US9   U$ XUS-    nUS-   nUR                  XbS9  MJ  )aL  Returns a dictionary from HTTP header text.

>>> h = HTTPHeaders.parse("Content-Type: text/html\r\nContent-Length: 42\r\n")
>>> sorted(h.items())
[('Content-Length', '42'), ('Content-Type', 'text/html')]

.. versionchanged:: 5.1

   Raises `HTTPInputError` on malformed headers instead of a
   mix of `KeyError`, and `ValueError`.

r   
r   Nri   r^   )findr   )clsr   rj   hr   lfr   s          rC   parseHTTPHeaders.parse#  su    8 EdE*BRxWV_?OP  26*DFELLLA rB   c                 V    [        U5      nX R                  U'   U/U R                  U'   g rR   rL   r_   r`   )rT   rD   rk   rt   s       rC   __setitem__HTTPHeaders.__setitem__N  s(    %d+	 %

9$)7i rB   c                 2    U R                   [        U5         $ rR   )r_   rL   )rT   rD   s     rC   __getitem__HTTPHeaders.__getitem__S  s    zz+D122rB   c                 N    [        U5      nU R                  U	 U R                  U	 g rR   r   rx   s      rC   __delitem__HTTPHeaders.__delitem__V  s$    %d+	JJy!MM)$rB   c                 ,    [        U R                  5      $ rR   )rb   r_   rT   s    rC   __len__HTTPHeaders.__len__[  s    4::rB   c                 ,    [        U R                  5      $ rR   )iterr_   r   s    rC   __iter__HTTPHeaders.__iter__^  s    DJJrB   c                     [        U 5      $ rR   )rN   r   s    rC   copyHTTPHeaders.copya  s    4  rB   c                     / nU R                  5        H  u  p#UR                  U SU S35        M     SR                  U5      $ )Nz: r    )rd   rs   rH   )rT   linesrD   rk   s       rC   __str__HTTPHeaders.__str__j  s@    <<>KDLLD6E7"-. *wwu~rB   )r`   r_   ra   )rE   rN   )!r%   r&   r'   r(   r)   typingoverloadr   strr   rU   r   Anyboolre   ry   r   rd   r   classmethodr   r   r   r   intr   r   r   r   __copy__r   __unicode__rA   r$   rB   rC   rN   rN      s   8 __gc49n5 $   __gc3h/ D   __eCHo $   __   
)fjj 
)C 
)D 
) FJ $ $C $d $d $,0S 0T#Y 0
$%S/2 $ AE 1s 1 1 1f =A &C &d &m & &T+ +C +D +
3 3 3% % %
  (6::.  ! H  KrB   rN   c                   N   \ rS rSrSrSrSrSr         SS\\	   S\\	   S\	S\\
   S\\   S	\\\	\S
   4      S\S   S\S   S\\   SS4S jjr\S\\	\R$                  R&                  4   4S j5       rS\	4S jrS\4S jr SS\S\S\\4   4S jjrSS jrS\	4S jrSrg)HTTPServerRequestis  a[	  A single HTTP request.

All attributes are type `str` unless otherwise noted.

.. attribute:: method

   HTTP request method, e.g. "GET" or "POST"

.. attribute:: uri

   The requested uri.

.. attribute:: path

   The path portion of `uri`

.. attribute:: query

   The query portion of `uri`

.. attribute:: version

   HTTP version specified in request, e.g. "HTTP/1.1"

.. attribute:: headers

   `.HTTPHeaders` dictionary-like object for request headers.  Acts like
   a case-insensitive dictionary with additional methods for repeated
   headers.

.. attribute:: body

   Request body, if present, as a byte string.

.. attribute:: remote_ip

   Client's IP address as a string.  If ``HTTPServer.xheaders`` is set,
   will pass along the real IP address provided by a load balancer
   in the ``X-Real-Ip`` or ``X-Forwarded-For`` header.

.. versionchanged:: 3.1
   The list format of ``X-Forwarded-For`` is now supported.

.. attribute:: protocol

   The protocol used, either "http" or "https".  If ``HTTPServer.xheaders``
   is set, will pass along the protocol used by a load balancer if
   reported via an ``X-Scheme`` header.

.. attribute:: host

   The requested hostname, usually taken from the ``Host`` header.

.. attribute:: arguments

   GET/POST arguments are available in the arguments property, which
   maps arguments names to lists of values (to support multiple values
   for individual names). Names are of type `str`, while arguments
   are byte strings.  Note that this is different from
   `.RequestHandler.get_argument`, which returns argument values as
   unicode strings.

.. attribute:: query_arguments

   Same format as ``arguments``, but contains only arguments extracted
   from the query string.

   .. versionadded:: 3.2

.. attribute:: body_arguments

   Same format as ``arguments``, but contains only arguments extracted
   from the request body.

   .. versionadded:: 3.2

.. attribute:: files

   File uploads are available in the files property, which maps file
   names to lists of `.HTTPFile`.

.. attribute:: connection

   An HTTP request is attached to a single HTTP connection, which can
   be accessed through the "connection" attribute. Since connections
   are typically kept open in HTTP/1.1, multiple requests can be handled
   sequentially on a single connection.

.. versionchanged:: 4.0
   Moved from ``tornado.httpserver.HTTPRequest``.
Nr9   uriversionr   bodyfilesHTTPFile
connectionHTTPConnection
start_lineRequestStartLineserver_connectionrE   c
                 $   Ub  Uu  pnXl         X l        X0l        U=(       d
    [        5       U l        U=(       d    SU l        [        USS 5      n
[        U
SS 5      U l        [        U
SS5      U l         U R                  S   U l	        [        R                  R                  U R                  5      (       d;  [        [        R                  R                  5        [        S
U R                  -  5      eSU R                  ;   a  [        SU R                  -  5      e[!        U R                  R#                  5       5      S   U l        U=(       d    0 U l        Xpl        Xl        [,        R,                  " 5       U l        S U l        Ub  UR3                  S5      u  U l        ol        [9        U R6                  SS9U l        [<        R>                  " U R:                  5      U l         0 U l!        g ! [         a    US:X  a
  SU l	         GNz[        S	5      ef = f)NrB   context	remote_ipprotocolhttpHostHTTP/1.0z	127.0.0.1zMissing Host headerzInvalid Host header: %rrn   z%Multiple host headers not allowed: %rr   ?Tkeep_blank_values)"r9   r   r   rN   r   r   getattrr   r   r:   KeyErrorrp   r   ro   printr/   split_host_and_portlower	host_namer   r   r   time_start_time_finish_time	partitionpathqueryr   	argumentsr   deepcopyquery_argumentsbody_arguments)rT   r9   r   r   r   r   r   r   r   r   r   seps               rC   rU   HTTPServerRequest.__init__  s    !#- F/+-KC	 *i6 +t<V<	<V,DI zz##DII..%**$$% !:TYY!FGG$))" !!H499!TUU,TYY__->?B[b
$!299; ?),s);&DIsJ'

dK#}}T^^< M  	<*$'	$%:;;	<s   5G) )HHc                    [        U S5      (       d  [        R                  R                  5       U l        SU R
                  ;   aM   [        U R
                  S   5      nUR                  5        H  u  p# X0R                  U'   M     U R                  $ U R                  $ ! [         a     M=  f = f! [         a     U R                  $ f = f)z0A dictionary of ``http.cookies.Morsel`` objects._cookiesCookie)	hasattrr   cookiesSimpleCookier   r   parse_cookier|   	Exception)rT   parsedrg   rh   s       rC   r   HTTPServerRequest.cookies  s     tZ(())+ M 4<<'!)$,,x*@AF !'!/0MM!, !/ }}t}}  ) ! !	! !  }}s$   B/ 4B
B,+B,/
CCc                 T    U R                   S-   U R                  -   U R                  -   $ )z+Reconstructs the full URL for this request.z://)r   r:   r   r   s    rC   full_urlHTTPServerRequest.full_url1  s#    }}u$tyy0488;;rB   c                     U R                   c"  [        R                  " 5       U R                  -
  $ U R                   U R                  -
  $ )z?Returns the amount of time it took for this request to execute.)r   r   r   r   s    rC   request_timeHTTPServerRequest.request_time5  s<    $99;!1!111$$t'7'777rB   binary_formc                      U R                   c  gU R                   R                  R                  R                  US9$ ! [         a     gf = f)a  Returns the client's SSL certificate, if any.

To use client certificates, the HTTPServer's
`ssl.SSLContext.verify_mode` field must be set, e.g.::

    ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
    ssl_ctx.load_cert_chain("foo.crt", "foo.key")
    ssl_ctx.load_verify_locations("cacerts.pem")
    ssl_ctx.verify_mode = ssl.CERT_REQUIRED
    server = HTTPServer(app, ssl_options=ssl_ctx)

By default, the return value is a dictionary (or None, if no
client certificate is present).  If ``binary_form`` is true, a
DER-encoded form of the certificate is returned instead.  See
SSLSocket.getpeercert() in the standard library for more
details.
http://docs.python.org/library/ssl.html#sslsocket-objects
N)r   )r   streamsocketgetpeercertr   )rT   r   s     rC   get_ssl_certificate%HTTPServerRequest.get_ssl_certificate<  sS    *	&??))00<<' =    		s   = ,= 
A
	A
c                 B   [        U R                  R                  SS5      U R                  U R                  U R
                  U R                  5        U R                  R                  5        H0  u  pU R                  R                  U/ 5      R                  U5        M2     g )NContent-Typer   )
parse_body_argumentsr   rw   r   r   r   r|   r   
setdefaultextend)rT   rg   rh   s      rC   _parse_bodyHTTPServerRequest._parse_body[  sx    LL^R0IIJJLL	
 ''--/DANN%%a,33A6 0rB   c                     SnSR                  U Vs/ s H  o" S[        X5      < 3PM     sn5      nU R                  R                   SU S3$ s  snf )N)r   r:   r9   r   r   r   z, =r#   r!   )rH   r   	__class__r%   )rT   attrsnrY   s       rC   __repr__HTTPServerRequest.__repr__g  sW    MyyuEu!Cq!1 45uEF..))*!D633 Fs   A)r   r   r   r   r   r   r   r   r   r:   r   r9   r   r   r   r   r   r   r   r   )	NNr   NNNNNN)FrE   N)r%   r&   r'   r(   r)   r   r   _body_futurer   r   rN   bytesr   r   objectrU   propertyr   r   Morselr   floatr   r   r   r   r   r  rA   r$   rB   rC   r   r   s  s`   Zx DE L !%!!)- $7;1537.2B!B! c]B! 	B!
 +&B! uoB! S$z"2234B! -.B! /0B! $F+B! 
B!H c4<<#6#667  ,<# <8e 8 #(	tT5 	!>
74# 4rB   r   c                       \ rS rSrSrSrg)rp   im  zeException class for malformed HTTP requests or responses
from remote sources.

.. versionadded:: 4.0
r$   Nr%   r&   r'   r(   r)   rA   r$   rB   rC   rp   rp   m  s     	rB   rp   c                       \ rS rSrSrSrg)HTTPOutputErroriw  zBException class for errors in HTTP output.

.. versionadded:: 4.0
r$   Nr  r$   rB   rC   r  r  w  s    
 	rB   r  c                   @    \ rS rSrSrS\SSSS4S jrS\SS	4S
 jrSrg	)HTTPServerConnectionDelegatei  zWImplement this interface to handle requests from `.HTTPServer`.

.. versionadded:: 4.0
server_connrequest_connr   rE   HTTPMessageDelegatec                     [        5       e)a:  This method is called by the server when a new request has started.

:arg server_conn: is an opaque object representing the long-lived
    (e.g. tcp-level) connection.
:arg request_conn: is a `.HTTPConnection` object for a single
    request/response exchange.

This method should return a `.HTTPMessageDelegate`.
NotImplementedError)rT   r  r  s      rC   start_request*HTTPServerConnectionDelegate.start_request  s     "##rB   Nc                     g)zThis method is called when a connection has been closed.

:arg server_conn: is a server connection that has previously been
    passed to ``start_request``.
Nr$   )rT   r  s     rC   on_close%HTTPServerConnectionDelegate.on_close       	rB   r$   )	r%   r&   r'   r(   r)   r  r  r  rA   r$   rB   rC   r  r    s7    
$!$1A$	$F t rB   r  c                   r    \ rS rSrSrS\S   S\S\\S      4S jr	S	\
S\\S      4S
 jrSS jrSS jrSrg)r  i  zWImplement this interface to handle an HTTP request or response.

.. versionadded:: 4.0
r   r   ResponseStartLiner   rE   Nc                     g)a  Called when the HTTP headers have been received and parsed.

:arg start_line: a `.RequestStartLine` or `.ResponseStartLine`
    depending on whether this is a client or server message.
:arg headers: a `.HTTPHeaders` instance.

Some `.HTTPConnection` methods can only be called during
``headers_received``.

May return a `.Future`; if it does the body will not be read
until it is done.
Nr$   )rT   r   r   s      rC   headers_received$HTTPMessageDelegate.headers_received  s    " 	rB   chunkc                     g)zYCalled when a chunk of data has been received.

May return a `.Future` for flow control.
Nr$   rT   r$  s     rC   data_received!HTTPMessageDelegate.data_received  s    
 	rB   c                     g)z6Called after the last chunk of data has been received.Nr$   r   s    rC   finishHTTPMessageDelegate.finish  rW   rB   c                     g)zCalled if the connection is closed without finishing the request.

If ``headers_received`` is called, either ``finish`` or
``on_connection_close`` will be called, but not both.
Nr$   r   s    rC   on_connection_close'HTTPMessageDelegate.on_connection_close  r  rB   r$   r  )r%   r&   r'   r(   r)   r   rN   r   r   r"  r  r'  r*  r-  rA   r$   rB   rC   r  r    s]    AB  
)D/	"	&5 Xio-F rB   r  c            	       `    \ rS rSrSr SS\S   S\S\\   SS	4S
 jjr	S\SS	4S jr
SS jrSrg)r   i  zQApplications use this interface to write their responses.

.. versionadded:: 4.0
Nr   r  r   r$  rE   zFuture[None]c                     [        5       e)a  Write an HTTP header block.

:arg start_line: a `.RequestStartLine` or `.ResponseStartLine`.
:arg headers: a `.HTTPHeaders` instance.
:arg chunk: the first (optional) chunk of data.  This is an optimization
    so that small responses can be written in the same call as their
    headers.

The ``version`` field of ``start_line`` is ignored.

Returns a future for flow control.

.. versionchanged:: 6.0

   The ``callback`` argument was removed.
r  )rT   r   r   r$  s       rC   write_headersHTTPConnection.write_headers  s    , "##rB   c                     [        5       e)zWrites a chunk of body data.

Returns a future for flow control.

.. versionchanged:: 6.0

   The ``callback`` argument was removed.
r  r&  s     rC   writeHTTPConnection.write  s     "##rB   c                     [        5       e)z3Indicates that the last body data has been written.r  r   s    rC   r*  HTTPConnection.finish  s    !##rB   r$   rR   r  )r%   r&   r'   r(   r)   r   rN   r   r  r1  r4  r*  rA   r$   rB   rC   r   r     sY     "&	$AB$ $ 	$
 
$0	$5 	$^ 	$$rB   r   urlrY   .c           	         Uc  U $ [        U 5      n[        U[        5      (       a4  [        UR                  SS9nUR                  UR                  5       5        Ou[        U[        5      (       d  [        U[        5      (       a&  [        UR                  SS9nUR                  U5        O%SR                  [        U5      5      n[        U5      e[        U5      n[        US   US   US   US   UUS   45      n U $ )	a  Concatenate url and arguments regardless of whether
url has existing query parameters.

``args`` may be either a dictionary or a list of key-value pairs
(the latter allows for multiple values with the same key.

>>> url_concat("http://example.com/foo", dict(c="d"))
'http://example.com/foo?c=d'
>>> url_concat("http://example.com/foo?a=b", dict(c="d"))
'http://example.com/foo?a=b&c=d'
>>> url_concat("http://example.com/foo?a=b", [("c", "d"), ("c", "d2")])
'http://example.com/foo?a=b&c=d&c=d2'
Tr   z7'args' parameter should be dict, list or tuple. Not {0}r   r^            )r   rc   dictr	   r   r   r|   listtupleformattype	TypeErrorr   r   )r8  rY   
parsed_urlparsed_queryerrfinal_querys         rC   
url_concatrG    s    & |
#J$ !1!1TJDJJL)	D$		:dE#:#: !1!1TJD!GNNJ
 nL)K
qMqMqMqMqM	
	C JrB   c                   8    \ rS rSr% Sr\\S'   \\S'   \\S'   Srg)r   i(  zRepresents a file uploaded via a form.

For backwards compatibility, its instance attributes are also
accessible as dictionary keys.

* ``filename``
* ``body``
* ``content_type``
filenamer   content_typer$   N)	r%   r&   r'   r(   r)   r   __annotations__r  rA   r$   rB   rC   r   r   (  s     M
KrB   r   range_headerc                 $   U R                  S5      u  pnUR                  5       UR                  5       p1US:w  a  gUR                  S5      u  pBn [        U5      n[        U5      nUb  Uc  US:w  a  U* nSnXg4$ US-  nXg4$ ! [         a     gf = f)a  Parses a Range header.

Returns either ``None`` or tuple ``(start, end)``.
Note that while the HTTP headers use inclusive byte positions,
this method returns indexes suitable for use in slices.

>>> start, end = _parse_request_range("bytes=1-2")
>>> start, end
(1, 3)
>>> [0, 1, 2, 3, 4][start:end]
[1, 2]
>>> _parse_request_range("bytes=6-")
(6, None)
>>> _parse_request_range("bytes=-6")
(-6, None)
>>> _parse_request_range("bytes=-0")
(None, 0)
>>> _parse_request_range("bytes=")
(None, None)
>>> _parse_request_range("foo=42")
>>> _parse_request_range("bytes=1-2,6-10")

Note: only supports one range (ex, ``bytes=1-2,6-10`` is not allowed).

See [0] for the details of the range header.

[0]: http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p5-range-latest.html#byte.ranges
r   r  NrG   r   r^   )r   r   _int_or_noner   )rL  unit_rk   start_bend_br   ends           rC   _parse_request_rangerT  8  s    > "++C0NDU**,%w,GW%5! =ax < 1HC<  s   B 
BBr   rS  totalc                 J    U =(       d    Sn U=(       d    US-
  nSU  SU SU 3$ )zReturns a suitable Content-Range header:

>>> print(_get_content_range(None, 1, 4))
bytes 0-0/4
>>> print(_get_content_range(1, 3, 4))
bytes 1-2/4
>>> print(_get_content_range(None, None, 4))
bytes 0-3/4
r   r^   zbytes rG   /r$   )r   rS  rU  s      rC   _get_content_rangerX  k  s4     JQE<%1
CE7!C5%))rB   valc                 F    U R                  5       n U S:X  a  g [        U 5      $ )Nr   )r   r   )rY  s    rC   rN  rN  z  s     
))+C
bys8OrB   rJ  r   r   r   r   c                    U R                  S5      (       am  U(       a  SU;   a  [        SUS   -  5      e [        USS9nUR	                  5        H/  u  pxU(       d  M  UR                  U/ 5      R                  U5        M1     gU R                  S5      (       a  U(       a  SU;   a  [        SUS   -  5      e U R                  S	5      n	U	 HL  n
U
R                  5       R                  S
5      u  pnUS:X  d  M-  U(       d  M6  [        [        U5      XU5          g   [        S5      eg! [         a  n[        SU-  5      UeSnAff = f! [         a  n[        SU-  5      UeSnAff = f)a.  Parses a form request body.

Supports ``application/x-www-form-urlencoded`` and
``multipart/form-data``.  The ``content_type`` parameter should be
a string and ``body`` should be a byte string.  The ``arguments``
and ``files`` parameters are dictionaries that will be updated
with the parsed contents.
z!application/x-www-form-urlencodedzContent-Encodingz Unsupported Content-Encoding: %sTr   z&Invalid x-www-form-urlencoded body: %sNzmultipart/form-data;r   boundaryzmultipart boundary not foundzInvalid multipart/form-data: %s)
startswithrp   r   r   r|   r   r   rI   r   r   parse_multipart_form_datar   )rJ  r   r   r   r   uri_argumentserD   r}   fieldsfieldrg   r   rh   s                 rC   r   r     sx    BCC)W4 2W=O5PP 	V*44HM *//1LDv$$T2.55f= 2 
	 	 !6	7	7)W4 2W=O5PP 
	O!'',F!KKM33C8	
?qq-d1gtN	   %%CDD 
8  	V !IA!MNTUU	V&  	O !BQ!FGQN	OsA   
D( 9<E	 9E	 E	 E	 (
E2EE	
E'E""E'r]  datac           	      x   U R                  S5      (       a  U R                  S5      (       a  U SS n UR                  SU -   S-   5      nUS:X  a  [        S5      eUSU R	                  SU -   S-   5      nU GH@  nU(       d  M  UR                  S5      nUS:X  a  [        S	5      e[        R                  USU R                  S
5      SS9nUR                  SS5      n	[        U	5      u  pU
S:w  d  UR                  S5      (       d  [        S5      eXgS-   S nUR                  S5      (       d  [        S5      eUS   nUR                  S5      (       aA  UR                  SS5      nUR                  U/ 5      R                  [        US   XS95        GM  UR                  U/ 5      R                  U5        GMC     g)aA  Parses a ``multipart/form-data`` body.

The ``boundary`` and ``data`` parameters are both byte strings.
The dictionaries given in the arguments and files parameters
will be updated with the contents of the body.

.. versionchanged:: 5.1

   Now recognizes non-ASCII filenames in RFC 2231/5987
   (``filename*=``) format.
   "r^   r   s   --z4Invalid multipart/form-data: no final boundary foundNs   
s   

z#multipart/form-data missing headerszutf-8Fri   zContent-Dispositionr   z	form-datazInvalid multipart/form-data   rD   z multipart/form-data missing namerI  r   zapplication/unknown)rI  r   rJ  )r^  endswithrfindrp   rI   r   rN   r   decoderw   _parse_headerr   rs   r   )r]  rd  r   r   final_boundary_indexpartsparteohr   disp_headerdispositiondisp_paramsrk   rD   ctypes                  rC   r_  r_    s   , 4  X%6%6t%<%<Ab>::eh&6&>?r!STT&&'--eh.>.HIEii$"9 !FGG##D#J$5$5g$>QV#Wkk"7<#0#= +%T]]7-C-C !>??1Wr"v&& !CDD6"??:&&KK0EFET2&--(45   r*11%8/ rB   tsc                    [        U [        [        45      (       a  U nO[        U [        [        R
                  45      (       a  [        R                  " U 5      nOR[        U [        R                  5      (       a%  [        R                  " U R                  5       5      nO[        SU -  5      e[        R                  R                  USS9$ )ay  Formats a timestamp in the format used by HTTP.

The argument may be a numeric timestamp as returned by `time.time`,
a time tuple as returned by `time.gmtime`, or a `datetime.datetime`
object. Naive `datetime.datetime` objects are assumed to represent
UTC; aware objects are converted to UTC before formatting.

>>> format_timestamp(1359312200)
'Sun, 27 Jan 2013 18:43:20 GMT'
zunknown timestamp type: %rT)usegmt)rc   r   r  r?  r   struct_timecalendartimegmdatetimeutctimetuplerB  emailutils
formatdate)ru  time_nums     rC   format_timestampr    s     "sEl##	B 0 01	2	2??2&	B))	*	*??2??#454r9::;;!!(4!88rB   c                   4    \ rS rSr% \\S'   \\S'   \\S'   Srg)r   i  r9   r   r   r$   N)r%   r&   r'   r(   r   rK  rA   r$   rB   rC   r   r     s    K
ILrB   r   r   c                 L   [         R                  R                  U 5      nU(       d  [        S5      e[	        UR                  S5      UR                  S5      UR                  S5      5      nUR                  R                  S5      (       d  [        SUR                  -  5      eU$ )zReturns a (method, path, version) tuple for an HTTP 1.x request line.

The response is a `typing.NamedTuple`.

>>> parse_request_start_line("GET /foo HTTP/1.1")
RequestStartLine(method='GET', path='/foo', version='HTTP/1.1')
zMalformed HTTP request liner^   r:  r;  HTTP/1Unexpected HTTP version %r)r   r>   ro   rp   r   groupr   r^  r   matchrs      rC   parse_request_start_liner    s     ((.E :;;QQQHA99)) 9AIIEFFHrB   c                   4    \ rS rSr% \\S'   \\S'   \\S'   Srg)r   i  r   codereasonr$   N)r%   r&   r'   r(   r   rK  r   rA   r$   rB   rC   r   r     s    L
IKrB   r   c                 ^   [         R                  R                  U 5      nU(       d  [        S5      e[	        UR                  S5      [        UR                  S5      5      UR                  S5      5      nUR                  R                  S5      (       d  [        SUR                  -  5      eU$ )zReturns a (version, code, reason) tuple for an HTTP 1.x response line.

The response is a `typing.NamedTuple`.

>>> parse_response_start_line("HTTP/1.1 200 OK")
ResponseStartLine(version='HTTP/1.1', code=200, reason='OK')
z!Error parsing response start liner^   r:  r;  r  r  )	r   r@   ro   rp   r   r  r   r   r^  r  s      rC   parse_response_start_liner    s     ''-E@AA%++a.#ekk!n*=u{{1~NA99))9AIIEFFHrB   sc              #     #    U S S S:X  a  U SS  n U R                  S5      nUS:  a{  U R                  SSU5      U R                  SSU5      -
  S-  (       aL  U R                  SUS-   5      nUS:  a1  U R                  SSU5      U R                  SSU5      -
  S-  (       a  ML  US:  a  [        U 5      nU S U nUR                  5       v   XS  n U S S S:X  a  M  g g 7f)Nr^   r\  r   "z\"r:  )r   countrb   r   )r  rS  fs      rC   _parseparamr  9  s     
BQ%3,abEffSkAg17733/!''%C2HHAM&&cAg&C Ag17733/!''%C2HHAMM7a&CdsGggidG BQ%3,s   BC#5CCc                 4   [        SU -   5      n[        U5      nS/nU Hn  nUR                  S5      nUS:  d  M  USU R                  5       R	                  5       nXES-   S R                  5       nUR                  U[        U5      45        Mp     [        R                  R                  U5      nUR                  S5        0 n	U HN  u  pj[        R                  R                  U
5      n[        U5      S:  a  US   S:X  a  US	   S:X  a  USS	 nXyU'   MP     X)4$ )
a1  Parse a Content-type like header.

Return the main content-type and a dictionary of options.

>>> d = "form-data; foo=\"b\\\\a\\\"r\"; file*=utf-8''T%C3%A4st"
>>> ct, d = _parse_header(d)
>>> ct
'form-data'
>>> d['file'] == r'T\u00e4st'.encode('ascii').decode('unicode_escape')
True
>>> d['foo']
'b\\a"r'
r\  )Dummyrk   r   r   Nr^   r:  r  r   )r  nextr   r   r   rs   r
   r}  r~  decode_paramspopcollapse_rfc2231_valuerb   )r   rn  keyparamspirD   rk   decoded_paramspdictdecoded_values              rC   rl  rl  F  s    d
#E
u+C !FFF3K6Ra5;;=&&(D!egJ$$&EMM4E!234  [[..v6NqE-22=Au:?uQx3593C!BKEd	  .
 :rB   r  r  c                     U(       d  U $ U /n[        UR                  5       5       H1  u  p4Uc  UR                  U5        M  UR                  U SU 35        M3     SR                  U5      $ )zInverse of _parse_header.

>>> _encode_header('permessage-deflate',
...     {'client_max_window_bits': 15, 'client_no_context_takeover': None})
'permessage-deflate; client_max_window_bits=15; client_no_context_takeover'
r   z; )sortedr|   rs   rH   )r  r  outrg   rh   s        rC   _encode_headerr  i  sb     
%Cu{{}%9JJqM JJ!AaSz" & 99S>rB   usernamepasswordc                     [        U [        5      (       a  [        R                  " SU 5      n [        U[        5      (       a  [        R                  " SU5      n[	        U 5      S-   [	        U5      -   $ )zEncodes a username/password pair in the format used by HTTP auth.

The return value is a byte string in the form ``username:password``.

.. versionadded:: 5.1
NFC   :)rc   r   unicodedata	normalizer   )r  r  s     rC   encode_username_passwordr  }  sZ     (L))((9(L))((9>D 4>11rB   c                  *    SS K n U R                  5       $ )Nr   )doctestDocTestSuite)r  s    rC   doctestsr    s    !!rB   z^(.+):(\d+)$netlocc                     [         R                  U 5      nU(       a.  UR                  S5      n[        UR                  S5      5      nX#4$ U nSnX#4$ )z{Returns ``(host, port)`` tuple from ``netloc``.

Returned ``port`` will be ``None`` if not present.

.. versionadded:: 4.1
r^   r:  N)
_netloc_rer  r  r   )r  r  r:   ports       rC   r   r     sT     V$E{{1~5;;q>" < <rB   qsc              #   Z   #    U R                  5        H  u  pU H  nX4v   M
     M     g7f)z_Generator converting a result of ``parse_qs`` back to name-value pairs.

.. versionadded:: 5.0
N)r|   )r  rg   vsrh   s       rC   	qs_to_qslr    s*     
 A&L  s   )+z\\(?:([0-3][0-7][0-7])|(.))r   c                 P    U S   (       a  [        [        U S   S5      5      $ U S   $ )Nr^      r:  )chrr   )r   s    rC   _unquote_replacer    s'    t3qtQ<  trB   c                 |    U b  [        U 5      S:  a  U $ U S   S:w  d	  U S   S:w  a  U $ U SS n [        [        U 5      $ )zHandle double quotes and escaping in cookie values.

This method is copied verbatim from the Python 3.13 standard
library (http.cookies._unquote) so we don't have to depend on
non-public interfaces.
r:  r   r  r   r^   )rb   _unquote_subr  )r  s    rC   _unquote_cookier    sO     	yCFQJts{aesl 	
!BA (!,,rB   cookiec                     0 nU R                  S5       H]  nSU;   a  UR                  SS5      u  p4OSUpCUR                  5       UR                  5       pCU(       d	  U(       d  MP  [        U5      X'   M_     U$ )aC  Parse a ``Cookie`` HTTP header into a dict of name/value pairs.

This function attempts to mimic browser cookie parsing behavior;
it specifically does not follow any of the cookie-related RFCs
(because browsers don't either).

The algorithm used is identical to that used by Django version 1.9.10.

.. versionadded:: 4.4.2
r\  r   r^   r   )rI   r   r  )r  
cookiedictr$  r  rY  s        rC   r   r     sn     Jc"%<{{3*HC 599;		S##-c2JO # rB   rR   )br)   ry  collections.abccollectionsr   r{  email.utilsr}  	functoolsr   http.clientr   http.cookiesr   r*   sslr   r   r  urllib.parser   r   r   r	   tornado.escaper
   r   r   r   tornado.utilr   r   r   r   r   r   r   r   r   r   r   r   r   r   TYPE_CHECKINGr   asyncior   unittestabcMutableMappingr   StrMutableMappingr   r+   rq   r   rL   rN   r   r   rp   r  r  r  r   rG  r   r   rT  rX  rN  r  r   r_  r  r?  rx  r  
NamedTupler   r  r   r  r  rl  r  r  r  r  r   r  subr  Matchr  r  r   r$   rB   rC   <module>r     s          !  	    C C G G 1
 
     
 $66sCx@#66   ZZ(KL 5 5p 4?C ?C ? ?`# `Fw4 w4t	Y 		i 	 :+ +\+$ +$\,	,
d38nd5c?3U5c?C;O5PP,
 	,^z  00eHSM8C=0120f*hsm *(3- * *PS *c hsm  &*+O+O
+O Ce$%+O T(^#$	+O
 k"+O 
+O\3939
39 Ce$%39 T(^#$	39
 
39l9c5%!1!183D3DDE990v(( 3 +; ,)) C ,= 4
3 
9S$_5 
   c4S>&9 :  F DcN s (2CJ2+0e+<2
2 " ZZ(
 c8C=.@(A "$sDL() huS&[7I.J  zz89== S -s -s -6 c3h rB   