403Webshell
Server IP : 54.37.205.81  /  Your IP : 216.73.216.76
Web Server : nginx/1.22.1
System : Linux vps-249481fa 6.1.0-50-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.176-1 (2026-07-02) x86_64
User : debian ( 1000)
PHP Version : 8.2.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/tornado/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/tornado/__pycache__/web.cpython-311.pyc
�

���i�&���dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Zddlm
Z
ddlmZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlm Z m!Z!ddlm"Z"ddlm#Z#dd	l$m%Z%dd
lm&Z&ddlm'Z'ddl(Zddlm)Z)dd
l*m+Z+m,Z,m-Z-ddl.Zddlm/Z/ddl0m1Z1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;ddl<m=Z=m>Z>m?Z?e:Z@ddlAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOddlmPZPddlAZAeAjQrddlAmRZReDeSe>eTejUejfZVeDeWeSeBeTeWfeBeTeSffZXdZY	dZZ	dZ[	dZ\	Gd�d��Z]e]��Z^ej_d��Z`Gd�dea��ZbeMdeb���ZcdeLecdeLecfd �ZddeLebdeefd!�Zfd"eId#eEeFdfdeId#eEeFdffd$�Zgd"eId#eEeFdfdeId#eEeFdffd%�ZhGd&�d'e9��ZiGd(�d)e7��ZjGd*�d+e&jk��ZlGd,�d-em��ZnGd.�d/em��ZoGd0�d1en��ZpGd2�d3eb��ZqGd4�d5eb��ZrGd6�d7eb��ZsGd8�d9eb��ZtGd:�d;ea��ZuGd<�d=eu��Zvd"eId#eEeFdfdeId#eEeFdffd>�ZwGd?�d@ea��ZxGdA�dBex��ZyGdC�dDex��ZzGdE�dFex��Z{GdG�dHea��Z|			d`dIeXdJeWdKeDeWeSfdLeEeTdMeEeIge}fdNeEeTdeSfdO�Z~ej_dP��ZdKeSdeTfdQ�Z�			dadIeXdJeWdKeDdeWeSfdSe}dMeEeIge}fdTeEeTdeEeSfdU�Z�dIeDeWeSfdJeWdKeSdSe}dMeIge}fdeEeSfdV�Z�dKeSdeGeTeSeSeSeSffdW�Z�dIeXdJeWdKeSdSe}dMeIge}fdeEeSfdX�Z�dKeDeWeSfdeEeTfdY�Z�dIeDeWeSfdZeDeWeSfdeSfd[�Z�dIeDeWeSfd\eSdeSfd]�Z�d^eWdeefd_�Z�dS)baT``tornado.web`` provides a simple web framework with asynchronous
features that allow it to scale to large numbers of open connections,
making it ideal for `long polling
<http://en.wikipedia.org/wiki/Push_technology#Long_polling>`_.

Here is a simple "Hello, world" example app:

.. testcode::

    import asyncio
    import tornado.web

    class MainHandler(tornado.web.RequestHandler):
        def get(self):
            self.write("Hello, world")

    async def main():
        application = tornado.web.Application([
            (r"/", MainHandler),
        ])
        application.listen(8888)
        await asyncio.Event().wait()

    if __name__ == "__main__":
        asyncio.run(main())

.. testoutput::
   :hide:


See the :doc:`guide` for additional information.

Thread-safety notes
-------------------

In general, methods on `RequestHandler` and elsewhere in Tornado are
not thread-safe. In particular, methods such as
`~RequestHandler.write()`, `~RequestHandler.finish()`, and
`~RequestHandler.flush()` must only be called from the main thread. If
you use multiple threads it is important to use `.IOLoop.add_callback`
to transfer control back to the main thread before finishing the
request, or to limit your use of other threads to
`.IOLoop.run_in_executor` and ensure that your callbacks running in
the executor do not refer to Tornado objects.

�N)�isclass)�BytesIO)�	urlencode)�Future�"future_set_result_unless_cancelled)�escape)�gen)�
HTTPServer)�httputil)�iostream)�locale)�
access_log�app_log�gen_log)�template)�utf8�_unicode)�
AnyMatches�DefaultHostMatches�HostMatches�ReversibleRouter�Rule�ReversibleRuleRouter�URLSpec�	_RuleList)�
ObjectDict�unicode_type�_websocket_mask)�Dict�Any�Union�Optional�	Awaitable�Tuple�List�Callable�Iterable�	Generator�Type�TypeVar�cast�overload)�
TracebackType)�Set��c��eZdZdS)�_ArgDefaultMarkerN)�__name__�
__module__�__qualname__���-/usr/lib/python3/dist-packages/tornado/web.pyr2r2�s�������Dr7r2z"(?:[\t ]|[\x21-\x7E]|[\x80-\xFF])+c�x��eZdZdZdZiZej��Ze	j
d��ZdZdZ
dZdZdddejd	ed
df�fd�Zd�d�ZeZ	ed
eeeffd
���Zded	ed
dfd�ZeZeZeZeZeZeZ eZ!d
e"e#dfd�Z$d�d�Z%d�d�Z&d�d�Z'd�d�Z(d�de)de"ed
dfd�Z*d
e)fd�Z+dede,d
dfd�Z-dede,d
dfd�Z.ded
dfd�Z/e	j
d��Z0de,d
efd�Z1e2d�ded!ed"e3d
efd#���Z4e2e5d fded!e6d"e3d
efd$���Z4e2	d�ded!dd"e3d
e"efd%���Z4e5d fded!e7dee6fd"e3d
e"efd&�Z4d�ded"e3d
e8efd'�Z9e5d fded!e7dee6fd"e3d
e"efd(�Z:d�ded"e3d
e8efd)�Z;e5d fded!e7dee6fd"e3d
e"efd*�Z<d�ded"e3d
e8efd+�Z=	d�ded!e7dee6fd,eee8e>fd"e3d
e"ef
d-�Z?	d�ded,eee8e>fd"e3d
e8efd.�Z@d�de>de"ed
efd/�ZAed
eeeBjCjDffd0���ZCd�ded!e"ed
e"efd1�ZE				d�dede7ee>fd3e"ed4e"e7eFeGeHjHfd5ed6e"eFd	ed
dfd7�ZI	d�ded5ed3e"ed
dfd8�ZJd�d5ed3e"ed
dfd9�ZK		d�dede7ee>fd6e"eFd;e"e)d	ed
dfd<�ZL	d�dede7ee>fd;e"e)d
e>fd=�ZM			d�dede"ed?eFd@e"e)d
e"e>f
dA�ZN	d�dede"ed
e"e)fdB�ZO	d�dCedDe3dEe"e)d
dfdF�ZPdGe7ee>eQfd
dfdH�ZRdIed	ed
dJfdK�ZSdLeTed
efdM�ZUdNeTe>d
e>fdO�ZVdPeTed
efdQ�ZWdReTe>d
e>fdS�ZXdIed	ed
e>fdT�ZYd
eeeffdU�ZZdVed
e[j\fdW�Z]d�dXe3d
dJfdY�Z^d�dGe"e7ee>eQfd
dJfdZ�Z_d
e`jafd[�Zbd�d\�Zcd�de)d	ed
dfd^�Zdde)d	ed
dfd_�Zeed
efjgjhfd`���Zgegjidefjgjhd
dfda���Zgd
e"efjgjhfdb�Zjd�d!ed
efjgjhfdd�Zked
efde���Zleljided
dfdf���Zld
efdg�Zmd
efdh�Znd
e"efdi�Zoed
e>fdj���Zpd
eGe"e)e>eFffdk�Zqdled
eGe"e)e"e>e"eFffdm�Zrd�dn�Zsd
efdo�Zt	d�d5edpe"e3d	ed
efdq�Zud�dedsed
dfdt�Zvdeded
efdu�Zwd
e"efdv�Zxd�dw�Zyd
e3fdx�Zzdye8dzde>d	e>d
dfd{�Z{dGe>d
e"e#dfd|�Z|d�d}�Z}d
efd~�Z~ded
dfd��Z�d�d�de"ed�e"e�d
dfd��Z�ded�e�d�d
e�d�effd��Z�d�e�d�efd
e�d�effd��Z�d�d��Z��xZ�S)��RequestHandleraFBase class for HTTP request handlers.

    Subclasses must define at least one of the methods defined in the
    "Entry points" section below.

    Applications should not construct `RequestHandler` objects
    directly and subclasses should not override ``__init__`` (override
    `~RequestHandler.initialize` instead).

    )�GET�HEAD�POST�DELETE�PATCH�PUT�OPTIONSz[\x00-\x08\x0e-\x1f]FN�application�Application�request�kwargs�returnc����t�����|�_|�_d�_d�_d�_d�_t�fd�|j	�
��D�����_t�|j
���jd<�jd�jd<�����jj�J��jj��j���jdi|��dS)NFTc3�L�K�|]\}}|��|��fV��dS�N)�
_ui_method)�.0�n�m�selfs   �r8�	<genexpr>z*RequestHandler.__init__.<locals>.<genexpr>�sI�����
�
�(,��1�Q�����"�"�#�
�
�
�
�
�
r7�_tt_modules�modulesr6)�super�__init__rBrD�_headers_written�	_finished�_auto_finish�_prepared_futurer�
ui_methods�items�ui�_UIModuleNamespace�
ui_modules�clear�
connection�set_close_callback�on_connection_close�
initialize)rNrBrDrE�	__class__s`   �r8rSzRequestHandler.__init__�s����	��������&������ %������ ��� $����
�
�
�
�0;�0F�0L�0L�0N�0N�
�
�
�
�
���"4�D�+�:P�!Q�!Q���
��!�W�]�3���	���
�
�����|�&�2�2�2����2�2��$�	
�	
�	
�	���!�!�&�!�!�!�!�!r7c��dSrIr6�rNs r8�_initializezRequestHandler._initialize�����r7c��|jjS)z@An alias for `self.application.settings <Application.settings>`.)rB�settingsrds r8rhzRequestHandler.settingss����(�(r7�argsc� �td���)N�)�	HTTPError�rNrirEs   r8�_unimplemented_methodz$RequestHandler._unimplemented_methods����n�n�r7c��dS)a�Called at the beginning of a request before  `get`/`post`/etc.

        Override this method to perform common initialization regardless
        of the request method.

        Asynchronous support: Use ``async def`` or decorate this method with
        `.gen.coroutine` to make it asynchronous.
        If this method returns an  ``Awaitable`` execution will not proceed
        until the ``Awaitable`` is done.

        .. versionadded:: 3.1
           Asynchronous support.
        Nr6rds r8�preparezRequestHandler.prepares	��	
�r7c��dS)aCalled after the end of a request.

        Override this method to perform cleanup, logging, etc.
        This method is a counterpart to `prepare`.  ``on_finish`` may
        not produce any output, as it is called after the response
        has been sent to the client.
        Nr6rds r8�	on_finishzRequestHandler.on_finish+�	��	
�r7c��t|j��rn|jj���sR|jj�t
j����|jj���dSdSdS)aFCalled in async handlers if the client closed the connection.

        Override this to clean up resources associated with
        long-lived connections.  Note that this method is called only if
        the connection was closed during asynchronous processing; if you
        need to do cleanup after every request override `on_finish`
        instead.

        Proxies may keep a connection open for a time (perhaps
        indefinitely) after the client has gone away, so this method
        may not be called promptly after the end user closes their
        connection.
        N)	�_has_stream_request_bodyrbrD�_body_future�done�
set_exceptionr�StreamClosedError�	exceptionrds r8r`z"RequestHandler.on_connection_close5s���$�D�N�3�3�	6��<�,�1�1�3�3�
6���)�7�7��8R�8T�8T�U�U�U���)�3�3�5�5�5�5�5�	6�	6�
6�
6r7c��tjdtjzdtjtj����d���|_|���g|_d|_	tj
d|_dS)z1Resets all headers and content for this response.zTornadoServer/%sztext/html; charset=UTF-8)�Server�Content-Type�Date��N)r�HTTPHeaders�tornado�version�format_timestamp�time�_headers�set_default_headers�
_write_buffer�_status_code�	responses�_reasonrds r8r]zRequestHandler.clearHsx�� �,�,�w��>� :� �1�$�)�+�+�>�>�
�
�
�
��
�	
� � �"�"�"��������)�#�.����r7c��dS)aBOverride this to set HTTP headers at the beginning of the request.

        For example, this is the place to set a custom ``Server`` header.
        Note that setting such headers in the normal flow of request
        processing may not do what you want, since headers may be reset
        during error handling.
        Nr6rds r8r�z"RequestHandler.set_default_headersVrsr7�status_code�reasonc���||_|�;d|vst�|��sd}tj|��|_dStj�|d��|_dS)a6Sets the status code for our response.

        :arg int status_code: Response status code.
        :arg str reason: Human-readable reason phrase describing the status
            code (for example, the "Not Found" in ``HTTP/1.1 404 Not Found``).
            Normally determined automatically from `http.client.responses`; this
            argument should only be used if you need to use a non-standard
            status code.

        .. versionchanged:: 5.0

           No longer validates that the response code is in
           `http.client.responses`.
        N�<�Unknown)	r��reason_phrase_re�	fullmatchr�
native_strr�rr��get)rNr�r�s   r8�
set_statuszRequestHandler.set_status`si��(������f�}�}�$4�$>�$>�v�$F�$F�}�#��!�,�V�4�4�D�L�L�L�#�-�1�1�+�y�I�I�D�L�L�Lr7c��|jS)z)Returns the status code for our response.)r�rds r8�
get_statuszRequestHandler.get_status}s��� � r7�name�valuec�@�|�|��|j|<dS)z�Sets the given response header name and value.

        All header values are converted to strings (`datetime` objects
        are formatted according to the HTTP specification for the
        ``Date`` header).

        N)�_convert_header_valuer��rNr�r�s   r8�
set_headerzRequestHandler.set_header�s$��#�8�8��?�?��
�d���r7c�b�|j�||�|����dS)z�Adds the given response header and value.

        Unlike `set_header`, `add_header` may be called multiple times
        to return multiple values for the same header.
        N)r��addr�r�s   r8�
add_headerzRequestHandler.add_header�s0��	
�
���$�� :� :�5� A� A�B�B�B�B�Br7c�,�||jvr
|j|=dSdS)z�Clears an outgoing header, undoing a previous `set_header` call.

        Note that this method does not apply to multi-valued headers
        set by `add_header`.
        N)r�)rNr�s  r8�clear_headerzRequestHandler.clear_header�s)���4�=� � ��
�d�#�#�#�!� r7z[\x00-\x1f]c��t|t��r|}n�t|t��r|�d��}nit|tj��rt|��St|tj��rtj|��Std|z���tj�|��rtd|���|S)N�latin1zUnsupported header value %rzUnsafe header value %r)�
isinstance�str�bytes�decode�numbers�Integral�datetimerr��	TypeErrorr:�_INVALID_HEADER_CHAR_RE�search�
ValueError)rNr��retvals   r8r�z$RequestHandler._convert_header_value�s���
�e�S�!�!�	C��F�F�
��u�
%�
%�
	C��\�\�(�+�+�F�F�
��w�/�
0�
0�	C��u�:�:��
��x�0�
1�
1�	C��,�U�3�3�3��9�E�A�B�B�B��1�8�8��@�@�	?��5�v�>�>�>��
r7T�default�stripc��dSrIr6�rNr�r�r�s    r8�get_argumentzRequestHandler.get_argument�����r7c��dSrIr6r�s    r8r�zRequestHandler.get_argument��	��	
�r7c��dSrIr6r�s    r8r�zRequestHandler.get_argument�r�r7c�F�|�|||jj|��S)arReturns the value of the argument with the given name.

        If default is not provided, the argument is considered to be
        required, and we raise a `MissingArgumentError` if it is missing.

        If the argument appears in the request more than once, we return the
        last value.

        This method searches both the query and body arguments.
        )�
_get_argumentrD�	argumentsr�s    r8r�zRequestHandler.get_argument�s#�� �!�!�$����1G��O�O�Or7c�r�t|t��sJ�|�||jj|��S)z�Returns a list of the arguments with the given name.

        If the argument is not present, returns an empty list.

        This method searches both the query and body arguments.
        )r��bool�_get_argumentsrDr��rNr�r�s   r8�
get_argumentszRequestHandler.get_arguments�s7���%��&�&�&�&�&��"�"�4���)?��G�G�Gr7c�F�|�|||jj|��S)ajReturns the value of the argument with the given name
        from the request body.

        If default is not provided, the argument is considered to be
        required, and we raise a `MissingArgumentError` if it is missing.

        If the argument appears in the url more than once, we return the
        last value.

        .. versionadded:: 3.2
        )r�rD�body_argumentsr�s    r8�get_body_argumentz RequestHandler.get_body_argument�s#��"�!�!�$����1L�e�T�T�Tr7c�D�|�||jj|��S)z�Returns a list of the body arguments with the given name.

        If the argument is not present, returns an empty list.

        .. versionadded:: 3.2
        )r�rDr�r�s   r8�get_body_argumentsz!RequestHandler.get_body_arguments�s!���"�"�4���)D�e�L�L�Lr7c�F�|�|||jj|��S)arReturns the value of the argument with the given name
        from the request query string.

        If default is not provided, the argument is considered to be
        required, and we raise a `MissingArgumentError` if it is missing.

        If the argument appears in the url more than once, we return the
        last value.

        .. versionadded:: 3.2
        )r�rD�query_argumentsr�s    r8�get_query_argumentz!RequestHandler.get_query_arguments#��"�!�!�$����1M�u�U�U�Ur7c�D�|�||jj|��S)z�Returns a list of the query arguments with the given name.

        If the argument is not present, returns an empty list.

        .. versionadded:: 3.2
        )r�rDr�r�s   r8�get_query_argumentsz"RequestHandler.get_query_argumentss!���"�"�4���)E�u�M�M�Mr7�sourcec��|�|||���}|s&t|t��rt|���|S|dS)N)r����)r�r�r2�MissingArgumentError)rNr�r�r�r�ris      r8r�zRequestHandler._get_argumentsU���"�"�4��u�"�=�=���	��'�#4�5�5�
1�*�4�0�0�0��N��B�x�r7c�*�g}|�|g��D]y}|�||���}t|t��r tj�d|��}|r|���}|�|���z|S)N�r�� )	r��decode_argumentr�rr:�_remove_control_chars_regex�subr��append)rNr�r�r��values�v�ss       r8r�zRequestHandler._get_arguments-s��������D�"�%�%�	�	�A��$�$�Q�T�$�2�2�A��!�\�*�*�
K�#�>�B�B�3��J�J���
��G�G�I�I���M�M�!������
r7c
�~�	t|��S#t$r!tdd|pd�d|dd������wxYw)aDecodes an argument from the request.

        The argument has been percent-decoded and is now a byte string.
        By default, this method decodes the argument as utf-8 and returns
        a unicode string, but this may be overridden in subclasses.

        This method is used as a filter for both `get_argument()` and for
        values extracted from the url and passed to `get()`/`post()`/etc.

        The name of the argument is provided if known, but may be None
        (e.g. for unnamed groups in the url regex).
        �zInvalid unicode in �url�: N�()r�UnicodeDecodeErrorrl)rNr�r�s   r8r�zRequestHandler.decode_argument<s^��	��E�?�?�"��!�	�	�	����D�M�E�M�M�5��"��:�:�N���
�	���s��+<c��|jjS)zRAn alias for
        `self.request.cookies <.httputil.HTTPServerRequest.cookies>`.)rD�cookiesrds r8r�zRequestHandler.cookiesPs���|�#�#r7c�h�|jj�%||jjvr|jj|jS|S)a-Returns the value of the request cookie with the given name.

        If the named cookie is not present, returns ``default``.

        This method only returns cookies that were present in the request.
        It does not see the outgoing cookies set by `set_cookie` in this
        handler.
        )rDr�r�)rNr�r�s   r8�
get_cookiezRequestHandler.get_cookieVs6���<��+����8L�0L�0L��<�'��-�3�3��r7�/�domain�expires�path�expires_daysc��tj|��}tj|��}tjd||z��rt	d|�d|�����t|d��s#tj���|_	||j	vr|j	|=||j	|<|j	|}|r||d<|�6|s4tj
���tj|���z}|rtj|��|d<|r||d	<|���D]\}	}
|	d
krd}	|	dvr|
s�|
||	<�dS)
a1Sets an outgoing cookie name/value with the given options.

        Newly-set cookies are not immediately visible via `get_cookie`;
        they are not present until the next request.

        expires may be a numeric timestamp as returned by `time.time`,
        a time tuple as returned by `time.gmtime`, or a
        `datetime.datetime` object.

        Additional keyword arguments are set on the cookies.Morsel
        directly.
        See https://docs.python.org/3/library/http.cookies.html#http.cookies.Morsel
        for available attributes.
        z[\x00-\x20]zInvalid cookie r��_new_cookier�N��daysr�r��max_agezmax-age)�httponly�secure)rr��rer�r��hasattr�httpr��SimpleCookier�r��utcnow�	timedeltarr�rY)rNr�r�r�r�r�r�rE�morsel�kr�s           r8�
set_cookiezRequestHandler.set_cookiecs��2� ��&�&���!�%�(�(��
�9�^�T�E�\�2�2�	F��*����e�e�D�E�E�E��t�]�+�+�	���)�)�+�+�
���4�#�#�#�� ��&�!&������!�$�'���	&�%�F�8���#�G�#��'�.�.�0�0�8�3E�<�3X�3X�3X�X�G��	C� (� 9�'� B� B�F�9���	"�!�F�6�N��L�L�N�N�		�		�D�A�q��I�~�~����*�*�*�1�*���F�1�I�I�		�		r7c��tj���tjd���z
}|�|d|||���dS)a�Deletes the cookie with the given name.

        Due to limitations of the cookie protocol, you must pass the same
        path and domain to clear a cookie as were used when that cookie
        was set (but there is no way to find out on the server side
        which values were used for a given cookie).

        Similar to `set_cookie`, the effect of this method will not be
        seen until the following request.
        imr��)r�r�r�r�N)r�r�r�r�)rNr�r�r�r�s     r8�clear_cookiezRequestHandler.clear_cookie�sM���#�*�*�,�,�x�/A�s�/K�/K�/K�K������B�T�7�6��R�R�R�R�Rr7c�T�|jjD]}|�|||����dS)ajDeletes all the cookies the user sent with this request.

        See `clear_cookie` for more information on the path and domain
        parameters.

        Similar to `set_cookie`, the effect of this method will not be
        seen until the following request.

        .. versionchanged:: 3.2

           Added the ``path`` and ``domain`` parameters.
        )r�r�N)rDr�r�)rNr�r�r�s    r8�clear_all_cookiesz RequestHandler.clear_all_cookies�s@���L�(�	>�	>�D����d��f��=�=�=�=�	>�	>r7�r�c�T�|j||�|||���fd|i|��dS)a�Signs and timestamps a cookie so it cannot be forged.

        You must specify the ``cookie_secret`` setting in your Application
        to use this method. It should be a long, random sequence of bytes
        to be used as the HMAC secret for the signature.

        To read a cookie set with this method, use `get_secure_cookie()`.

        Note that the ``expires_days`` parameter sets the lifetime of the
        cookie in the browser, but is independent of the ``max_age_days``
        parameter to `get_secure_cookie`.
        A value of None limits the lifetime to the current browser session.

        Secure cookies may contain arbitrary byte values, not just unicode
        strings (unlike regular cookies)

        Similar to `set_cookie`, the effect of this method will not be
        seen until the following request.

        .. versionchanged:: 3.2.1

           Added the ``version`` argument.  Introduced cookie version 2
           and made it the default.
        )r�r�N)r��create_signed_value)rNr�r�r�r�rEs      r8�set_secure_cookiez RequestHandler.set_secure_cookie�sY��@	�����$�$�T�5�'�$�B�B�	
�	
�&�	
��		
�	
�	
�	
�	
r7c�(�|�dd��|jjd}d}t|t��r@|jj�d���t
d���|jjd}t|||||���S)a�Signs and timestamps a string so it cannot be forged.

        Normally used via set_secure_cookie, but provided as a separate
        method for non-cookie uses.  To decode a value not stored
        as a cookie use the optional value argument to get_secure_cookie.

        .. versionchanged:: 3.2.1

           Added the ``version`` argument.  Introduced cookie version 2
           and made it the default.
        �
cookie_secret�secure cookiesN�key_versionz5key_version setting must be used for secret_key dicts)r�r)�require_settingrBrhr��dictr��	Exceptionr)rNr�r�r��secretrs      r8rz"RequestHandler.create_signed_value�s���	
���_�.>�?�?�?��!�*�?�;�����f�d�#�#�	C���(�,�,�]�;�;�C�� W�X�X�X��*�3�M�B�K�"��D�%��k�
�
�
�	
r7��max_age_days�min_versionc��|�dd��|�|�|��}t|jjd||||���S)a
Returns the given signed cookie if it validates, or None.

        The decoded cookie value is returned as a byte string (unlike
        `get_cookie`).

        Similar to `get_cookie`, this method only returns cookies that
        were present in the request. It does not see outgoing cookies set by
        `set_secure_cookie` in this handler.

        .. versionchanged:: 3.2.1

           Added the ``min_version`` argument.  Introduced cookie version 2;
           both versions 1 and 2 are accepted by default.
        rrN)rr)rr��decode_signed_valuerBrh)rNr�r�rrs     r8�get_secure_cookiez RequestHandler.get_secure_cookie�sb��*	
���_�.>�?�?�?��=��O�O�D�)�)�E�"���%�o�6���%�#�
�
�
�	
r7c��|�dd��|�|�|��}|�dSt|��S)zgReturns the signing key version of the secure cookie.

        The version is returned as int.
        rrN)rr��get_signature_key_versionr�s   r8�get_secure_cookie_key_versionz,RequestHandler.get_secure_cookie_key_versionsI��	
���_�.>�?�?�?��=��O�O�D�)�)�E��=��4�(��/�/�/r7r��	permanent�statusc�(�|jrtd���|�|rdnd}n&t|t��rd|cxkrdksnJ�|�|��|�dt
|����|���dS)a:Sends a redirect to the given (optionally relative) URL.

        If the ``status`` argument is specified, that value is used as the
        HTTP status code; otherwise either 301 (permanent) or 302
        (temporary) is chosen based on the ``permanent`` argument.
        The default is 302 (temporary).
        z/Cannot redirect after headers have been writtenNi-i.i,i��Location)rTrr��intr�r�r�finish)rNr�rrs    r8�redirectzRequestHandler.redirect+s���� �	O��M�N�N�N��>�%�.�S�S�3�F�F��f�c�*�*�C�s�f�/C�/C�/C�/C��/C�/C�/C�/C�/C�/C�����������
�D��I�I�.�.�.����
�
�
�
�
r7�chunkc��|jrtd���t|ttt
f��s+d}t|t��r|dz
}t|���t|t
��r*tj	|��}|�
dd��t|��}|j�
|��dS)a�Writes the given chunk to the output buffer.

        To write the output to the network, use the `flush()` method below.

        If the given chunk is a dictionary, we write it as JSON and set
        the Content-Type of the response to be ``application/json``.
        (if you want to send JSON as a different ``Content-Type``, call
        ``set_header`` *after* calling ``write()``).

        Note that lists are not converted to JSON because of a potential
        cross-site security vulnerability.  All JSON output should be
        wrapped in a dictionary.  More details at
        http://haacked.com/archive/2009/06/25/json-hijacking.aspx/ and
        https://github.com/facebook/tornado/issues/1009
        zCannot write() after finish()z5write() only accepts bytes, unicode, and dict objectsz|. Lists not accepted for security reasons; see http://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.writer}zapplication/json; charset=UTF-8N)rU�RuntimeErrorr�r�rr�listr�r�json_encoder�rr�r�)rNr�messages   r8�writezRequestHandler.write?s��� �>�	@��>�?�?�?��%�%��t�!<�=�=�	%�M�G��%��&�&�
��f����G�$�$�$��e�T�"�"�	O��&�u�-�-�E��O�O�N�,M�N�N�N��U������!�!�%�(�(�(�(�(r7�
template_namezFuture[None]c���|jrtd���|j|fi|��}g}g}g}g}g}g}	t|di�����D�]�}
|
���}|r"|�t|����|
���}|rTt|ttf��r#|�t|����n|�
|��|
���}|r"|�t|����|
���}|rTt|ttf��r#|�t|����n|�
|��|
���}
|
r"|�t|
����|
���}|r"|	�t|�������|rR|�|��}|�d��}|d|�t|��zdz||d�z}|rE|�|��}|�d��}|d|�|zdz||d�z}|rR|�|��}|�d��}|d|�t|��zdz||d�z}|rE|�|��}|�d��}|d|�|zdz||d�z}|rC|�d��}|d|�d�|��zdz||d�z}|	rC|�d��}|d|�d�|	��zdz||d�z}|�|��S)a�Renders the template with the given arguments as the response.

        ``render()`` calls ``finish()``, so no other output methods can be called
        after it.

        Returns a `.Future` with the same semantics as the one returned by `finish`.
        Awaiting this `.Future` is optional.

        .. versionchanged:: 5.1

           Now returns a `.Future` instead of ``None``.
        zCannot render() after finish()�_active_moduless</body>N�
s</head>r7)rUr�
render_string�getattrr��embedded_javascriptr�r�javascript_filesr�rr�r�extend�embedded_css�	css_files�	html_head�	html_body�render_linked_js�rindex�render_embed_js�render_linked_css�index�render_embed_css�joinr)rNr!rE�html�js_embed�js_files�	css_embedr+�
html_heads�html_bodies�module�
embed_part�	file_part�	head_part�	body_part�js�sloc�js_bytes�css�hloc�	css_bytess                     r8�renderzRequestHandler.render_s���>�	A��?�@�@�@�!�t�!�-�:�:�6�:�:�������	��	��
����d�$5�r�:�:�A�A�C�C�	4�	4�F��3�3�5�5�J��
2�����Z� 0� 0�1�1�1��/�/�1�1�I��
/��i�,��)>�?�?�/��O�O�H�Y�$7�$7�8�8�8�8��O�O�I�.�.�.��,�,�.�.�J��
3�� � ��j�!1�!1�2�2�2��(�(�*�*�I��
0��i�,��)>�?�?�0��$�$�X�i�%8�%8�9�9�9�9��$�$�Y�/�/�/��(�(�*�*�I��
3��!�!�$�y�/�/�2�2�2��(�(�*�*�I��
4��"�"�4�	�?�?�3�3�3���	@��&�&�x�0�0�B��;�;�z�*�*�D�����;��b���)�E�1�D����K�?�D��	@��+�+�H�5�5�H��;�;�z�*�*�D�����;��)�E�1�D����K�?�D��	A��(�(��3�3�C��:�:�j�)�)�D�����;��c���*�U�2�T�$�%�%�[�@�D��	A��-�-�i�8�8�I��:�:�j�)�)�D�����;��*�U�2�T�$�%�%�[�@�D��	L��:�:�j�)�)�D�����;����*�!5�!5�5��=��T�U�U��K�D��	M��:�:�j�)�)�D�����;����+�!6�!6�6��>��d�e�e��L�D��{�{�4� � � r7r7c��g}t��}|D]T}t|��s|�|��}||vr*|�|��|�|���Ud�d�|D����S)z�Default method used to render the final js links for the
        rendered webpage.

        Override this method in a sub-classed controller to change the output.
        r�c3�JK�|]}dtj|��zdzV��dS)z
<script src="z"" type="text/javascript"></script>N�r�xhtml_escape�rK�ps  r8rOz2RequestHandler.render_linked_js.<locals>.<genexpr>�sS����
�
��
��!�!�$�$�
%�2�
3�
�
�
�
�
�
r7��set�is_absolute�
static_urlr�r�r4)rNr7�paths�unique_pathsr�s     r8r.zRequestHandler.render_linked_js�s������u�u���	'�	'�D��t�$�$�
-����t�,�,���<�'�'����T�"�"�"�� � ��&�&�&���w�w�
�
��	
�
�
�
�
�	
r7r6c�8�dd�|��zdzS)z�Default method used to render the final embedded js for the
        rendered webpage.

        Override this method in a sub-classed controller to change the output.
        s,<script type="text/javascript">
//<![CDATA[
r$s
//]]>
</script>�r4)rNr6s  r8r0zRequestHandler.render_embed_js�s(��
>��j�j��"�"�
#�#�
$�	
r7r+c��g}t��}|D]T}t|��s|�|��}||vr*|�|��|�|���Ud�d�|D����S)z�Default method used to render the final css links for the
        rendered webpage.

        Override this method in a sub-classed controller to change the output.
        r�c3�JK�|]}dtj|��zdzV��dS)z<link href="z$" type="text/css" rel="stylesheet"/>NrIrKs  r8rOz3RequestHandler.render_linked_css.<locals>.<genexpr>�sR����
�
��
�V�0��3�3�3�71�
1�
�
�
�
�
�
r7rM)rNr+rQrRr�s     r8r1z RequestHandler.render_linked_css�s������u�u���	'�	'�D��t�$�$�
-����t�,�,���<�'�'����T�"�"�"�� � ��&�&�&���w�w�
�
��
�
�
�
�
�	
r7r8c�8�dd�|��zdzS)z�Default method used to render the final embedded css for the
        rendered webpage.

        Override this method in a sub-classed controller to change the output.
        s<style type="text/css">
r$s	
</style>rT)rNr8s  r8r3zRequestHandler.render_embed_css�s ��,�e�j�j��.C�.C�C�m�S�Sr7c��|���}|s�tjd��}|jj}|jj|kr%|j�|j}|jj|kr|j�|jj�J�tj�|jj��}tj
5|tjvr%|�|��}|tj|<ntj|}ddd��n#1swxYwY|�
|��}|���}|�|��|jdi|��S)z�Generate the given template with the given arguments.

        We return the generated byte string (in utf8). To generate and
        write a template as a response, use render() above.
        rNr6)�get_template_path�sys�	_getframe�f_code�co_filename�f_back�osr��dirnamer:�_template_loader_lock�_template_loaders�create_template_loader�load�get_template_namespace�update�generate)	rNr!rE�
template_path�frame�web_file�loader�t�	namespaces	         r8r%zRequestHandler.render_string�s����.�.�0�0�
��	F��M�!�$�$�E��|�/�H��,�*�h�6�6�5�<�;S�����,�*�h�6�6�5�<�;S��<�+�7�7�7��G�O�O�E�L�,D�E�E�M�
�
1�	I�	I��N�$D�D�D��4�4�]�C�C��BH��0��?�?�'�9�-�H��	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I����	I�	I�	I�	I�
�K�K�
�&�&���/�/�1�1�	����� � � ��q�z�&�&�I�&�&�&s�/AD�D�Dc���t||j|j|j|jj|jj|j|j|j��	�	}|�	|j
��|S)aBReturns a dictionary to be used as the default template namespace.

        May be overridden by subclasses to add or modify values.

        The results of this method will be combined with additional
        defaults in the `tornado.template` module and keyword arguments
        to `render` or `render_string`.
        )	�handlerrD�current_userr
�_�pgettextrP�xsrf_form_html�reverse_url)rrDrpr
�	translaterrrPrsrtrfrZ)rNrms  r8rez%RequestHandler.get_template_namespacesj�����L��*��;��k�#��[�)����.��(�

�

�

�	�	�����!�!�!��r7rhc��|jj}d|vr|dSi}d|vr|d|d<d|vr|d|d<tj|fi|��S)a]Returns a new template loader for the given path.

        May be overridden by subclasses.  By default returns a
        directory-based loader on the given path, using the
        ``autoescape`` and ``template_whitespace`` application
        settings.  If a ``template_loader`` application setting is
        supplied, uses that instead.
        �template_loader�
autoescape�template_whitespace�
whitespace)rBrhr�Loader)rNrhrhrEs    r8rcz%RequestHandler.create_template_loadersz���#�,����(�(��-�.�.����8�#�#�$,�L�#9�F�<� � �H�,�,�#+�,A�#B�F�<� ���}�7�7��7�7�7r7�include_footersc�:�|jj�J�d�|j��}g|_|js�d|_|jD]6}|�J�|�|j|j||��\|_|_}�7|jj	dkrd}t|d��rE|j���D]+}|�
d|�d�����,tjd|j|j��}|jj�||j|��S|jD]}|�||��}�|jj	dkr|jj�|��St+��}|�d��|S)z�Flushes the current output buffer to the network.

        .. versionchanged:: 4.0
           Now returns a `.Future` if no callback is given.

        .. versionchanged:: 6.0

           The ``callback`` argument was removed.
        Nr7Tr<r�z
Set-Cookier�)rDr^r4r�rT�_transforms�transform_first_chunkr�r��methodr�r�r�r��OutputStringr�ResponseStartLiner��
write_headers�transform_chunkr r�
set_result)rNr|r�	transform�cookie�
start_line�futures       r8�flushzRequestHandler.flush1s����|�&�2�2�2�����+�,�,������$�#	�$(�D�!�!�-�
�
�	��(�(�(�
�3�3��%�t�}�e�_���	��%��M��E�
�|�"�f�,�,���
�t�]�+�+�
M�"�.�5�5�7�7�M�M�F��O�O�L�&�2E�2E�d�2K�2K�L�L�L�L�!�3�B��8I�4�<�X�X�J��<�*�8�8��D�M�5���
�"�-�
J�
J�	�!�1�1�%��I�I����|�"�f�,�,��|�.�4�4�U�;�;�;������!�!�$�'�'�'��
r7c��|jrtd���|�|�|��|js�|jdkr[|jjdvrMd|jvrD|���|�	��rg|_
|�d��|jdvsd|jcxkrdkr1nn.|j
rJd	|jz���|���n=d
|jvr4td�|j
D����}|�d
|��|jj�J�|jj�d��|�d�
��}|jj���|���d|_|���|���|S)aDFinishes this response, ending the HTTP request.

        Passing a ``chunk`` to ``finish()`` is equivalent to passing that
        chunk to ``write()`` and then calling ``finish()`` with no arguments.

        Returns a `.Future` which may optionally be awaited to track the sending
        of the response to the client. This `.Future` resolves when all the response
        data has been sent, and raises an error if the connection is closed before all
        data can be sent.

        .. versionchanged:: 5.1

           Now returns a `.Future` instead of ``None``.
        zfinish() called twiceNr�r;r<�Etag�0)��r��dzCannot send body with %s�Content-Lengthc3�4K�|]}t|��V��dSrI)�len)rK�parts  r8rOz(RequestHandler.finish.<locals>.<genexpr>�s(����$N�$N�4�S��Y�Y�$N�$N�$N�$N�$N�$Nr7T)r|)rUrr rTr�rDr�r��set_etag_header�check_etag_headerr�r��_clear_representation_headers�sumr�r^r_r�r�_logrr�
_break_cycles)rNr�content_lengthr�s    r8rzRequestHandler.finishcs����>�	8��6�7�7�7����J�J�u�����$�	B��!�S�(�(��L�'�?�:�:��$�-�/�/��$�$�&�&�&��)�)�+�+�)�)+�D�&��O�O�C�(�(�(�� �J�.�.�3�$�:K�3Q�3Q�3Q�3Q�c�3Q�3Q�3Q�3Q�3Q��-���.��1B�B�����2�2�4�4�4�4�!���6�6�!$�$N�$N�4�;M�$N�$N�$N�!N�!N����� 0�.�A�A�A��|�&�2�2�2�
	
���2�2�4�8�8�8����D��1�1�����&�&�(�(�(��	�	��������������������
r7c�L�d|_|jj���S)aNTake control of the underlying stream.

        Returns the underlying `.IOStream` object and stops all
        further HTTP processing. Intended for implementing protocols
        like websockets that tunnel over an HTTP handshake.

        This method is only supported when HTTP/1.1 is used.

        .. versionadded:: 5.1
        T)rUrDr^�detachrds r8r�zRequestHandler.detach�s"������|�&�-�-�/�/�/r7c��d|_dSrI)rZrds r8r�zRequestHandler._break_cycles�s������r7��c�b�|jrYtjd��|js<	|���n&#t
$rtjdd���YnwxYwdS|���|�d��}d|vr1|dd}t|t��r|j
r|j
}|�||�	��	|d
kr|j|fi|��n&#t
$rtjdd���YnwxYw|js|���dSdS)a�Sends the given HTTP error code to the browser.

        If `flush()` has already been called, it is not possible to send
        an error, so this method will simply terminate the response.
        If output has been written but not yet flushed, it will be discarded
        and replaced with the error page.

        Override `write_error()` to customize the error page that is returned.
        Additional keyword arguments are passed through to `write_error`.
        z0Cannot send error response after headers writtenz Failed to flush partial responseT��exc_infoNr�r�r/)r�r�z!Uncaught exception in write_error)rTr�errorrUrrr]r�r�rlr�r��write_errorr)rNr�rEr�rzs     r8�
send_errorzRequestHandler.send_error�s��� �	��M�L�M�M�M��>�
U�
U��K�K�M�M�M�M�� �U�U�U��M�"D�t�T�T�T�T�T�T�U�����F��
�
�������H�%�%�������z�*�1�-�I��)�Y�/�/�
*�I�4D�
*�"�)������F��3�3�3�	N��c�!�!� �� ��7�7��7�7�7����	N�	N�	N��M�=��M�M�M�M�M�M�	N�����~�	��K�K�M�M�M�M�M�	�	s!�9� A�A�C,�, D�Dc�V�|j�d��r\d|vrX|�dd��tj|d�D]}|�|���|���dS|�d|tj|j	��d�z��dS)a�Override to implement custom error pages.

        ``write_error`` may call `write`, `render`, `set_header`, etc
        to produce output as usual.

        If this error was caused by an uncaught exception (including
        HTTPError), an ``exc_info`` triple will be available as
        ``kwargs["exc_info"]``.  Note that this exception may not be
        the "current" exception for purposes of methods like
        ``sys.exc_info()`` or ``traceback.format_exc``.
        �serve_tracebackr�r}�
text/plainzS<html><title>%(code)d: %(message)s</title><body>%(code)d: %(message)s</body></html>)�coderN)
rhr�r��	traceback�format_exceptionr rrrJr�)rNr�rE�lines    r8r�zRequestHandler.write_error�s����=���.�/�/�	�J�&�4H�4H��O�O�N�L�9�9�9�!�2�F�:�4F�G�
!�
!���
�
�4� � � � ��K�K�M�M�M�M�M��K�K�<�&�6�3F�t�|�3T�3T�U�U�V�
�
�
�
�
r7c��t|d��s@|���}|�||_n"|���|_|jsJ�|jS)a^The locale for the current session.

        Determined by either `get_user_locale`, which you can override to
        set the locale based on, e.g., a user preference stored in a
        database, or `get_browser_locale`, which uses the ``Accept-Language``
        header.

        .. versionchanged: 4.1
           Added a property setter.
        �_locale)r��get_user_localer��get_browser_locale)rN�locs  r8r
zRequestHandler.locale�s^���t�Y�'�'�	$��&�&�(�(�C���"����#�6�6�8�8����|�#�#�#��|�r7c��||_dSrI)r��rNr�s  r8r
zRequestHandler.locales
������r7c��dS)aOverride to determine the locale from the authenticated user.

        If None is returned, we fall back to `get_browser_locale()`.

        This method should return a `tornado.locale.Locale` object,
        most likely obtained via a call like ``tornado.locale.get("en")``
        Nr6rds r8r�zRequestHandler.get_user_locale	s	���tr7�en_USc���d|jjv�rJ|jjd�d��}g}|D]�}|����d��}t	|��dkr�|d����d��r^	t
|d���dd���}|dkrt���n#ttf$rd	}YnwxYwd
}|dkr|�	|d|f����|r2|�
d�d�
��d�|D��}tj|�Stj|��S)z�Determines the user's locale from ``Accept-Language`` header.

        See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
        zAccept-Language�,�;r/zq=r0Nrgg�?c��|dS)Nr/r6)�pairs r8�<lambda>z3RequestHandler.get_browser_locale.<locals>.<lambda>)s
��d�1�g�r7T)�key�reversec��g|]
}|d��S)rr6)rKr�s  r8�
<listcomp>z5RequestHandler.get_browser_locale.<locals>.<listcomp>*s��3�3�3�C��Q��3�3�3r7)
rD�headers�splitr�r��
startswith�floatr�r�r��sortr
r�)rNr��	languages�locales�language�parts�score�codess        r8r�z!RequestHandler.get_browser_localesz��
��� 4�4�4���,�->�?�E�E�c�J�J�I��G�%�
6�
6�� ���(�(�.�.�s�3�3���u�:�:��>�>�e�A�h�n�n�&6�&6�&A�&A�$�&G�&G�>�$� %�e�A�h�n�n�&6�&6�q�r�r�&:� ;� ;�� �1�9�9�",�,�,�.�%��&�	�2�$�$�$� #����$���� �E��1�9�9��N�N�E�!�H�e�#4�5�5�5���
*����!5�!5�t��D�D�D�3�3�7�3�3�3���z�5�)�)��z�'�"�"�"s�#AC'�'C=�<C=c�b�t|d��s|���|_|jS)a�The authenticated user for this request.

        This is set in one of two ways:

        * A subclass may override `get_current_user()`, which will be called
          automatically the first time ``self.current_user`` is accessed.
          `get_current_user()` will only be called once per request,
          and is cached for future access::

              def get_current_user(self):
                  user_cookie = self.get_secure_cookie("user")
                  if user_cookie:
                      return json.loads(user_cookie)
                  return None

        * It may be set as a normal variable, typically from an overridden
          `prepare()`::

              @gen.coroutine
              def prepare(self):
                  user_id_cookie = self.get_secure_cookie("user_id")
                  if user_id_cookie:
                      self.current_user = yield load_user(user_id_cookie)

        Note that `prepare()` may be a coroutine while `get_current_user()`
        may not, so the latter form is necessary if loading the user requires
        asynchronous operations.

        The user object may be any type of the application's choosing.
        �
_current_user)r��get_current_userr�rds r8rpzRequestHandler.current_user.s4��@�t�_�-�-�	9�!%�!6�!6�!8�!8�D���!�!r7c��||_dSrI)r�r�s  r8rpzRequestHandler.current_userRs��"����r7c��dS)zrOverride to determine the current user from, e.g., a cookie.

        This method may not be a coroutine.
        Nr6rds r8r�zRequestHandler.get_current_userVs	��
�tr7c�R�|�dd��|jjdS)z�Override to customize the login URL based on the request.

        By default, we use the ``login_url`` application setting.
        �	login_urlz@tornado.web.authenticated)rrBrhrds r8�
get_login_urlzRequestHandler.get_login_url]s,��
	
���[�*F�G�G�G���(��5�5r7c�@�|jj�d��S)z�Override to customize template path for each handler.

        By default, we use the ``template_path`` application setting.
        Return None to load templates relative to the calling file.
        rh)rBrhr�rds r8rYz RequestHandler.get_template_pathes����(�,�,�_�=�=�=r7c��t|d���s6|���\}}}|j�dd��}|j�di��}|dkrt	j|��|_n�|dkr�tjd��}d�	dt	j|��t	jt||����ttt|������g��|_ntd	|���|�$|jr	d|vrd|d<|jd
|jfi|��|jS)a�The XSRF-prevention token for the current user/session.

        To prevent cross-site request forgery, we set an '_xsrf' cookie
        and include the same '_xsrf' value as an argument with all POST
        requests. If the two do not match, we reject the form submission
        as a potential forgery.

        See http://en.wikipedia.org/wiki/Cross-site_request_forgery

        This property is of type `bytes`, but it contains only ASCII
        characters. If a character string is required, there is no
        need to base64-encode it; just decode the byte string as
        UTF-8.

        .. versionchanged:: 3.2.2
           The xsrf token will now be have a random mask applied in every
           request, which makes it safe to include the token in pages
           that are compressed.  See http://breachattack.com for more
           information on the issue fixed by this change.  Old (version 1)
           cookies will be converted to version 2 when this method is called
           unless the ``xsrf_cookie_version`` `Application` setting is
           set to 1.

        .. versionchanged:: 4.3
           The ``xsrf_cookie_kwargs`` `Application` setting may be
           used to supply additional cookie options (which will be
           passed directly to `set_cookie`). For example,
           ``xsrf_cookie_kwargs=dict(httponly=True, secure=True)``
           will set the ``secure`` and ``httponly`` flags on the
           ``_xsrf`` cookie.
        �_xsrf_token�xsrf_cookie_versionr0�xsrf_cookie_kwargsr/��|�2zunknown xsrf cookie version %dNr�r��_xsrf)r��_get_raw_xsrf_tokenrhr��binascii�b2a_hexr�r_�urandomr4rrr�rr�rpr�)rNr��token�	timestamp�output_version�
cookie_kwargs�masks       r8�
xsrf_tokenzRequestHandler.xsrf_tokenmsX��B�t�]�+�+�	L�(,�(@�(@�(B�(B�%�G�U�I�!�]�.�.�/D�a�H�H�N� �M�-�-�.B�B�G�G�M���"�"�#+�#3�E�#:�#:�� � ��1�$�$��z�!�}�}��#'�9�9�� �(��.�.� �(���u�)E�)E�F�F��S��Y���0�0�1�1�	�$�$�� � �!�!A�>�R�R�R����$�7��}�)L�)L�46�M�.�1������)9�K�K�]�K�K�K���r7c��t|d��st|�d��}|r|�|��\}}}nd\}}}|�)d}tjd��}tj��}|�J�|�J�|||f|_|jS)a�Read or generate the xsrf token in its raw form.

        The raw_xsrf_token is a tuple containing:

        * version: the version of the cookie from which this token was read,
          or None if we generated a new token in this request.
        * token: the raw token data; random (non-ascii) bytes.
        * timestamp: the time this token was generated (will not be accurate
          for version 1 cookies)
        �_raw_xsrf_tokenr��NNNN�)r�r��_decode_xsrf_tokenr_r�r�r�)rNr�r�r�r�s     r8r�z"RequestHandler._get_raw_xsrf_token�s����t�.�/�/�	?��_�_�W�-�-�F��
=�,0�,C�,C�F�,K�,K�)���	�	�,<�)���	��}����
�2���� �I�K�K�	��$�$�$��(�(�(�$+�U�I�#>�D� ��#�#r7r�c��	t�t|����}|r�t|�d����}|dkr~|�d��\}}}}t
jt|����}t|t
jt|������}	t|��}
||	|
fStd���d}	t
jt|����}	n+#tj
tf$rt|��}	YnwxYwttj����}
||	|
fS#t$rtjdd���YdSwxYw)	z_Convert a cookie string into a the tuple form returned by
        _get_raw_xsrf_token.
        r/r0�|zUnknown xsrf cookie versionz(Uncaught exception in _decode_xsrf_tokenTr�r�)�_signed_value_version_re�matchrr�groupr�r��a2b_hexrr�Errorr�r�r�debug)rNr�rMr�rq�mask_str�masked_token�
timestamp_strr�r�r�s           r8r�z!RequestHandler._decode_xsrf_token�sr��	$�(�.�.�t�F�|�|�<�<�A��
3��a�g�g�a�j�j�/�/���a�<�<�?E�|�|�C�?P�?P�<�A�x��}�#�+�D��N�N�;�;�D�+�D�(�2B�4��CU�CU�2V�2V�W�W�E� #�M� 2� 2�I�"�E�9�4�4�$�$A�B�B�B���)�$�,�T�&�\�\�:�:�E�E�� ��	�2�)�)�)� ��L�L�E�E�E�)���� ��	���,�,�	���	�2�2���	$�	$�	$��M�D�t�T�T�T�T�#�#�#�	$���s<�CE�E�#!D�E�%D-�*E�,D-�-'E� E9�8E9c���|�dd��p=|jj�d��p|jj�d��}|st	dd���|�|��\}}}|���\}}}|st	dd���tjt|��t|����st	dd���dS)	a�Verifies that the ``_xsrf`` cookie matches the ``_xsrf`` argument.

        To prevent cross-site request forgery, we set an ``_xsrf``
        cookie and include the same value as a non-cookie
        field with all ``POST`` requests. If the two do not match, we
        reject the form submission as a potential forgery.

        The ``_xsrf`` value may be set as either a form field named ``_xsrf``
        or in a custom HTTP header named ``X-XSRFToken`` or ``X-CSRFToken``
        (the latter is accepted for compatibility with Django).

        See http://en.wikipedia.org/wiki/Cross-site_request_forgery

        .. versionchanged:: 3.2.2
           Added support for cookie version 2.  Both versions 1 and 2 are
           supported.
        r�NzX-XsrftokenzX-Csrftoken�z"'_xsrf' argument missing from POSTz#'_xsrf' argument has invalid formatz(XSRF cookie does not match POST argument)
r�rDr�r�rlr�r��hmac�compare_digestr)rNr�rq�expected_tokens    r8�check_xsrf_cookiez RequestHandler.check_xsrf_cookie�s���2
���g�t�,�,�
7��|�#�'�'�
�6�6�
7��|�#�'�'�
�6�6�	�
�	G��C�!E�F�F�F��-�-�e�4�4���5�!�#�7�7�9�9���>�1��	H��C�!F�G�G�G��"�4��;�;��^�0D�0D�E�E�	M��C�!K�L�L�L�	M�	Mr7c�@�dtj|j��zdzS)a�An HTML ``<input/>`` element to be included with all POST forms.

        It defines the ``_xsrf`` input value, which we check on all POST
        requests to prevent cross-site request forgery. If you have set
        the ``xsrf_cookies`` application setting, you must include this
        HTML within all of your HTML forms.

        In a template, this method should be called with ``{% module
        xsrf_form_html() %}``

        See `check_xsrf_cookie()` above for more information.
        z)<input type="hidden" name="_xsrf" value="z"/>)rrJr�rds r8rszRequestHandler.xsrf_form_html
s)��
8��!�$�/�2�2�
3��
�	
r7�include_hostc��|�dd��|j�dt��j}|�t|dd��}|r|jjdz|jjz}nd}|||j|fi|��zS)	a�Returns a static URL for the given relative static file path.

        This method requires you set the ``static_path`` setting in your
        application (which specifies the root directory of your static
        files).

        This method returns a versioned url (by default appending
        ``?v=<signature>``), which allows the static files to be
        cached indefinitely.  This can be disabled by passing
        ``include_version=False`` (in the default implementation;
        other static file implementations are not required to support
        this, but they may support other options).

        By default this method returns URLs relative to the current
        host, but if ``include_host`` is true the URL returned will be
        absolute.  If this handler has an ``include_host`` attribute,
        that value will be used as the default for all `static_url`
        calls that do not pass ``include_host`` as a keyword argument.

        �static_pathrP�static_handler_classNr�Fz://r�)	rrhr��StaticFileHandler�make_static_urlr&rD�protocol�host)rNr�r�rE�get_url�bases      r8rPzRequestHandler.static_urls���.	
���]�L�9�9�9��-�#�#�"�$5�
�
�
�	���"�4���?�?�L��	��<�(�5�0�4�<�3D�D�D�D��D��g�g�d�m�T�<�<�V�<�<�<�<r7�this feature�featurec�n�|jj�|��std|�d|�����dS)z<Raises an exception if the given app setting is not defined.zYou must define the 'z%' setting in your application to use N)rBrhr�r)rNr�rs   r8rzRequestHandler.require_settingCsL����(�,�,�T�2�2�	��)�+/�4�4���:���
�	�	r7c�(�|jj|g|�R�S)z$Alias for `Application.reverse_url`.)rBrt)rNr�ris   r8rtzRequestHandler.reverse_urlKs ��+�t��+�D�8�4�8�8�8�8r7c��tj��}|jD]}|�|���d|���zS)aComputes the etag header to be used for this request.

        By default uses a hash of the content written so far.

        May be overridden to provide custom etag implementations,
        or may return None to disable tornado's default etag support.
        z"%s")�hashlib�sha1r�rf�	hexdigest)rN�hasherr�s   r8�compute_etagzRequestHandler.compute_etagOsM��������&�	 �	 �D��M�M�$�������(�(�*�*�*�*r7c�b�|���}|�|�d|��dSdS)z�Sets the response's Etag header using ``self.compute_etag()``.

        Note: no header will be set if ``compute_etag()`` returns ``None``.

        This method is called automatically when the request is finished.
        Nr�)rr�)rN�etags  r8r�zRequestHandler.set_etag_header\s=��� � �"�"�����O�O�F�D�)�)�)�)�)��r7c	�j�t|j�dd����}tjdt|jj�dd������}|r|sdSd}|ddkrd}n3d	td
tfd�}|D]}||��||��krd}n�|S)a�Checks the ``Etag`` header against requests's ``If-None-Match``.

        Returns ``True`` if the request's Etag matches and a 304 should be
        returned. For example::

            self.set_etag_header()
            if self.check_etag_header():
                self.set_status(304)
                return

        This method is called automatically when the request is finished,
        but may be called earlier for applications that override
        `compute_etag` and want to do an early check for ``If-None-Match``
        before completing the request.  The ``Etag`` header should be set
        (perhaps with `set_etag_header`) before calling this method.
        r�r�s\*|(?:W/)?"[^"]*"�
If-None-MatchFr�*T�xrFc�D�|�d��r
|dd�n|S)NsW/r0�r�)rs r8�valz-RequestHandler.check_etag_header.<locals>.val�s%�� !���U� 3� 3�:�q����u�u��:r7)rr�r�r��findallrDr�r�)rN�
computed_etag�etagsr�rrs      r8r�z RequestHandler.check_etag_headergs���"�T�]�.�.�v�r�:�:�;�;�
��
�!�4���(<�(@�(@��RT�(U�(U�#V�#V�
�
���	�E�	��5�����8�t����E�E�
;�u�
;��
;�
;�
;�
;��
�
���3�t�9�9���M� 2� 2�2�2� �E��E�3��r7�
transforms�OutputTransformc��H�K�|�_	�jj�jvrt	d���t�j��sF	�j���n+#tj	$r}t	dd|z��|�d}~wwxYw�fd�|D���_
t�fd�|���D�����_
�jjdvr3�jj�d��r��������}|�|�d{V��}�j�t)�jd���jrdSt�j��r*	�jj�d{V��n#t.j$rYdSwxYwt3��jj�����}|�j
i�j
��}|�|�d{V��}�jr�js����dSdSdS#t:$r�}	��|��n&#t:$rt?j d	d
���YnwxYwd}n#d}wxYw�j�9�j�!��s&�j�"d��Yd}~dSYd}~dSYd}~dSd}~wwxYw)z7Executes this request with the given output transforms.rkr�zInvalid body: %sNc�:��g|]}��|����Sr6�r�)rK�argrNs  �r8r�z+RequestHandler._execute.<locals>.<listcomp>�s'���H�H�H�C�d�2�2�3�7�7�H�H�Hr7c3�P�K�|] \}}|��||���fV��!dS)r�Nr!)rKr�r�rNs   �r8rOz*RequestHandler._execute.<locals>.<genexpr>�sP�����$�$�9?�!�Q��D�(�(���(�3�3�4�$�$�$�$�$�$r7)r;r<rA�xsrf_cookieszException in exception handlerTr�)#r~rDr��SUPPORTED_METHODSrlrurb�_parse_bodyr�HTTPInputError�	path_argsrrY�path_kwargsrBrhr�r�rprWrrUrvrryr&�lowerrVrr�_handle_request_exceptionrr�rwr�)rNrrirE�e�resultr�s`      r8�_executezRequestHandler._execute�s������&���B	7��|�"�$�*@�@�@���n�n�$�,�D�N�;�;�
H�H��L�,�,�.�.�.�.���.�H�H�H�#�C�);�a�)?�@�@�a�G�����H����I�H�H�H�4�H�H�H�D�N�#�$�$�$�$�CI�<�<�>�>�$�$�$� � �D����#�����$�-�1�1�.�A�A�
��&�&�(�(�(��\�\�^�^�F��!�%���������$�0�3�4�3H�$�O�O�O��~�
���'���7�7�
�
��,�3�3�3�3�3�3�3�3�3���1�����F�F������T�4�<�#6�#<�#<�#>�#>�?�?�F��V�T�^�@�t�/?�@�@�F��!�%��������� �
���
����
�
�
�
�
�
�
�
�
���	7�	7�	7�
��.�.�q�1�1�1�1���
O�
O�
O��
�>��N�N�N�N�N�N�
O����������
�
�
�
��$�0��9N�9S�9S�9U�9U�0��%�0�0��6�6�6�6�6�6�6�6�6�	1�0�0�0�0�0�0�0�0�0�0�0�����	7���s��6G?�A�G?�B�,B�B�C
G?�G?�&E9�8G?�9F�G?�F�A-G?�?
J!�
H �I	�  I�I	�I�I	�J�	I
�
=J�J!c��t���)z�Implement this method to handle streamed request data.

        Requires the `.stream_request_body` decorator.

        May be a coroutine for flow control.
        ��NotImplementedError)rNrs  r8�
data_receivedzRequestHandler.data_received�s��"�#�#�#r7c�:�|j�|��dS)z�Logs the current request.

        Sort of deprecated since this functionality was moved to the
        Application, but left in place for the benefit of existing apps
        that have overridden this method.
        N)rB�log_requestrds r8r�zRequestHandler._log�s!��	
��$�$�T�*�*�*�*�*r7c�T�|jj�d|jj�d|jj�d�S)Nr�� (�))rDr��uri�	remote_iprds r8�_request_summaryzRequestHandler._request_summary�s6���L�����L�����L�"�"�"�
�	
r7r,c���t|t��r|js|j|j�dS	|jt
j���n&#t$rtj
dd���YnwxYw|jrdSt|t��r/|�|j
t
j�����dS|�dt
j�����dS)NzError in exception loggerTr�r�)r��FinishrUrri�
log_exceptionrZr�rrr�rlr�r�)rNr,s  r8r+z(RequestHandler._handle_request_exception�s����a�� � �	��>�
%����Q�V�$�$��F�	F��D������/�/�/���	F�	F�	F�
�M�5��E�E�E�E�E�E�	F�����>�	�
�F��a��#�#�	:��O�O�A�M�C�L�N�N�O�C�C�C�C�C��O�O�C�#�,�.�.�O�9�9�9�9�9s�A� A.�-A.�typzOptional[Type[BaseException]]�tbc�B�t|t��rW|jrNd|jz}|j|���gt|j��z}tj|g|�R�dSdStj
d|���|j|||f���dS)aKOverride to customize logging of uncaught exceptions.

        By default logs instances of `HTTPError` as warnings without
        stack traces (on the ``tornado.general`` logger), and all
        other exceptions as errors with stack traces (on the
        ``tornado.application`` logger).

        .. versionadded:: 3.1
        z%d %s: zUncaught exception %s
%rr�N)r�rl�log_messager�r:rrir�warningrr�rD)rNr>r�r?�formatris      r8r=zRequestHandler.log_exceptions����e�Y�'�'�	�� �
/�"�U�%6�6���)�4�+@�+@�+B�+B�C�d�5�:�FV�FV�V�����.��.�.�.�.�.�.�
/�
/�

�M�+��%�%�'�'����u�b�)�	
�
�
�
�
�
r7r;�UIModule.c�*����dtf���fd�}|S)NrFc���t�d��si�_��jvr�����j�<�j�j|i|��}|S)Nr#)r�r#rF)rirE�renderedr;r�rNs   ���r8rFz)RequestHandler._ui_module.<locals>.render$se����4�!2�3�3�
*�')��$��4�/�/�/�-3�V�D�\�\��$�T�*�8�t�+�D�1�8�$�I�&�I�I�H��Or7)r�)rNr�r;rFs``` r8�
_ui_modulezRequestHandler._ui_module#s;�����	�s�	�	�	�	�	�	�	�	��
r7r�c������fd�S)Nc�����g|�Ri|��SrIr6)rirEr�rNs  ��r8r�z+RequestHandler._ui_method.<locals>.<lambda>/s!���v�v�d�'D�T�'D�'D�'D�V�'D�'D�r7r6)rNr�s``r8rJzRequestHandler._ui_method.s����D�D�D�D�D�Dr7c�B�gd�}|D]}|�|���dS)N)�Content-EncodingzContent-Languager})r�)rNr��hs   r8r�z,RequestHandler._clear_representation_headers1s@��K�J�J���	!�	!�A����a� � � � �	!�	!r7�rFNrI�T)NNr�N)r�N)r�N)Nr
N)FN)F)r�)r�)r)�r3r4r5�__doc__r%rb�	threading�Lockrar��compiler��_stream_request_bodyr~r(r)r�HTTPServerRequestr rSrera�propertyrr�rhrn�headr��post�delete�patch�put�optionsr"r#rprrr`r]r�rr�r��_HeaderTypesr�r�r�r�r�r,r�r��_ARG_DEFAULTr2r!r%r�r�r�r�r�r�r�r�r�r�r��Morselr�r�r$r�r�r�r�rrrrrrr rFr'r.r0r1r3r%rer�
BaseLoaderrcr�rr�IOStreamr�r�r�r�r�r
�Locale�setterr�r�rpr�r�rYr�r�r�r�rsrPrrtrr�r�r.r2r�r:�
BaseExceptionr+r-r=r)r&rHrJr��
__classcell__�rbs@r8r:r:�s��������	�	�U����*�I�N�,�,��",�"�*�-D�"E�"E�� ���K��I��K�"�"�"��+�"��	"�

�"�"�"�"�"�"�@
�
�
�
��J��&�)�$�s�C�x�.�)�)�)��X�)��3��#��$�����!�D�
�C� �D�
"�F�!�E�
�C�#�G�
��)�D�/�2�
�
�
�
� 
�
�
�
�6�6�6�6�&/�/�/�/�
�
�
�
�J�J�c�J�8�C�=�J�D�J�J�J�J�:!�C�!�!�!�!�@�s�@�<�@�D�@�@�@�@�C�s�C�<�C�D�C�C�C�C�$��$��$�$�$�$�)�b�j��8�8���<��C�����0�
�
��
�s�
�4�
�3�
�
�
��X�
��6B�RV�
�
��
�"3�
�KO�
�	�
�
�
��X�
�
�6:�
�
��
�"&�
�/3�
�	�#��
�
�
��X�
�8D��	P�P��P��t�S�"3�3�4�P��	P�

�#��P�P�P�P�$
H�
H�#�
H�d�
H�d�3�i�
H�
H�
H�
H�$8D��	U�U��U��t�S�"3�3�4�U��	U�

�#��U�U�U�U�&M�M�s�M�4�M�4��9�M�M�M�M�8D��	V�V��V��t�S�"3�3�4�V��	V�

�#��V�V�V�V�&N�N��N�D�N�D��I�N�N�N�N�������t�S�"3�3�4���S�$�u�+�%�&�	�
��
�#��
����HL�
�
��
�!%�c�4��;�&6�!7�
�@D�
�	
�c��
�
�
�
���U��(�3�-��3�����(�$��c�4�<�#6�6�7�$�$�$��X�$�
��s��X�c�]��h�s�m�����"!%�DH��(,�7�7��7��S�%�Z� �7���
�	7�
�%��u�h�.?� ?�@�A�7��
7��u�o�7��7�
�7�7�7�7�tCG�S�S��S�"�S�2:�3�-�S�	
�S�S�S�S� >�>�c�>��#��>�RV�>�>�>�>�()+�!%�%
�%
��%
��S�%�Z� �%
��u�o�	%
�
�#��%
��
%
�
�%
�%
�%
�%
�PMQ�
�
��
� %�c�5�j� 1�
�<D�S�M�
�	�
�
�
�
�: $� �%)�
�
��
���}�
��	
�
�c�]�
�
�%��

�
�
�
�B15�0�0��0� (��
�0�	�#��0�0�0�0�JN�����#'��9A�#���	
�����()�5��e�T�!1�2�)�t�)�)�)�)�@I!�C�I!�3�I!�>�I!�I!�I!�I!�V
��#��
�3�
�
�
�
�.

����

�E�

�

�

�

�
�8�C�=�
�S�
�
�
�
�,T�(�5�/�T�e�T�T�T�T�'�3�'�#�'�%�'�'�'�'�4��S�#�X������.8�C�8�H�<O�8�8�8�8�*0�0�T�0�n�0�0�0�0�d7�7�H�U�3��t�+;�%<�=�7��7�7�7�7�r
0��)�
0�
0�
0�
0�����
%�%�c�%�3�%�4�%�%�%�%�N�s��c��d�����2����-�����X��(�]��G�N�1��d�����]����'�.�*?�!@�����#�#�#�#�G�N�<Q�#�#�#�#�6�!"�c�!"�!"�!"��X�!"�F��#�#�#�$�#�#�#���#��#�����6�s�6�6�6�6�>�8�C�=�>�>�>�>��6 �E�6 �6 �6 ��X�6 �p$�U�8�C�=�%��+F�%G�$�$�$�$�4"$��"$�	�x��}�h�u�o�x���>�	?�"$�"$�"$�"$�H$M�$M�$M�$M�L
��
�
�
�
�(9=�$=�$=��$=�'/��~�$=�HK�$=�	�$=�$=�$=�$=�L��C��#��4�����9��9�C�9�C�9�9�9�9�+�h�s�m�+�+�+�+�	*�	*�	*�	*�&�4�&�&�&�&�PG7��0�1�G7�:?�G7�KP�G7�	
�G7�G7�G7�G7�R$�5�$�X�i��o�-F�$�$�$�$�+�+�+�+�
�#�
�
�
�
�:�=�:�T�:�:�:�:�,�
,���
�&��
�]�#�	�

�����8	�s�	�D��,<�	��#�s�(�AS�	�	�	�	�E��#�s�(�!3�E���c��8J�E�E�E�E�!�!�!�!�!�!�!�!r7r:�_RequestHandlerType)�bound�clsrFc�^�t|t��std|���d|_|S)aApply to `RequestHandler` subclasses to enable streaming body support.

    This decorator implies the following changes:

    * `.HTTPServerRequest.body` is undefined, and body arguments will not
      be included in `RequestHandler.get_argument`.
    * `RequestHandler.prepare` is called when the request headers have been
      read instead of after the entire body has been read.
    * The subclass must define a method ``data_received(self, data):``, which
      will be called zero or more times as data is available.  Note that
      if the request has an empty body, ``data_received`` may not be called.
    * ``prepare`` and ``data_received`` may return Futures (such as via
      ``@gen.coroutine``, in which case the next method will not be called
      until those futures have completed.
    * The regular HTTP method (``post``, ``put``, etc) will be called after
      the entire body has been read.

    See the `file receiver demo <https://github.com/tornadoweb/tornado/tree/master/demos/file_upload/>`_
    for example usage.
    �+expected subclass of RequestHandler, got %rT��
issubclassr:r�rT�ris r8�stream_request_bodyro?s5��*�c�>�*�*�L��E�s�K�K�K�#�C���Jr7c�Z�t|t��std|���|jS)Nrkrlrns r8ruruZs/���c�>�*�*�L��E�s�K�K�K��#�#r7r�.c���tj���dtdttdf�fd���}|S)a#Use this decorator to remove trailing slashes from the request path.

    For example, a request to ``/foo/`` would redirect to ``/foo`` with this
    decorator. Your request handler mapping should use a regular expression
    like ``r'/foo/*'`` in conjunction with using the decorator.
    rNrFNc�F��|jj�d��rv|jjdvrY|jj�d��}|r7|jjr|d|jjzz
}|�|d���dSntd����|g|�Ri|��S�Nr�r��?T�r�)rDr��endswithr��rstrip�queryrrl�rNrirEr8r�s    �r8�wrapperzremoveslash.<locals>.wrapperjs�����<��%�%�c�*�*�		%��|�"�o�5�5��l�'�.�.�s�3�3��� ��|�)�8��s�T�\�%7�7�7���M�M�#��M�6�6�6��4�	 � ��n�n�$��v�d�,�T�,�,�,�V�,�,�,r7��	functools�wrapsr:r"r#�r�r{s` r8�removeslashr�`sX����_�V���
-��
-�	�)�D�/�	"�
-�
-�
-�
-�
-���
-��Nr7c���tj���dtdttdf�fd���}|S)a&Use this decorator to add a missing trailing slash to the request path.

    For example, a request to ``/foo`` would redirect to ``/foo/`` with this
    decorator. Your request handler mapping should use a regular expression
    like ``r'/foo/?'`` in conjunction with using the decorator.
    rNrFNc� ��|jj�d��sc|jjdvrF|jjdz}|jjr|d|jjzz
}|�|d���dSt
d����|g|�Ri|��Srs)rDr�rwr�ryrrlrzs    �r8r{zaddslash.<locals>.wrapper�s�����|� �)�)�#�.�.�	!��|�"�o�5�5��l�'�#�-���<�%�4��3���!3�3�3�C��
�
�c�T�
�2�2�2��t��C�.�.� ��v�d�,�T�,�,�,�V�,�,�,r7r|rs` r8�addslashr�}sX����_�V���-��-�	�)�D�/�	"�-�-�-�-�-���-��Nr7c	���eZdZdZ	ddddeeddf�fd�
Zdedef�fd	�Zd
e	de
jde	dee
jf�fd
�Z
�xZS)�_ApplicationRoutera�Routing implementation used internally by `Application`.

    Provides a binding between `Application` and `RequestHandler`.
    This implementation extends `~.routing.ReversibleRuleRouter` in a couple of ways:
        * it allows to use `RequestHandler` subclasses as `~.routing.Rule` target and
        * it allows to use a list/tuple of rules as `~.routing.Rule` target.
        ``process_rule`` implementation will substitute this list with an appropriate
        `_ApplicationRouter` instance.
    NrBrC�rulesrFc���t|t��sJ�||_t���|��dSrI)r�rCrBrRrS)rNrBr�rbs   �r8rSz_ApplicationRouter.__init__�sA����+�{�3�3�3�3�3�&���
����������r7�rulec����t���|��}t|jtt
f��rt
|j|j��|_|SrI)rR�process_ruler��targetr�tupler�rB)rNr�rbs  �r8r�z_ApplicationRouter.process_rule�sT����w�w�#�#�D�)�)���d�k�D�%�=�1�1�	�,�� �$�+���D�K��r7r�rD�
target_paramsc���t|��r)t|t��r|jj||fi|��St��j||fi|��SrI)rrmr:rB�get_handler_delegaterR�get_target_delegate)rNr�rDr�rbs    �r8r�z&_ApplicationRouter.get_target_delegate�ss����6�?�?�	�z�&�.�A�A�	�8�4�#�8�����#0���
�+�u�w�w�*�6�7�L�L�m�L�L�Lr7rI)r3r4r5rPr"rrSrr�r rrU�HTTPMessageDelegater�rerfs@r8r�r��s����������HL� � �(� �19�)�1D� �	
� � � � � � ����$�������M��M�$,�$>�M�QT�M�	�(�.�	/�M�M�M�M�M�M�M�M�M�Mr7r�c�<�eZdZdZ			d+deedeedeeedde	ddf
d	�Z
	d,eje
jjdd
d�ded
eedejdedeedede	defd�Zdededdfd�Zdedddfd�Zde	ddfd�Zde	ddfd�Zdejdeedfd�Zdejde	ddfd �Z			d+dejd!eed"eeee	fd#eee d$eeee fddfd%�Z!d&ed'e	defd(�Z"d)eddfd*�Z#dS)-rCa�
A collection of request handlers that make up a web application.

    Instances of this class are callable and can be passed directly to
    HTTPServer to serve the application::

        application = web.Application([
            (r"/", MainPageHandler),
        ])
        http_server = httpserver.HTTPServer(application)
        http_server.listen(8080)

    The constructor for this class takes in a list of `~.routing.Rule`
    objects or tuples of values corresponding to the arguments of
    `~.routing.Rule` constructor: ``(matcher, target, [target_kwargs], [name])``,
    the values in square brackets being optional. The default matcher is
    `~.routing.PathMatches`, so ``(regexp, target)`` tuples can also be used
    instead of ``(PathMatches(regexp), target)``.

    A common routing target is a `RequestHandler` subclass, but you can also
    use lists of rules as a target, which create a nested routing configuration::

        application = web.Application([
            (HostMatches("example.com"), [
                (r"/", MainPageHandler),
                (r"/feed", FeedHandler),
            ]),
        ])

    In addition to this you can use nested `~.routing.Router` instances,
    `~.httputil.HTTPMessageDelegate` subclasses and callables as routing targets
    (see `~.routing` module docs for more information).

    When we receive requests, we iterate over the list in order and
    instantiate an instance of the first request class whose regexp
    matches the request path. The request class can be specified as
    either a class object or a (fully-qualified) name.

    A dictionary may be passed as the third element (``target_kwargs``)
    of the tuple, which will be used as keyword arguments to the handler's
    constructor and `~RequestHandler.initialize` method. This pattern
    is used for the `StaticFileHandler` in this example (note that a
    `StaticFileHandler` can be installed automatically with the
    static_path setting described below)::

        application = web.Application([
            (r"/static/(.*)", web.StaticFileHandler, {"path": "/var/www"}),
        ])

    We support virtual hosts with the `add_handlers` method, which takes in
    a host regular expression as the first argument::

        application.add_handlers(r"www\.myhost\.com", [
            (r"/article/([0-9]+)", ArticleHandler),
        ])

    If there's no match for the current request's host, then ``default_host``
    parameter value is matched against host regular expressions.


    .. warning::

       Applications that do not use TLS may be vulnerable to :ref:`DNS
       rebinding <dnsrebinding>` attacks. This attack is especially
       relevant to applications that only listen on ``127.0.0.1`` or
       other private networks. Appropriate host patterns must be used
       (instead of the default of ``r'.*'``) to prevent this risk. The
       ``default_host`` argument must not be used in applications that
       may be vulnerable to DNS rebinding.

    You can serve static files by sending the ``static_path`` setting
    as a keyword argument. We will serve those files from the
    ``/static/`` URI (this is configurable with the
    ``static_url_prefix`` setting), and we will serve ``/favicon.ico``
    and ``/robots.txt`` from the same directory.  A custom subclass of
    `StaticFileHandler` can be specified with the
    ``static_handler_class`` setting.

    .. versionchanged:: 4.5
       Integration with the new `tornado.routing` module.

    N�handlers�default_hostrrrhrFc�<�|�Qg|_|�d��s|�d��r|j�t��n||_||_||_tttd�|_	i|_
|�|�di����|�|�di����|j�d��r�|jd}t|pg��}|�dd��}|�d	t��}|�d
i��}||d<tj|��dzd
dfD]}	|�d|	||f���|j�d��rl|j�dd��|j�dd��|j�dd��|j�dd��t'||��|_t'|t+t-��|j��g��|_|j�d��rddlm}
|
���dSdS)N�compress_response�gzip)�linkifyrs�Templater\rXr��static_url_prefix�/static/r�static_handler_argsr�z(.*)z/(favicon\.ico)z/(robots\.txt)rr��
autoreloadT�compiled_template_cacheF�static_hash_cacher�)r�)rr�r��GZipContentEncodingr�rh�_linkify�_xsrf_form_html�TemplateModuler\rX�_load_ui_modules�_load_ui_methodsrrr�r�insert�
setdefaultr��wildcard_routerrr�default_routerr�r��start)rNr�r�rrhr�r�rr��patternr�s           r8rSzApplication.__init__s����� �D�O��|�|�/�0�0�
<�H�L�L��4H�4H�
<���&�&�':�;�;�;��(�D�O�(��� ��
��-�&�
�
���
������h�l�l�<��<�<�=�=�=����h�l�l�<��<�<�=�=�=��=���]�+�+�	Y��=��/�D��H�N��+�+�H� (���-@�*� M� M��#+�<�<�&�(9�$�$� �#+�,�,�/D�b�"I�"I��*.���'��	�+�,�,�w�6�"�!��
Y�
Y��
����G�-A�CV�#W�X�X�X�X��=���W�%�%�	>��M�$�$�\�4�8�8�8��M�$�$�%>��F�F�F��M�$�$�%8�%�@�@�@��M�$�$�%6��=�=�=�1�$��A�A���0��4�
���d�&:�;�;�<�
�
���
�=���\�*�*�	�*�*�*�*�*�*���������	�	r7F)�family�backlog�flags�
reuse_port�port�addressr�r�r�r�rEc�V�t|fi|��}|�||||||���|S)a�Starts an HTTP server for this application on the given port.

        This is a convenience alias for creating an `.HTTPServer` object and
        calling its listen method.  Keyword arguments not supported by
        `HTTPServer.listen <.TCPServer.listen>` are passed to the `.HTTPServer`
        constructor.  For advanced uses (e.g. multi-process mode), do not use
        this method; create an `.HTTPServer` and call its
        `.TCPServer.bind`/`.TCPServer.start` methods directly.

        Note that after calling this method you still need to call
        ``IOLoop.current().start()`` (or run within ``asyncio.run``) to start
        the server.

        Returns the `.HTTPServer` object.

        .. versionchanged:: 4.3
           Now returns the `.HTTPServer` object.

        .. versionchanged:: 6.2
           Added support for new keyword arguments in `.TCPServer.listen`,
           including ``reuse_port``.
        )r�r�r�r�r�)r
�listen)	rNr�r�r�r�r�r�rE�servers	         r8r�zApplication.listenJsN��B�D�+�+�F�+�+���
�
������!�
	�	
�	
�	
��
r7�host_pattern�
host_handlersc��t|��}t|t||����}|jj�d|��|j�2|j�t||j
��|fg��dSdS)z�Appends the given handlers to our handler list.

        Host patterns are processed sequentially in the order they were
        added. All matching patterns will be considered.
        r�N)rrr�r�r�r�r�r��	add_rulesrr�)rNr�r��host_matcherr�s     r8�add_handlerszApplication.add_handlersvs���#�<�0�0���L�"4�T�=�"I�"I�J�J����!�(�(��T�2�2�2���(�� �*�*�$�T�<�+D�E�E�}�U�V�
�
�
�
�
�)�(r7�transform_classc�:�|j�|��dSrI)rr�)rNr�s  r8�
add_transformzApplication.add_transform�s�������/�/�/�/�/r7�methodsc����t�tj��r=|�t	�fd�t���D������dSt�t��r�D]}|�|���dS����D]X\}}|�d��s>t|d��r.|d�
��|dkr
||j|<�YdS)Nc3�<�K�|]}|t�|��fV��dSrI�r&)rKrLr�s  �r8rOz/Application._load_ui_methods.<locals>.<genexpr>��2�����&V�&V�A��7�7�A�+>�+>�'?�&V�&V�&V�&V�&V�&Vr7rq�__call__r)r��types�
ModuleTyper�r�dirrrYr�r�r*rX)rNr�rMr��fns `   r8r�zApplication._load_ui_methods�s����g�u�/�0�0�	/��!�!�$�&V�&V�&V�&V��W���&V�&V�&V�"V�"V�W�W�W�W�W�
���
&�
&�
	/��
)�
)���%�%�a�(�(�(�(�
)�
)�$�M�M�O�O�
/�
/���b�����,�,�/���J�/�/�/��Q��
�
���4��7�2�2�,.�D�O�D�)��

/�
/r7rQc����t�tj��r=|�t	�fd�t���D������dSt�t��r�D]}|�|���dSt�t��sJ�����D]5\}}	t|t��r
||j
|<�&#t$rY�2wxYwdS)Nc3�<�K�|]}|t�|��fV��dSrIr�)rKrLrQs  �r8rOz/Application._load_ui_modules.<locals>.<genexpr>�r�r7)r�r�r�r�rr�rrYrmrDr\r�)rNrQrMr�ris `   r8r�zApplication._load_ui_modules�s����g�u�/�0�0�	��!�!�$�&V�&V�&V�&V��W���&V�&V�&V�"V�"V�W�W�W�W�W�
���
&�
&�
	��
)�
)���%�%�a�(�(�(�(�
)�
)��g�t�,�,�,�,�,�$�]�]�_�_�
�
�	��c��!�#�x�0�0�4�03����-��� �����D�����	
�
s�;C�
C(�'C(rDc�T�|�|��}|���SrI)�find_handler�execute)rNrD�
dispatchers   r8r�zApplication.__call__�s)���&�&�w�/�/�
��!�!�#�#�#r7�_HandlerDelegatec�@�|j�|��}|�td|��S|j�d��r;|�||jd|j�di����S|�|tddi��S)Nr��default_handler_class�default_handler_argsr�rv)r�r�r+rhr�r��ErrorHandler)rNrDrE�routes    r8r�zApplication.find_handler�s����#�0�0��9�9�����*�E�2�2�2��=���4�5�5�	��,�,���
�5�6��
�!�!�"8�"�=�=���
��(�(��,��PS�@T�U�U�Ur7�target_class�
target_kwargsr(r)c�*�t||||||��S)aeReturns `~.httputil.HTTPMessageDelegate` that can serve a request
        for application and `RequestHandler` subclass.

        :arg httputil.HTTPServerRequest request: current HTTP request.
        :arg RequestHandler target_class: a `RequestHandler` class.
        :arg dict target_kwargs: keyword arguments for ``target_class`` constructor.
        :arg list path_args: positional arguments for ``target_class`` HTTP method that
            will be executed while handling a request (``get``, ``post`` or any other).
        :arg dict path_kwargs: keyword arguments for ``target_class`` HTTP method.
        )r�)rNrDr�r�r(r)s      r8r�z Application.get_handler_delegate�s#��$ ��'�<��	�;�
�
�	
r7r�ric�T�|jj|g|�R�}|�|Std|z���)a3Returns a URL path for handler named ``name``

        The handler must be added to the application as a named `URLSpec`.

        Args will be substituted for capturing groups in the `URLSpec` regex.
        They will be converted to strings if necessary, encoded as utf8,
        and url-escaped.
        Nz%s not found in named urls)r�rt�KeyError)rNr�ri�reversed_urls    r8rtzApplication.reverse_url�sA��7�t�*�6�t�C�d�C�C�C���#����3�d�:�;�;�;r7roc��d|jvr|jd|��dS|���dkr
tj}n1|���dkr
tj}ntj}d|j���z}|d|���|���|��dS)a!Writes a completed HTTP request to the logs.

        By default writes to the python root logger.  To change
        this behavior either subclass Application and override this method,
        or pass a function in the application settings dictionary as
        ``log_function``.
        �log_functionNr�r�g@�@z%d %s %.2fms)	rhr�r�inforBr�rD�request_timer:)rNro�
log_methodr�s    r8r4zApplication.log_request�s����T�]�*�*�)�D�M�.�)�'�2�2�2��F������#�%�%�#��J�J�
�
�
�
!�
!�C�
'�
'�#�+�J�J�#�)�J���� <� <� >� >�>���
����� � ��$�$�&�&��		
�	
�	
�	
�	
r7r�rI)$r3r4r5rPr"rr�r%r)r rS�socket�	AF_UNSPECr��netutil�_DEFAULT_BACKLOGr�
AddressFamilyr�r
r�r�r�r�r�rrUr#r�r�r:rr�r�rtr4r6r7r8rCrC�s�������P�P�h)-�&*�>B�	6�6��9�%�6��s�m�6��T�$�'8�"9�:�;�	6�
�6�
�
6�6�6�6�v"&�*�
(.�'7���7�#� �*�*�*��*��#��*�
�$�*��
*���}�*��*��*�
�*�*�*�*�X���Y��4����� 0�T�2C�-D�0��0�0�0�0�
/��
/��
/�
/�
/�
/�
��
��
�
�
�
�$��1�$�	�)�D�/�	"�$�$�$�$�V��1�V�=@�V�	�V�V�V�V�(37�+/�26�

�
��+�
��>�*�
� ��S�#�X��/�	
�
�D��K�(�
��d�3��:�.�/�

�
�
�
�
�
�,
<��
<�C�
<�C�
<�
<�
<�
<�
�>�
�d�
�
�
�
�
�
r7rCc�N�eZdZdedejdeedee	e
efdeee
dee	e
e
fddfd	�Zd
eejejfdejdeedfd�Zd
e
deedfd�Zdd�Zdd�Zdeedfd�ZdS)r�rBrD�
handler_class�handler_kwargsr(r)rFNc��||_|j|_||_||_|pi|_|pg|_|pi|_g|_t|j��|_	dSrI)
rBr^rDr�r�r(r)�chunksruro)rNrBrDr�r�r(r)s       r8rSz_HandlerDelegate.__init__�sj��'���!�,������*���,�2����"��b���&�,�"������#;�D�<N�#O�#O�� � � r7r�r�c�l�|jr,t��|j_|���SdSrI)rorrDrvr�)rNr�r�s   r8�headers_receivedz!_HandlerDelegate.headers_received	s0��
�#�	"�(.���D�L�%��<�<�>�>�!��tr7�datac�|�|jr|j�|��S|j�|��dSrI)roror2r�r�)rNr�s  r8r2z_HandlerDelegate.data_received	s>���#�	��<�-�-�d�3�3�3��K���t�$�$�$��4r7c��|jrt|jjd��dSd�|j��|j_|���dS)Nr7)rorrDrvr4r��bodyr�rds r8rz_HandlerDelegate.finish"	sS���#�	�.�t�|�/H�$�O�O�O�O�O�!$����� 5� 5�D�L���L�L�N�N�N�N�Nr7c�X�|jr|j���dSd|_dSrI)roror`r�rds r8r`z$_HandlerDelegate.on_connection_close+	s2���#�	��L�,�,�.�.�.�.�.��D�K�K�Kr7c����jj�dd��sZtj5tj���D]}|����	ddd��n#1swxYwY�jj�dd��s9�jj�dt��}|����j	�j�j
fi�j���_�fd��jj
D��}�jrt���j_t#j�jj|g�j�Ri�j����}|�d����jjS)Nr�Tr�rc�0��g|]}|�j����Sr6)rD)rKrlrNs  �r8r�z,_HandlerDelegate.execute.<locals>.<listcomp>B	s#���K�K�K�!�a�a���o�o�K�K�Kr7c�*�|���SrI)r-)�fs r8r�z*_HandlerDelegate.execute.<locals>.<lambda>P	s�����
�
�r7)rBrhr�r:rarbr��resetrr�rDr�rorrorrWr	�convert_yieldedr.r(r)�add_done_callback)rNrkrr�futs`    r8r�z_HandlerDelegate.execute1	s������(�,�,�-F��M�M�	#��5�
#�
#�,�>�E�E�G�G�#�#�F��L�L�N�N�N�N�#�
#�
#�
#�
#�
#�
#�
#�
#�
#�
#�
#����
#�
#�
#�
#���(�,�,�-@�$�G�G�	)�#'�#3�#<�#@�#@�&�(9�$�$� �
!�&�&�(�(�(�)�t�)���d�l�
�
�.2�.A�
�
���L�K�K�K�t�/?�/J�K�K�K�
��#�	5�,2�H�H�D�L�)��!�!�D�L�!�*�R�t�~�R�R�R��AQ�R�R�
�
��	���2�2�3�3�3��|�,�,s�6A1�1A5�8A5rN)r3r4r5rCrrUr)r:r"rr�r r%r�rSr!�RequestStartLiner�r�r#r�r2rr`r�r6r7r8r�r��sf������P� �P��+�P��N�+�	P�
!��c�3�h��0�P��D��K�(�
P��d�3��:�.�/�P�
�P�P�P�P�&��(�3�X�5O�O�P���%��
�)�D�/�	"�	�����%��H�Y�t�_�,E�������������#-��)�D�/�2�#-�#-�#-�#-�#-�#-r7r�c�L�eZdZdZ		ddedeedededdf
d	�Zdefd
�Z	dS)rlavAn exception that will turn into an HTTP error response.

    Raising an `HTTPError` is a convenient alternative to calling
    `RequestHandler.send_error` since it automatically ends the
    current function.

    To customize the response sent with an `HTTPError`, override
    `RequestHandler.write_error`.

    :arg int status_code: HTTP status code.  Must be listed in
        `httplib.responses <http.client.responses>` unless the ``reason``
        keyword argument is given.
    :arg str log_message: Message to be written to the log for this error
        (will not be shown to the user unless the `Application` is in debug
        mode).  May contain ``%s``-style placeholders, which will be filled
        in with remaining positional parameters.
    :arg str reason: Keyword-only argument.  The HTTP "reason" phrase
        to pass in the status line along with ``status_code`` (for example,
        the "Not Found" in ``HTTP/1.1 404 Not Found``).  Normally
        determined automatically from ``status_code``, but can be used
        to use a non-standard numeric code. This is not a general-purpose
        error message.
    r�Nr�rArirErFc��||_||_||_|�dd��|_|r|s|�dd��|_dSdSdS)Nr��%z%%)r�rArir�r��replace)rNr�rArirEs     r8rSzHTTPError.__init__p	sq��'���&�����	��j�j��4�0�0����	>�t�	>�*�2�2�3��=�=�D����	>�	>�	>�	>r7c��d|j|jp$tj�|jd��fz}|jr|dz|j|jzzdzS|S)NzHTTP %d: %sr�r6r7)r�r�rr�r�rAri)rNrs  r8�__str__zHTTPError.__str__~	sg������K�N�8�-�1�1�$�2B�I�N�N�#
�
����	��T�>�T�%5��	�%A�B�S�H�H��Nr7)r�N)
r3r4r5rPrr"r�r rSr�r6r7r8rlrlW	s���������4�%)�>�>��>��c�]�>��	>�
�>�
�
>�>�>�>��������r7rlc��eZdZdZdS)r<a�An exception that ends the request without producing an error response.

    When `Finish` is raised in a `RequestHandler`, the request will
    end (calling `RequestHandler.finish` if it hasn't already been
    called), but the error-handling methods (including
    `RequestHandler.write_error`) will not be called.

    If `Finish()` was created with no arguments, the pending response
    will be sent as-is. If `Finish()` was given an argument, that
    argument will be passed to `RequestHandler.finish()`.

    This can be a more convenient way to implement custom error pages
    than overriding ``write_error`` (especially in library code)::

        if self.current_user is None:
            self.set_status(401)
            self.set_header('WWW-Authenticate', 'Basic realm="something"')
            raise Finish()

    .. versionchanged:: 4.3
       Arguments passed to ``Finish()`` will be passed on to
       `RequestHandler.finish`.
    N)r3r4r5rPr6r7r8r<r<�	s��������0	�Dr7r<c�,��eZdZdZdeddf�fd�Z�xZS)r�z�Exception raised by `RequestHandler.get_argument`.

    This is a subclass of `HTTPError`, so if it is uncaught a 400 response
    code will be used instead of 500 (and a stack trace will not be logged).

    .. versionadded:: 3.1
    �arg_namerFNc�`��t���dd|z��||_dS)Nr�zMissing argument %s)rRrSr)rNrrbs  �r8rSzMissingArgumentError.__init__�	s.���
������3�h�>�?�?�?� ��
�
�
r7)r3r4r5rPr�rSrerfs@r8r�r��	sU���������!��!��!�!�!�!�!�!�!�!�!�!r7r�c�2�eZdZdZdeddfd�Zdd�Zdd�ZdS)	r�zBGenerates an error response with ``status_code`` for all requests.r�rFNc�0�|�|��dSrI)r�)rNr�s  r8razErrorHandler.initialize�	s������$�$�$�$�$r7c�*�t|j���rI)rlr�rds r8rpzErrorHandler.prepare�	s����)�*�*�*r7c��dSrIr6rds r8r�zErrorHandler.check_xsrf_cookie�	r�r7rN)r3r4r5rPrrarpr�r6r7r8r�r��	sd������L�L�%�c�%�d�%�%�%�%�+�+�+�+�
�
�
�
�
�
r7r�c�<�eZdZdZddededdfd�Zded	eddfd
�ZdS)�RedirectHandlera_Redirects the client to the given URL for all GET requests.

    You should provide the keyword argument ``url`` to the handler, e.g.::

        application = web.Application([
            (r"/oldpath", web.RedirectHandler, {"url": "/newpath"}),
        ])

    `RedirectHandler` supports regular expression substitutions. E.g., to
    swap the first and second parts of a path while preserving the remainder::

        application = web.Application([
            (r"/(.*?)/(.*?)/(.*)", web.RedirectHandler, {"url": "/{1}/{0}/{2}"}),
        ])

    The final URL is formatted with `str.format` and the substrings that match
    the capturing groups. In the above example, a request to "/a/b/c" would be
    formatted like::

        str.format("/{1}/{0}/{2}", "a", "b", "c")  # -> "/b/a/c"

    Use Python's :ref:`format string syntax <formatstrings>` to customize how
    values are substituted.

    .. versionchanged:: 4.5
       Added support for substitutions into the destination URL.

    .. versionchanged:: 5.0
       If any query arguments are present, they will be copied to the
       destination URL.
    Tr�rrFNc�"�||_||_dSrI)�_url�
_permanent)rNr�rs   r8razRedirectHandler.initialize�	s����	�#����r7rirEc��|jj|i|��}|jjr>t	j|t
t	j|jj������}|�||j	���dS)Nru)
r
rCrDr�r�
url_concatr�	qs_to_qslrr)rNrirE�to_urls    r8r�zRedirectHandler.get�	sx��!���!�4�2�6�2�2���<�'�	��(���X�'���(D�E�E�F�F���F�	
�
�
�f���
�8�8�8�8�8r7rO)	r3r4r5rPr�r�rar r�r6r7r8rr�	sv��������@$�$�c�$�d�$�d�$�$�$�$�9��9��9��9�9�9�9�9�9r7rc
���eZdZdZdZiZej��Zd)de	de
e	ddfd�Zed*d���Z
de	dedfd	�Zd+de	deddfd�Zde
e	fd
�Zd*d�Zdefd�Zede	de	de	fd���Zde	de	de
e	fd�Ze	d,de	de
ede
edeeddffd���Zede	de	fd���Zdejfd�Zdefd�Zde
e j fd�Z!de	fd�Z"de	ddfd�Z#de	de
e j de	defd �Z$e	d+d!e%e	e&fde	d"ede	fd#���Z'd$e	de	fd%�Z(ed!e%e	e&fde	de
e	fd&���Z)ed'e	de
e	fd(���Z*dS)-raMA simple handler that can serve static content from a directory.

    A `StaticFileHandler` is configured automatically if you pass the
    ``static_path`` keyword argument to `Application`.  This handler
    can be customized with the ``static_url_prefix``, ``static_handler_class``,
    and ``static_handler_args`` settings.

    To map an additional path to this handler for a static data directory
    you would add a line to your application like::

        application = web.Application([
            (r"/content/(.*)", web.StaticFileHandler, {"path": "/var/www"}),
        ])

    The handler constructor requires a ``path`` argument, which specifies the
    local root directory of the content to be served.

    Note that a capture group in the regex is required to parse the value for
    the ``path`` argument to the get() method (different than the constructor
    argument above); see `URLSpec` for details.

    To serve a file like ``index.html`` automatically when a directory is
    requested, set ``static_handler_args=dict(default_filename="index.html")``
    in your application settings, or add ``default_filename`` as an initializer
    argument for your ``StaticFileHandler``.

    To maximize the effectiveness of browser caching, this class supports
    versioned urls (by default using the argument ``?v=``).  If a version
    is given, we instruct the browser to cache this file indefinitely.
    `make_static_url` (also available as `RequestHandler.static_url`) can
    be used to construct a versioned url.

    This handler is intended primarily for use in development and light-duty
    file serving; for heavy traffic it will be more efficient to use
    a dedicated static file server (such as nginx or Apache).  We support
    the HTTP ``Accept-Ranges`` mechanism to return partial content (because
    some browsers require this functionality to be present to seek in
    HTML5 audio or video).

    **Subclassing notes**

    This class is designed to be extensible by subclassing, but because
    of the way static urls are generated with class methods rather than
    instance methods, the inheritance patterns are somewhat unusual.
    Be sure to use the ``@classmethod`` decorator when overriding a
    class method.  Instance methods may use the attributes ``self.path``
    ``self.absolute_path``, and ``self.modified``.

    Subclasses should only override methods discussed in this section;
    overriding other methods is error-prone.  Overriding
    ``StaticFileHandler.get`` is particularly problematic due to the
    tight coupling with ``compute_etag`` and other methods.

    To change the way static urls are generated (e.g. to match the behavior
    of another server or CDN), override `make_static_url`, `parse_url_path`,
    `get_cache_time`, and/or `get_version`.

    To replace all interaction with the filesystem (e.g. to serve
    static content from a database), override `get_content`,
    `get_content_size`, `get_modified_time`, `get_absolute_path`, and
    `validate_absolute_path`.

    .. versionchanged:: 3.1
       Many of the methods for subclasses were added in Tornado 3.1.
    i�Nr��default_filenamerFc�"�||_||_dSrI)�rootr)rNr�rs   r8razStaticFileHandler.initialize;
s����	� 0����r7c�T�|j5i|_ddd��dS#1swxYwYdSrI)�_lock�_static_hashesrns r8r�zStaticFileHandler.reset?
sv��
�Y�	$�	$�!#�C��	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$�	$�	$s��!�!c�0�|�|d���S)NF)�include_body)r��rNr�s  r8rWzStaticFileHandler.headD
s���x�x��5�x�1�1�1r7Trc��HK�|�|��|_~|�|j|j��}|�|j|��|_|j�dS|���|_|���|�	��r|�
d��dSd}|jj�
d��}|rtj|��}|���}|r�|\}}|�|dkr
||z
}|dkrd}|�||ks|�||ks|dkrF|�
d��|�dd��|�dd|����dS|�||kr|}||p||pdz
kr?|�
d	��|�dtj|||����ndx}}|�|�||z
}	n|�|}	n
|�||z
}	n|}	|�d
|	��|r�|�|j||��}
t)|
t*��r|
g}
|
D]I}	|�|��|����d{V���3#t0j$rYdSwxYwdS|jjdksJ�dS)Nr��Rangeri�r}r�z
Content-Rangezbytes */��r�r<)�parse_url_pathr��get_absolute_pathr�validate_absolute_path�
absolute_path�get_modified_time�modified�set_headers�should_return_304r�rDr�r�r�_parse_request_range�get_content_sizer��_get_content_range�get_contentr�r�r r�rryr�)rNr�rr �
request_range�range_header�sizer��endr��contentrs            r8r�zStaticFileHandler.getG
s0�����'�'��-�-��	���.�.�t�y�$�)�D�D�
�!�8�8���M�R�R�����%��F��.�.�0�0��
��������!�!�#�#�	��O�O�C� � � ��F��
��|�+�/�/��8�8���	H�%�9�,�G�G�M��$�$�&�&���"	�&�J�E�3�� �U�Q�Y�Y���
���1�9�9��E��!��d�]�]�s��5�C�<�<���������$�$�$������=�=�=��������1G�H�H�H�����3��:�:���
���t��
��3�3�3�����$�$�$����#�X�%@���T�%R�%R�������E�C����� �5�[�N�N�
�_� �N�N�
�
�!�E�\�N�N�!�N����(�.�9�9�9��	1��&�&�t�'9�5�#�F�F�G��'�5�)�)�
$�"�)�� �
�
����J�J�u�%�%�%��*�*�,�,�&�&�&�&�&�&�&�&���1�����F�F�F�����	
�
��<�&�&�0�0�0�0�0�0s�/I7�7J�
Jc�\�|j�J�|�|j��}|sdSd|�d�S)aSets the ``Etag`` header based on static url version.

        This allows efficient ``If-None-Match`` checks against cached
        versions, and sends the correct ``Etag`` for a partial response
        (i.e. the same ``Etag`` as the full file).

        .. versionadded:: 3.1
        N�")r �_get_cached_version)rN�version_hashs  r8rzStaticFileHandler.compute_etag�
sH���!�-�-�-��/�/��0B�C�C���	��4�	�%���'�'r7c�T�|�dd��|���|j�|�d|j��|���}|r|�d|��|�|j|j|��}|dkrn|�dtj���t
j|���z��|�d	d
t|��z��|�
|j��dS)z]Sets the content and caching headers on the response.

        .. versionadded:: 3.1
        z
Accept-Rangesr�Nz
Last-Modifiedr}r�Expires)�secondsz
Cache-Controlzmax-age=)r�r�r"�get_content_type�get_cache_timer�r�r�r�r��set_extra_headers)rN�content_type�
cache_times   r8r#zStaticFileHandler.set_headers�
s��
	
�����1�1�1��������=�$��O�O�O�T�]�;�;�;��,�,�.�.���	:��O�O�N�L�9�9�9��(�(���D�M�<�P�P�
���>�>��O�O���!�(�(�*�*�X�-?�
�-S�-S�-S�S�
�
�
�
�O�O�O�Z�#�j�/�/�-I�J�J�J����t�y�)�)�)�)�)r7c�H�|jj�d��r|���S|jj�d��}|�Mtj�|��}|�,tj|dd��}|j�J�||jkrdSdS)zgReturns True if the headers indicate that we should return 304.

        .. versionadded:: 3.1
        rzIf-Modified-SinceN�TF)	rDr�r�r��email�utils�	parsedater�r")rN�	ims_value�
date_tuple�if_sinces    r8r$z#StaticFileHandler.should_return_304�
s����<��#�#�O�4�4�	,��)�)�+�+�+��L�(�,�,�-@�A�A�	�� ���.�.�y�9�9�J��%�#�,�j��!��n�=���}�0�0�0��t�}�,�,��4��ur7rc��tj�tj�||����}|S)a�Returns the absolute location of ``path`` relative to ``root``.

        ``root`` is the path configured for this `StaticFileHandler`
        (in most cases the ``static_path`` `Application` setting).

        This class method may be overridden in subclasses.  By default
        it returns a filesystem path, but other strings may be used
        as long as they are unique and understood by the subclass's
        overridden `get_content`.

        .. versionadded:: 3.1
        )r_r��abspathr4)rirr�rCs    r8rz#StaticFileHandler.get_absolute_path�
s,���'�/�/�"�'�,�,�t�T�":�":�;�;���r7r c�r�tj�|��}|�tjj��s|tjjz
}|tjjz�|��st
dd|j���tj�|��r�|j��|j	j�d��sU|j	j�d��rt
dd���|�
|j	jdzd���dStj�||j��}tj�|��st
d	���tj�
|��st
dd
|j���|S)a�Validate and return the absolute path.

        ``root`` is the configured path for the `StaticFileHandler`,
        and ``path`` is the result of `get_absolute_path`

        This is an instance method called during request processing,
        so it may raise `HTTPError` or use methods like
        `RequestHandler.redirect` (return None after redirecting to
        halt further processing).  This is where 404 errors for missing files
        are generated.

        This method may modify the path before returning it, but note that
        any such modifications will not be understood by `make_static_url`.

        In instance methods, this method's result is available as
        ``self.absolute_path``.

        .. versionadded:: 3.1
        r�z"%s is not in root static directoryNr�z//z-cannot redirect path with two initial slashesTrurvz%s is not a file)r_r�rCrw�sepr�rl�isdirrrDrr4�exists�isfile)rNrr s   r8rz(StaticFileHandler.validate_absolute_path�
sz��0�w���t�$�$���}�}�R�W�[�)�)�	 �
�B�G�K��D�����+�7�7��=�=�	R��C�!E�t�y�Q�Q�Q�
�7�=�=��'�'�	O�D�,A�,M��<�$�-�-�c�2�2�
��<�$�/�/��5�5��$��L�����
�
�d�l�/�#�5��
�F�F�F��t��G�L�L���8M�N�N�M��w�~�~�m�,�,�	!��C�.�.� ��w�~�~�m�,�,�	@��C�!3�T�Y�?�?�?��r7rCr�r,c#�4K�t|d��5}|�|�|��|�||pdz
}nd}	d}|�||kr|}|�|��}|r|�|t|��z}|V�n|�|dksJ�	ddd��dS�U#1swxYwYdS)aZRetrieve the content of the requested resource which is located
        at the given absolute path.

        This class method may be overridden by subclasses.  Note that its
        signature is different from other overridable class methods
        (no ``settings`` argument); this is deliberate to ensure that
        ``abspath`` is able to stand on its own as a cache key.

        This method should either return a byte string or an iterator
        of byte strings.  The latter is preferred for large files
        as it helps reduce memory fragmentation.

        .. versionadded:: 3.1
        �rbNrTi)�open�seek�readr�)rirCr�r,�file�	remaining�
chunk_sizers        r8r(zStaticFileHandler.get_content$s����$�'�4�
 �
 �	�D�� ��	�	�%� � � ����5�:�A�.�	�	� �	�
�&�
��(�Y��-C�-C�!*�J��	�	�*�-�-���� �,�!�S��Z�Z�/�	��K�K�K�K� �,�(�A�~�~�~�~��'	�	�	�	�	�	�	�	�
�	�	�	�	����	�	�	�	�	�	s�A,B
�B
�
B�Bc��|�|��}tj��}t|t��r|�|��n|D]}|�|���|���S)z�Returns a version string for the resource at the given path.

        This class method may be overridden by subclasses.  The
        default implementation is a SHA-512 hash of the file's contents.

        .. versionadded:: 3.1
        )r(r�sha512r�r�rfr)rirCr�rrs     r8�get_content_versionz%StaticFileHandler.get_content_versionKs�����w�'�'����!�!���d�E�"�"�	%��M�M�$������
%�
%���
�
�e�$�$�$�$����!�!�!r7c�~�|j�J�t|d��stj|j��|_|jS)N�_stat_result)r r�r_�statrUrds r8�_statzStaticFileHandler._stat]sA���!�-�-�-��t�^�,�,�	<� "���(:� ;� ;�D��� � r7c�8�|���}|jS)a%Retrieve the total size of the resource at the given path.

        This method may be overridden by subclasses.

        .. versionadded:: 3.1

        .. versionchanged:: 4.0
           This method is now always called, instead of only when
           partial results are requested.
        )rW�st_size)rN�stat_results  r8r&z"StaticFileHandler.get_content_sizecs���j�j�l�l���"�"r7c��|���}tj�t|j����}|S)z�Returns the time that ``self.absolute_path`` was last modified.

        May be overridden in subclasses.  Should return a `~datetime.datetime`
        object or None.

        .. versionadded:: 3.1
        )rWr��utcfromtimestampr�st_mtime)rNrZr"s   r8r!z#StaticFileHandler.get_modified_timeqs9���j�j�l�l���$�5�5�c�+�:N�6O�6O�P�P���r7c�p�|j�J�tj|j��\}}|dkrdS|�dS|�|SdS)zhReturns the ``Content-Type`` header to be used for this request.

        .. versionadded:: 3.1
        Nr�zapplication/gzipzapplication/octet-stream)r �	mimetypes�
guess_type)rN�	mime_type�encodings   r8r5z"StaticFileHandler.get_content_type�s^��
�!�-�-�-�'�2�4�3E�F�F��	�8��v���%�%��
!�-�-�
�
"���.�-r7c��dS)z1For subclass to add extra headers to the responseNr6rs  r8r7z#StaticFileHandler.set_extra_headers�r�r7r"rac�0�d|jjvr|jndS)a�Override to customize cache control behavior.

        Return a positive number of seconds to make the result
        cacheable for that amount of time or 0 to mark resource as
        cacheable for an unspecified amount of time (subject to
        browser heuristics).

        By default returns cache expiry of 10 years for resources requested
        with ``v`` argument.
        r�r)rDr��
CACHE_MAX_AGE)rNr�r"ras    r8r6z StaticFileHandler.get_cache_time�s!��&)�D�L�,B�%B�%B�t�!�!��Ir7rh�include_versionc�~�|�dd��|z}|s|S|�||��}|s|S|�d|��S)aConstructs a versioned url for the given path.

        This method may be overridden in subclasses (but note that it
        is a class method rather than an instance method).  Subclasses
        are only required to implement the signature
        ``make_static_url(cls, settings, path)``; other keyword
        arguments may be passed through `~RequestHandler.static_url`
        but are not standard.

        ``settings`` is the `Application.settings` dictionary.  ``path``
        is the static path being requested.  The url returned should be
        relative to the current host.

        ``include_version`` determines whether the generated URL should
        include the query string containing the version hash of the
        file corresponding to the given ``path``.

        r�r�z?v=)r��get_version)rirhr�rfr�r1s      r8rz!StaticFileHandler.make_static_url�s[��,�l�l�.�
�;�;�d�B���	��J����x��6�6���	��J��C�C���.�.r7�url_pathc�z�tjjdkr%|�dtjj��}|S)a"Converts a static URL path into a filesystem path.

        ``url_path`` is the path component of the URL with
        ``static_url_prefix`` removed.  The return value should be
        filesystem path relative to ``static_path``.

        This is the inverse of `make_static_url`.
        r�)r_r�rEr�)rNris  r8rz StaticFileHandler.parse_url_path�s1���7�;�#����'�'��R�W�[�9�9�H��r7c�d�|�|d|��}|�|��S)a%Generate the version string to be used in static URLs.

        ``settings`` is the `Application.settings` dictionary and ``path``
        is the relative location of the requested asset on the filesystem.
        The returned value should be a string, or ``None`` if no version
        could be determined.

        .. versionchanged:: 3.1
           This method was previously recommended for subclasses to override;
           `get_content_version` is now preferred as it allows the base
           class to handle caching of the result.
        r�)rr0)rirhr��abs_paths    r8rhzStaticFileHandler.get_version�s2���(�(��-�)@�$�G�G���&�&�x�0�0�0r7rlc�.�|j5|j}||vrD	|�|��||<n*#t$rt	jd|��d||<YnwxYw|�|��}|r|cddd��S	ddd��n#1swxYwYdS)NzCould not open static file %r)rrrSrrr�r�)rirl�hashes�hshs    r8r0z%StaticFileHandler._get_cached_version�s"��
�Y�
	�
	��'�F��v�%�%�,�'*�'>�'>�x�'H�'H�F�8�$�$�� �,�,�,��M�"A�8�L�L�L�'+�F�8�$�$�$�,�����*�*�X�&�&�C��
��
	�
	�
	�
	�
	�
	�
	�
	�
�
	�
	�
	�
	�
	�
	�
	�
	�
	�
	�
	����
	�
	�
	�
	��ts1�B
�.�B
�$A�B
�A�B
�
B�BrIrNrO)NN)+r3r4r5rPrerrQrRrr�r"ra�classmethodr�r#rWr�r�rr#r$rrrr(r�r(rSr_rZrWr&r�r!r5r7r6rr rrrhr0r6r7r8rr�	s�������@�@�D%�M��N��I�N���E�1�1�s�1�h�s�m�1�t�1�1�1�1��$�$�$��[�$�2��2��4��2�2�2�2�Q1�Q1�c�Q1��Q1��Q1�Q1�Q1�Q1�f
(�h�s�m�
(�
(�
(�
(�*�*�*�*�2�4�����,��S���������[�� 9�3�9�s�9�x�PS�}�9�9�9�9�v�MQ�$�$��$�"*�3�-�$�=E�c�]�$�	�5�$��$�	%�$�$�$��[�$�L�"�#�"�#�"�"�"��[�"�"!�r�~�!�!�!�!�#�#�#�#�#�#��8�H�,=�#>�����(.�#�.�.�.�.�*
�c�
�d�
�
�
�
�
J��
J�#+�H�,=�#>�
J�KN�
J�	�
J�
J�
J�
J��JN�/�/��C��H�~�/�-0�/�CG�/�	�/�/�/��[�/�>�s��s������1�4��S��>�1��1��#��1�1�1��[�1� ��3��8�C�=�����[���r7rc�F�eZdZdZdeejgdfddfd�Zdd�ZdS)�FallbackHandleraMA `RequestHandler` that wraps another HTTP server callback.

    The fallback is a callable object that accepts an
    `~.httputil.HTTPServerRequest`, such as an `Application` or
    `tornado.wsgi.WSGIContainer`.  This is most useful to use both
    Tornado ``RequestHandlers`` and WSGI in the same server.  Typical
    usage::

        wsgi_app = tornado.wsgi.WSGIContainer(
            django.core.handlers.wsgi.WSGIHandler())
        application = tornado.web.Application([
            (r"/foo", FooHandler),
            (r".*", FallbackHandler, dict(fallback=wsgi_app),
        ])
    �fallbackNrFc��||_dSrI)rs)rNrss  r8razFallbackHandler.initializes��!��
�
�
r7c�p�|�|j��d|_|���dS)NT)rsrDrUrrrds r8rpzFallbackHandler.prepares3���
�
�d�l�#�#�#�����������r7rN)	r3r4r5rPr&rrUrarpr6r7r8rrrr�sf�������� !� �(�"<�!=�t�!C�D�!�	
�!�!�!�!�
�����r7rrc
��eZdZdZdejddfd�Zdedejde	d	e
deeeje	ff
d
�Zde	d	e
de	fd�Z
dS)rz�A transform modifies the result of an HTTP request (e.g., GZip encoding)

    Applications are not expected to create their own OutputTransforms
    or interact with them directly; the framework chooses which transforms
    (if any) to apply.
    rDrFNc��dSrIr6�rNrDs  r8rSzOutputTransform.__init__rfr7r�r�r�	finishingc��|||fSrIr6)rNr�r�rrys     r8rz%OutputTransform.transform_first_chunk"s���G�U�*�*r7c��|SrIr6�rNrrys   r8r�zOutputTransform.transform_chunk+s���r7)r3r4r5rPrrUrSrr�r�r�r$rr�r6r7r8rrs���������
�� :�
�t�
�
�
�
�+��+��%�+��	+�
�+�
�s�H�(�%�/�	0�
+�+�+�+��U��t��������r7rc
��eZdZdZegd���ZdZdZdej	ddfd�Z
d	edefd
�Z
dedejd
ededeeejeff
d�Zd
ededefd�ZdS)r�aIApplies the gzip content encoding to the response.

    See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11

    .. versionchanged:: 4.0
        Now compresses all mime types beginning with ``text/``, instead
        of just a whitelist. (the whitelist is still used for certain
        non-text mime types).
    )zapplication/javascriptzapplication/x-javascriptzapplication/xmlzapplication/atom+xmlzapplication/jsonzapplication/xhtml+xmlz
image/svg+xmlr;irDrFNc�J�d|j�dd��v|_dS)Nr��Accept-Encodingr�)r�r��	_gzippingrxs  r8rSzGZipContentEncoding.__init__Rs%���7�?�#6�#6�7H�"�#M�#M�M����r7�ctypec�>�|�d��p||jvS)Nztext/)r��
CONTENT_TYPES)rNr�s  r8�_compressible_typez&GZipContentEncoding._compressible_typeUs#������(�(�G�E�T�5G�,G�Gr7r�r�rryc�@�d|vr|dxxdz
cc<nd|d<|jrut|�dd�����d��d}|�|��o|pt|��|jkod|v|_|jr}d	|d<t��|_tj
d
|j|j���|_|�
||��}d|vr%|r tt|����|d<n|d=|||fS)
N�Varyz, Accept-Encodingrr}r�r�rrLr��w)�mode�fileobj�
compresslevelr�)r�rr�r�r�r��
MIN_LENGTHr�_gzip_valuer��GzipFile�
GZIP_LEVEL�
_gzip_filer�r�)rNr�r�rryr�s      r8rz)GZipContentEncoding.transform_first_chunkXsM���W����F�O�O�O�2�2�O�O�O�O�/�G�F�O��>�	��W�[�[���<�<�=�=�C�C�C�H�H��K�E��'�'��.�.�8�"�]�C�c�%�j�j�D�O�&C�8�'�w�6�
�N�
�>�	2�*0�G�&�'�&�y�y�D��"�m��$�"2�$�/����D�O��(�(��	�:�:�E��7�*�*�
�2�03�C��J�J���G�,�-�-�� 0�1��G�U�*�*r7c�L�|jr�|j�|��|r|j���n|j���|j���}|j�d��|j�d��|S)Nr)	r�r�r �closer�r��getvalue�truncaterLr|s   r8r�z#GZipContentEncoding.transform_chunk}s����>�	%��O�!�!�%�(�(�(��
(���%�%�'�'�'�'���%�%�'�'�'��$�-�-�/�/�E���%�%�a�(�(�(���!�!�!�$�$�$��r7)r3r4r5rPrNr�r�r�rrUrSr�r�r�rr�r�r$rr�r6r7r8r�r�/s!���������C�	
�	
�	
�
�
�M��J��J�N�� :�N�t�N�N�N�N�H��H��H�H�H�H�#+��#+��%�#+��	#+�
�#+�
�s�H�(�%�/�	0�
#+�#+�#+�#+�J
�U�
�t�
��
�
�
�
�
�
r7r�c���tj���dtdttdf�fd���}|S)a�Decorate methods with this to require that the user be logged in.

    If the user is not logged in, they will be redirected to the configured
    `login url <RequestHandler.get_login_url>`.

    If you configure a login url with a query parameter, Tornado will
    assume you know what you're doing and use it as-is.  If not, it
    will add a `next` parameter so the login page knows where to send
    you once you're logged in.
    rNrFNc���|js�|jjdvr�|���}d|vr{tj�|��jr|j���}n|jj	�J�|jj	}|dtt|�����zz
}|�|��dStd����|g|�Ri|��S)Nr�rt)�nextr�)rprDr�r��urllib�parse�urlsplit�scheme�full_urlr8rrrrl)rNrirEr��next_urlr�s     �r8r{zauthenticated.<locals>.wrapper�s����� �
	!��|�"�o�5�5��(�(�*�*���c�>�>��|�,�,�S�1�1�8�4�#'�<�#8�#8�#:�#:���#�|�/�;�;�;�#'�<�#3���3��4�X�+>�+>�+>�!?�!?�?�?�C��
�
�c�"�"�"��t��C�.�.� ��v�d�,�T�,�,�,�V�,�,�,r7r|rs` r8�
authenticatedr��sX����_�V���-��-�	�)�D�/�	"�-�-�-�-�-���-�&�Nr7c��eZdZdZdeddfd�Zedefd���Zdedede	fd	�Z
dee	fd
�Zdee
e	fd�Zdee	fd�Zdee
e	fd
�Zdee	fd�Zdee	fd�Zde	dedefd�ZdS)rDa2A re-usable, modular UI unit on a page.

    UI modules often execute additional queries, and they can include
    additional CSS and JavaScript that will be included in the output
    page, which is automatically inserted on page render.

    Subclasses of UIModule must override the `render` method.
    rorFNc�\�||_|j|_|j|_|j|_dSrI)rorDrZr
)rNros  r8rSzUIModule.__init__�s(����������*����n����r7c��|jjSrI)rorprds r8rpzUIModule.current_user�s
���|�(�(r7rirEc��t���)z6Override in subclasses to return this module's output.r0rms   r8rFzUIModule.render�s��!�#�#�#r7c��dS)zJOverride to return a JavaScript string
        to be embedded in the page.Nr6rds r8r'zUIModule.embedded_javascript��	���tr7c��dS)z�Override to return a list of JavaScript files needed by this module.

        If the return values are relative paths, they will be passed to
        `RequestHandler.static_url`; otherwise they will be used as-is.
        Nr6rds r8r(zUIModule.javascript_files��	���tr7c��dS)zJOverride to return a CSS string
        that will be embedded in the page.Nr6rds r8r*zUIModule.embedded_css�r�r7c��dS)z�Override to returns a list of CSS files required by this module.

        If the return values are relative paths, they will be passed to
        `RequestHandler.static_url`; otherwise they will be used as-is.
        Nr6rds r8r+zUIModule.css_files�r�r7c��dS)z[Override to return an HTML string that will be put in the <head/>
        element.
        Nr6rds r8r,zUIModule.html_head��	���tr7c��dS)zfOverride to return an HTML string that will be put at the end of
        the <body/> element.
        Nr6rds r8r-zUIModule.html_body�r�r7r�c�(�|jj|fi|��S)z.Renders a template and returns it as a string.)ror%)rNr�rEs   r8r%zUIModule.render_string�s��)�t�|�)�$�9�9�&�9�9�9r7)r3r4r5rPr:rSrVr rpr�rFr"r'r'r(r*r+r,r-r�r%r6r7r8rDrD�s}��������%��%�4�%�%�%�%��)�c�)�)�)��X�)�$�C�$�3�$�3�$�$�$�$��X�c�]�����
�(�8�C�=�"9������h�s�m�����
�8�H�S�M�2������8�C�=������8�C�=�����:�#�:��:��:�:�:�:�:�:r7rDc�"�eZdZdededefd�ZdS)r��textrErFc�&�tj|fi|��SrI)rr�)rNr�rEs   r8rFz_linkify.render�s���~�d�-�-�f�-�-�-r7N)r3r4r5r�r rFr6r7r8r�r��s=������.�3�.�#�.�#�.�.�.�.�.�.r7r�c��eZdZdefd�ZdS)r�rFc�4�|j���SrI)rorsrds r8rFz_xsrf_form_html.render�s���|�*�*�,�,�,r7N)r3r4r5r�rFr6r7r8r�r��s/������-��-�-�-�-�-�-r7r�c���eZdZdZdeddf�fd�Zdededefd�Z	d	ede
efd
�Zdefd�Zde
efd�Z
defd
�Zde
efd�Zdefd�Zdefd�Z�xZS)r�a�UIModule that simply renders the given template.

    {% module Template("foo.html") %} is similar to {% include "foo.html" %},
    but the module version gets its own namespace (with kwargs passed to
    Template()) instead of inheriting the outer template's namespace.

    Templates rendered through this module also get access to UIModule's
    automatic JavaScript/CSS features.  Simply call set_resources
    inside the template and give it keyword arguments corresponding to
    the methods on UIModule: {{ set_resources(js_files=static_url("my.js")) }}
    Note that these resources are output once per template file, not once
    per instantiation of the template, so they must not depend on
    any arguments to the template.
    rorFNc�f��t���|��g|_i|_dSrI)rRrS�_resource_list�_resource_dict)rNrorbs  �r8rSzTemplateModule.__init__
s1���
������!�!�!� ��� ����r7r�rEc�B���dtf��fd�}�j�fd|i|��S)NrFc�����jvr%�j�|��|�j�<n �j�|krtd���dS)NzCset_resources called with different resources for the same templater�)r�r�r�r�)rEr�rNs ��r8�
set_resourcesz,TemplateModule.render.<locals>.set_resources
si����4�.�.�.��#�*�*�6�2�2�2�,2��#�D�)�)��&�t�,��6�6�$�:�����2r7r�)r�r%)rNr�rEr�s``  r8rFzTemplateModule.render
sP����
	�s�
	�
	�
	�
	�
	�
	�
	�"�t�!�$�N�N�m�N�v�N�N�Nr7r�c�*���fd�|jD��S)Nc3�0�K�|]}�|v�|�V��dSrIr6)rK�rr�s  �r8rOz0TemplateModule._get_resources.<locals>.<genexpr>"
s+�����@�@�1�s�a�x�x��#��x�x�x�x�@�@r7)r��rNr�s `r8�_get_resourceszTemplateModule._get_resources!
s ���@�@�@�@�� 3�@�@�@�@r7c�R�d�|�d����S)N�
r'�r4r�rds r8r'z"TemplateModule.embedded_javascript$
s#���y�y��,�,�-B�C�C�D�D�Dr7c���g}|�d��D]I}t|ttf��r|�|���4|�|���J|S)Nr(�r�r�rr�r�r)�rNr-r�s   r8r(zTemplateModule.javascript_files'
sk�����$�$�%7�8�8�	!�	!�A��!�l�E�2�3�3�
!��
�
�a� � � � ��
�
�a� � � � ��
r7c�R�d�|�d����S)Nr�r*r�rds r8r*zTemplateModule.embedded_css0
s"���y�y��,�,�^�<�<�=�=�=r7c���g}|�d��D]I}t|ttf��r|�|���4|�|���J|S)Nr+r�r�s   r8r+zTemplateModule.css_files3
sj�����$�$�[�1�1�	!�	!�A��!�l�E�2�3�3�
!��
�
�a� � � � ��
�
�a� � � � ��
r7c�R�d�|�d����S)Nr�r,r�rds r8r,zTemplateModule.html_head<
�"���w�w�t�*�*�;�7�7�8�8�8r7c�R�d�|�d����S)Nr�r-r�rds r8r-zTemplateModule.html_body?
r�r7)r3r4r5rPr:rSr�r r�rFr'r�r'r(r*r+r,r-rerfs@r8r�r��s`�������
�
�!��!�4�!�!�!�!�!�!�
O�3�
O�#�
O�%�
O�
O�
O�
O�A�#�A�(�3�-�A�A�A�A�E�S�E�E�E�E��(�3�-�����>�c�>�>�>�>��8�C�=�����9�3�9�9�9�9�9�3�9�9�9�9�9�9�9�9r7r�c��eZdZdZdedeeeefddfd�Z	dede
deffd	�Zdede
deffd
�ZdS)r[zALazy namespace which creates UIModule proxies bound to a handler.ror\rFNc�"�||_||_dSrI)ror\)rNror\s   r8rSz_UIModuleNamespace.__init__F
s�����$����r7r�.c�N�|j�||j|��SrI)rorHr\r�s  r8�__getitem__z_UIModuleNamespace.__getitem__L
s!���|�&�&�s�D�O�C�,@�A�A�Ar7c�p�	||S#t$r!}tt|�����d}~wwxYwrI)r��AttributeErrorr�)rNr�r,s   r8�__getattr__z_UIModuleNamespace.__getattr__O
sD��	)���9����	)�	)�	)� ��Q���(�(�(�����	)���s�
�
5�0�5)
r3r4r5rPr:rr�r)rDrSr&r�r�r6r7r8r[r[C
s�������K�K�%�%�%�37��T�(�^�8K�3L�%�	
�%�%�%�%�B�s�B�x��S��'9�B�B�B�B�)�s�)�x��S��'9�)�)�)�)�)�)r7r[r	r�r�r��clockrc	��|�t}|�tj}ttt	|��������}tjt|����}|dkrCt|t��rJ�t||||��}d�
|||g��}|S|dkr�dtttfdtfd�}d�
d|t|pd����||��||��||��d	g��}	t|t��r$|�
Jd
���|dks
Jd���||}t||	��}|	|zStd|z���)
Nr/r�r0r�rFc�`�tdt|��z��t|��zS)Nz%d:)rr�)r�s r8�format_fieldz)create_signed_value.<locals>.format_fieldy
s%�����A����'�'�$�q�'�'�1�1r7r�rr7z2Key version must be set when sign key dict is usedz2Version must be at least 2 for key version supportzUnsupported version %d)�DEFAULT_SIGNED_VALUE_VERSIONr�rr�r�base64�	b64encoder�r�_create_signature_v1r4r!r��_create_signature_v2r�)
r	r�r�r�r�rr��	signaturer��to_signs
          r8rrV
s�����.���}��	���S��U�U�W�W���&�&�'�'�I���T�%�[�[�)�)�E��!�|�|��f�d�+�+�+�+�+�(���u�i�H�H�	��	�	�5�)�Y�7�8�8����	�A���	2�E�#�u�*�-�	2�%�	2�	2�	2�	2��)�)����S��!1��2�2�3�3���Y�'�'���T�"�"���U�#�#��

�	
�	
���f�d�#�#�	)��'�'�C�(�'�'��a�<�<�<�!U�<�<�<��K�(�F�(���9�9�	���"�"��1�G�;�<�<�<r7s^([1-9][0-9]*)\|(.*)$c��t�|��}|�d}n>	t|�d����}|dkrd}n#t$rd}YnwxYw|S)Nr/i�)r�r�rr�r�)r�rMr�s   r8�_get_versionr��
sw��	!�&�&�u�-�-�A��y����	��!�'�'�!�*�*�o�o�G���}�}������	�	�	��G�G�G�	�����Ns�*A�A�Ar
rrc�J�|�tj}|�t}|dkrtd|z���|sdSt|��}t	|��}||krdS|dkr*t|t��rJ�t|||||��S|dkrt|||||��SdS)Nr0zUnsupported min_version %dr/)	r�� DEFAULT_SIGNED_VALUE_MIN_VERSIONr�rr�r�r�_decode_signed_value_v1�_decode_signed_value_v2)r	r�r�rr�rr�s       r8rr�
s���
�}��	����6���Q����5��C�D�D�D����t���K�K�E��5�!�!�G������t��!�|�|��f�d�+�+�+�+�+�&�v�t�U�L�%�P�P�P�	�A���&�v�t�U�L�%�P�P�P��tr7c��t|���d��}t|��dkrdSt|||d|d��}t	j|d|��st
jd|��dSt|d��}||��|dzz
krt
jd|��dS||��d	zkrt
jd
|��dS|d�	d��rt
jd|��dS	tj|d��S#t$rYdSwxYw)
Nr��rr/r0zInvalid cookie signature %r�QzExpired cookie %ri��(z1Cookie timestamp in future; possible tampering %r�0zTampered cookie %r)
rr�r�r�r�r�rrBrr�r��	b64decoder)r	r�r�rr�r�r�r�s        r8r�r��
s]��
��K�K���d�#�#�E�
�5�z�z�Q����t�$�V�T�5��8�U�1�X�F�F�I���u�Q�x��3�3����5�u�=�=�=��t��E�!�H�
�
�I��5�5�7�7�\�E�1�1�1�1���+�U�3�3�3��t��5�5�7�7�Z�'�'�'�	��K�U�S�S�S��t��Q�x���4� � ����,�e�4�4�4��t�����a��)�)�)�������t�t����s�#D=�=
E�
Ec��dtdtttffd�}|dd�}||��\}}||��\}}||��\}}||��\}}t|��||||fS)Nr�rFc���|�d��\}}}t|��}|d|�}|||dz�dkrtd���||dzd�}||fS)N�:r/r�zmalformed v2 signed value field)�	partitionrr�)r��lengthrq�restrL�field_values      r8�_consume_fieldz)_decode_fields_v2.<locals>._consume_field�
su���+�+�d�+�+����4���K�K���2�A�2�h����A��E�	�?�d�"�"��>�?�?�?��A��E�G�G�}���D� � r7r0)r�r$r)r�r�r�rr��
name_field�value_field�
passed_sigs        r8�_decode_fields_v2r��
s���	!�%�	!�E�%��,�$7�	!�	!�	!�	!�����9�D�&��t�,�,��K��$�n�T�*�*�O�I�t�%�~�d�+�+��J��,�n�T�2�2��K���{���Y�
�K��K�Kr7c���	t|��\}}}}}	n#t$rYdSwxYw|dt|	���}
t|t��r	||}n#t
$rYdSwxYwt
||
��}tj|	|��sdS|t|��krdSt|��}||��|dzz
krdS	tj|��S#t$rYdSwxYw)Nr�)r�r�r�r�rr�r�r�r�rrr�r�r)
r	r�r�rr�r�timestamp_bytesr�r�r��
signed_string�expected_sigr�s
             r8r�r�sP��	�
�e�$�$�
	
������J�������t�t������,�S��_�_�,�,�-�M��&�$����	��K�(�F�F���	�	�	��4�4�	����(��
�>�>�L���z�<�8�8���t��T�$�Z�Z����t��O�$�$�I��5�5�7�7�\�E�1�1�1�1��t�����,�,�,�������t�t����s0��
&�&�A � 
A.�-A.�C'�'
C5�4C5c��t|��}t|��}|dkrdS	t|��\}}}}}n#t$rYdSwxYw|S)Nr0)rr�r�r�)r�r�rrqs    r8rr.sq����K�K�E��5�!�!�G���{�{��t��"3�E�":�":���Q��1�a�a�������t�t������s�>�
A�Ar�c���tjt|��tj���}|D]$}|�t|�����%t|�����S�N)�	digestmod)r��newrrr
rfr)r	r��hashr�s    r8r�r�;s`���8�D��L�L�G�L�9�9�9�D�� � �����D��J�J��������� � �!�!�!r7r�c���tjt|��tj���}|�t|����t|�����Sr�)r�r�rr�sha256rfr)r	r�r�s   r8r�r�BsN���8�D��L�L�G�N�;�;�;�D��K�K��Q���������� � �!�!�!r7r�c�:��t�fd�dD����S)Nc3�B�K�|]}��|��V��dSrIr)rKrr�s  �r8rOzis_absolute.<locals>.<genexpr>Is/�����D�D�a�t���q�!�!�D�D�D�D�D�Dr7)r�zhttp:zhttps:)�any)r�s`r8rOrOHs'����D�D�D�D�+C�D�D�D�D�D�Dr7r�)r
NN)�rPr�r�r��email.utilsr<r}r�rr��http.cookiesr��inspectr�iorr_r��os.pathr_r�r�rZrQr�r�r�r��urllib.parser�r�tornado.concurrentrrrr	�tornado.httpserverr
rr�tornado.localer
�tornado.logrrr�tornado.netutilr�tornado.escaperr�tornado.routingrrrrrrrr�tornado.utilrrrr��typingrr r!r"r#r$r%r&r'r(r)r*r+r,r-�
TYPE_CHECKINGr.r�rr�r]r��_CookieSecretTypes�"MIN_SUPPORTED_SIGNED_VALUE_VERSION�"MAX_SUPPORTED_SIGNED_VALUE_VERSIONr�r�r2r^rSr��objectr:rgror�rur�r�r�rCr�r�rrlr<r�r�rrrrrr�r�rDr�r�r�r[r�rr�r�rr�r�r�rr�r�rOr6r7r8�<module>rs��� -�-�^�
�
�
���������������������������������������������������������	�	�	�	�
�
�
�
�
�
�
�
�������������������������"�"�"�"�"�"�I�I�I�I�I�I�I�I�������������)�)�)�)�)�)�����������������������4�4�4�4�4�4�4�4�4�4�����������)�)�)�)�)�)�)�)�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�C�B�B�B�B�B�B�B�B�B�
����������������������������������  ������
�
�
�
�	���������
�U�L�#�w�/?��AR�R�S���3��t�C��H�~�t�C��J�7G�G�H��&'�"��&'�"�� !���$%� ��	�	�	�	�	�	�	�	�!� �"�"���2�:�C�D�D��~!�~!�~!�~!�~!�V�~!�~!�~!�B4�g�3�>�J�J�J���T�"5�6��4�@S�;T�����6$�$�~�"6�$�4�$�$�$�$���S�(�9�T�?�3�3�4��
�c�8�I�d�O�,�,�-�����:��S�(�9�T�?�3�3�4��
�c�8�I�d�O�,�,�-�����6$M�$M�$M�$M�$M�-�$M�$M�$M�N{
�{
�{
�{
�{
�"�{
�{
�{
�|	W-�W-�W-�W-�W-�x�3�W-�W-�W-�t/�/�/�/�/�	�/�/�/�d	�	�	�	�	�Y�	�	�	�8!�!�!�!�!�9�!�!�!�

�

�

�

�

�>�

�

�

� -9�-9�-9�-9�-9�n�-9�-9�-9�`E�E�E�E�E��E�E�E�P�����n����8�����f����0X�X�X�X�X�/�X�X�X�v"��S�(�9�T�?�3�3�4�"�
�c�8�I�d�O�,�,�-�"�"�"�"�J@:�@:�@:�@:�@:�v�@:�@:�@:�F.�.�.�.�.�x�.�.�.�
-�-�-�-�-�h�-�-�-�
D9�D9�D9�D9�D9�X�D9�D9�D9�N)�)�)�)�)��)�)�)�."�+/�!%�
;=�;=��;=�

�;=���e���;=��c�]�	;=�
�H�R��Y�'�(�;=��#��
;=��;=�;=�;=�;=�@&�2�:�&?�@�@�����#�����6�+/�!%�
����

����s�E�!�"���	�
�H�R��Y�'�(���#��
��e�_�����> ��#�u�*�� �

� �� ��	 �
�B��I�� ��e�_�
 � � � �FL�U�L�u�S�%���u�-L�'M�L�L�L�L�(%��%�

�%��%��	%�
�B��I��%��e�_�
%�%�%�%�P
�U�3��:�%6�
�8�C�=�
�
�
�
�"��s�E�z�!2�"�E�#�u�*�<M�"�RW�"�"�"�"�"��s�E�z�!2�"�u�"��"�"�"�"�E�c�E�d�E�E�E�E�E�Er7

Youez - 2016 - github.com/yon3zu
LinuXploit