§
    ‹Ÿj4b  ã                   ó>  — d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZmZmZmZ dd	lmZmZmZmZmZmZmZmZmZmZ  G d
„ dej        ¦  «        Z G d„ de¦  «        Z  G d„ dej!        ¦  «        Z" G d„ dej!        ¦  «        Z#eedee         eee$df         ef         eee$df         eee$ef         f         eee$df         eee$ef         e$f         f                  Z% G d„ de¦  «        Z& G d„ de e&¦  «        Z' G d„ d¦  «        Z( G d„ d¦  «        Z) G d„ de)¦  «        Z* G d„ de)¦  «        Z+ G d„ de)¦  «        Z, G d „ d!e)¦  «        Z- G d"„ d#e(¦  «        Z.ed$e$d%e/fd&„¦   «         Z0ed)d'„¦   «         Z0d$ee$         d%ee/         fd(„Z0dS )*ap  Flexible routing implementation.

Tornado routes HTTP requests to appropriate handlers using `Router`
class implementations. The `tornado.web.Application` class is a
`Router` implementation and may be used directly, or the classes in
this module may be used for additional flexibility. The `RuleRouter`
class can match on more criteria than `.Application`, or the `Router`
interface can be subclassed for maximum customization.

`Router` interface extends `~.httputil.HTTPServerConnectionDelegate`
to provide additional routing capabilities. This also means that any
`Router` implementation can be used directly as a ``request_callback``
for `~.httpserver.HTTPServer` constructor.

`Router` subclass must implement a ``find_handler`` method to provide
a suitable `~.httputil.HTTPMessageDelegate` instance to handle the
request:

.. code-block:: python

    class CustomRouter(Router):
        def find_handler(self, request, **kwargs):
            # some routing logic providing a suitable HTTPMessageDelegate instance
            return MessageDelegate(request.connection)

    class MessageDelegate(HTTPMessageDelegate):
        def __init__(self, connection):
            self.connection = connection

        def finish(self):
            self.connection.write_headers(
                ResponseStartLine("HTTP/1.1", 200, "OK"),
                HTTPHeaders({"Content-Length": "2"}),
                b"OK")
            self.connection.finish()

    router = CustomRouter()
    server = HTTPServer(router)

The main responsibility of `Router` implementation is to provide a
mapping from a request to `~.httputil.HTTPMessageDelegate` instance
that will handle this request. In the example above we can see that
routing is possible even without instantiating an `~.web.Application`.

For routing to `~.web.RequestHandler` implementations we need an
`~.web.Application` instance. `~.web.Application.get_handler_delegate`
provides a convenient way to create `~.httputil.HTTPMessageDelegate`
for a given request and `~.web.RequestHandler`.

Here is a simple example of how we can we route to
`~.web.RequestHandler` subclasses by HTTP method:

.. code-block:: python

    resources = {}

    class GetResource(RequestHandler):
        def get(self, path):
            if path not in resources:
                raise HTTPError(404)

            self.finish(resources[path])

    class PostResource(RequestHandler):
        def post(self, path):
            resources[path] = self.request.body

    class HTTPMethodRouter(Router):
        def __init__(self, app):
            self.app = app

        def find_handler(self, request, **kwargs):
            handler = GetResource if request.method == "GET" else PostResource
            return self.app.get_handler_delegate(request, handler, path_args=[request.path])

    router = HTTPMethodRouter(Application())
    server = HTTPServer(router)

`ReversibleRouter` interface adds the ability to distinguish between
the routes and reverse them to the original urls using route's name
and additional arguments. `~.web.Application` is itself an
implementation of `ReversibleRouter` class.

`RuleRouter` and `ReversibleRuleRouter` are implementations of
`Router` and `ReversibleRouter` interfaces and can be used for
creating rule-based routing configurations.

Rules are instances of `Rule` class. They contain a `Matcher`, which
provides the logic for determining whether the rule is a match for a
particular request and a target, which can be one of the following.

1) An instance of `~.httputil.HTTPServerConnectionDelegate`:

.. code-block:: python

    router = RuleRouter([
        Rule(PathMatches("/handler"), ConnectionDelegate()),
        # ... more rules
    ])

    class ConnectionDelegate(HTTPServerConnectionDelegate):
        def start_request(self, server_conn, request_conn):
            return MessageDelegate(request_conn)

2) A callable accepting a single argument of `~.httputil.HTTPServerRequest` type:

.. code-block:: python

    router = RuleRouter([
        Rule(PathMatches("/callable"), request_callable)
    ])

    def request_callable(request):
        request.write(b"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nOK")
        request.finish()

3) Another `Router` instance:

.. code-block:: python

    router = RuleRouter([
        Rule(PathMatches("/router.*"), CustomRouter())
    ])

Of course a nested `RuleRouter` or a `~.web.Application` is allowed:

.. code-block:: python

    router = RuleRouter([
        Rule(HostMatches("example.com"), RuleRouter([
            Rule(PathMatches("/app1/.*"), Application([(r"/app1/handler", Handler)])),
        ]))
    ])

    server = HTTPServer(router)

In the example below `RuleRouter` is used to route between applications:

.. code-block:: python

    app1 = Application([
        (r"/app1/handler", Handler1),
        # other handlers ...
    ])

    app2 = Application([
        (r"/app2/handler", Handler2),
        # other handlers ...
    ])

    router = RuleRouter([
        Rule(PathMatches("/app1.*"), app1),
        Rule(PathMatches("/app2.*"), app2)
    ])

    server = HTTPServer(router)

For more information on application-level routing see docs for `~.web.Application`.

.. versionadded:: 4.5

é    N)Úpartial)Úhttputil)Ú_CallableAdapter)Ú
url_escapeÚurl_unescapeÚutf8)Úapp_log)Úbasestring_typeÚimport_objectÚre_unescapeÚunicode_type)
ÚAnyÚUnionÚOptionalÚ	AwaitableÚListÚDictÚPatternÚTupleÚoverloadÚSequencec                   ón   — e Zd ZdZdej        dedeej                 fd„Z	de
dej        dej        fd„Zd	S )
ÚRouterzAbstract router interface.ÚrequestÚkwargsÚreturnc                 ó   — t          ¦   «         ‚)aò  Must be implemented to return an appropriate instance of `~.httputil.HTTPMessageDelegate`
        that can serve the request.
        Routing implementations may pass additional kwargs to extend the routing logic.

        :arg httputil.HTTPServerRequest request: current HTTP request.
        :arg kwargs: additional keyword arguments passed by routing implementation.
        :returns: an instance of `~.httputil.HTTPMessageDelegate` that will be used to
            process the request.
        ©ÚNotImplementedError)Úselfr   r   s      ú\/var/www/finuniver-perm.ru/html/student/venv/lib/python3.11/site-packages/tornado/routing.pyÚfind_handlerzRouter.find_handlerÌ   s   € õ "Ñ#Ô#Ð#ó    Úserver_connÚrequest_connc                 ó$   — t          | ||¦  «        S ©N)Ú_RoutingDelegate)r    r$   r%   s      r!   Ústart_requestzRouter.start_requestÚ   s   € õ    k°<Ñ@Ô@Ð@r#   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚHTTPServerRequestr   r   ÚHTTPMessageDelegater"   ÚobjectÚHTTPConnectionr)   © r#   r!   r   r   É   sŒ   € € € € € Ø$Ð$ð$ØÔ1ð$Ø=@ð$à	�(Ô.Ô	/ð$ð $ð $ð $ðAØ!ðAØ19Ô1HðAà	Ô	%ðAð Að Að Að Að Ar#   r   c                   ó2   — e Zd ZdZdededee         fd„ZdS )ÚReversibleRouterzxAbstract router interface for routers that can handle named routes
    and support reversing them to original urls.
    ÚnameÚargsr   c                 ó   — t          ¦   «         ‚)a  Returns url string for a given route name and arguments
        or ``None`` if no match is found.

        :arg str name: route name.
        :arg args: url parameters.
        :returns: parametrized url string for a given route name (or ``None``).
        r   )r    r5   r6   s      r!   Úreverse_urlzReversibleRouter.reverse_urlå   s   € õ "Ñ#Ô#Ð#r#   N)r*   r+   r,   r-   Ústrr   r   r8   r2   r#   r!   r4   r4   à   sK   € € € € € ðð ð$ ð $¨Cð $°H¸S´Mð $ð $ð $ð $ð $ð $r#   r4   c                   óÂ   — e Zd Zdededej        ddfd„Zdeej	        ej
        f         dej        deed                  fd	„Zd
edeed                  fd„Zdd„Zdd„ZdS )r(   Úrouterr$   r%   r   Nc                 ó>   — || _         || _        d | _        || _        d S r'   )r$   r%   Údelegater;   )r    r;   r$   r%   s       r!   Ú__init__z_RoutingDelegate.__init__ñ   s&   € ð 'ˆÔØ(ˆÔØˆŒØˆŒˆˆr#   Ú
start_lineÚheadersc                 ór  — t          |t          j        ¦  «        sJ ‚t          j        | j        | j        ||¬¦  «        }| j                             |¦  «        | _        | j        €9t          j
        d|j        |j        ¦  «         t          | j        ¦  «        | _        | j                             ||¦  «        S )N)Ú
connectionÚserver_connectionr?   r@   z$Delegate for %s %s request not found)Ú
isinstancer   ÚRequestStartLiner.   r%   r$   r;   r"   r=   r	   ÚdebugÚmethodÚpathÚ_DefaultMessageDelegateÚheaders_received)r    r?   r@   r   s       r!   rJ   z!_RoutingDelegate.headers_receivedù   sµ   € õ
 ˜*¥hÔ&?Ñ@Ô@Ð@Ð@Ð@ÝÔ,ØÔ(Ø"Ô.Ø!Øð	
ñ 
ô 
ˆð œ×0Ò0°Ñ9Ô9ˆŒØŒ=Ð ÝŒMØ6ØÔ!Ø”ñô ð õ
 4°DÔ4EÑFÔFˆDŒMàŒ}×-Ò-¨j¸'ÑBÔBÐBr#   Úchunkc                 óH   — | j         €J ‚| j                              |¦  «        S r'   )r=   Údata_received)r    rK   s     r!   rM   z_RoutingDelegate.data_received  s&   € ØŒ}Ð(Ð(Ð(ØŒ}×*Ò*¨5Ñ1Ô1Ð1r#   c                 óJ   — | j         €J ‚| j                              ¦   «          d S r'   )r=   Úfinish©r    s    r!   rO   z_RoutingDelegate.finish  s*   € ØŒ}Ð(Ð(Ð(ØŒ×ÒÑÔÐÐÐr#   c                 óJ   — | j         �| j                              ¦   «          d S d S r'   )r=   Úon_connection_closerP   s    r!   rR   z$_RoutingDelegate.on_connection_close  s,   € ØŒ=Ð$ØŒM×-Ò-Ñ/Ô/Ð/Ð/Ð/ð %Ð$r#   ©r   N)r*   r+   r,   r   r0   r   r1   r>   r   rE   ÚResponseStartLineÚHTTPHeadersr   r   rJ   ÚbytesrM   rO   rR   r2   r#   r!   r(   r(   ð   sñ   € € € € € ðØðØ+1ðØAIÔAXðà	ðð ð ð ðCà˜(Ô3°XÔ5OÐOÔPðCð Ô%ðCð 
�)˜D”/Ô	"ð	Cð Cð Cð Cð02 5ð 2¨X°iÀ´oÔ-Fð 2ð 2ð 2ð 2ðð ð ð ð0ð 0ð 0ð 0ð 0ð 0r#   r(   c                   ó0   — e Zd Zdej        ddfd„Zdd„ZdS )rI   rB   r   Nc                 ó   — || _         d S r'   )rB   )r    rB   s     r!   r>   z _DefaultMessageDelegate.__init__  s   € Ø$ˆŒˆˆr#   c                 ó¸   — | j                              t          j        ddd¦  «        t          j        ¦   «         ¦  «         | j                              ¦   «          d S )NzHTTP/1.1i”  z	Not Found)rB   Úwrite_headersr   rT   rU   rO   rP   s    r!   rO   z_DefaultMessageDelegate.finish"  sV   € ØŒ×%Ò%ÝÔ& z°3¸ÑDÔDÝÔ Ñ"Ô"ñ	
ô 	
ð 	
ð 	Œ×ÒÑ Ô Ð Ð Ð r#   rS   )r*   r+   r,   r   r1   r>   rO   r2   r#   r!   rI   rI     sM   € € € € € ð% 8Ô#:ð %¸tð %ð %ð %ð %ð!ð !ð !ð !ð !ð !r#   rI   ÚRuleÚMatcherc            	       ó´   — e Zd ZdZddee         ddfd„Zdeddfd„Zdd	„Zd
e	j
        dedee	j                 fd„Zded
e	j
        dedee	j                 fd„ZdS )Ú
RuleRouterz!Rule-based router implementation.NÚrulesr   c                 óF   — g | _         |r|                      |¦  «         dS dS )aI  Constructs a router from an ordered list of rules::

            RuleRouter([
                Rule(PathMatches("/handler"), Target),
                # ... more rules
            ])

        You can also omit explicit `Rule` constructor and use tuples of arguments::

            RuleRouter([
                (PathMatches("/handler"), Target),
            ])

        `PathMatches` is a default matcher, so the example above can be simplified::

            RuleRouter([
                ("/handler", Target),
            ])

        In the examples above, ``Target`` can be a nested `Router` instance, an instance of
        `~.httputil.HTTPServerConnectionDelegate` or an old-style callable,
        accepting a request argument.

        :arg rules: a list of `Rule` instances or tuples of `Rule`
            constructor arguments.
        N)r_   Ú	add_rules)r    r_   s     r!   r>   zRuleRouter.__init__:  s5   € ð6 ˆŒ
Øð 	"Ø�NŠN˜5Ñ!Ô!Ð!Ð!Ð!ð	"ð 	"r#   c                 ób  — |D ]«}t          |t          t          f¦  «        r`t          |¦  «        dv sJ ‚t          |d         t          ¦  «        r)t          t          |d         ¦  «        g|dd…         ¢R Ž }n	t          |Ž }| j                             |  	                    |¦  «        ¦  «         Œ¬dS )z£Appends new rules to the router.

        :arg rules: a list of Rule instances (or tuples of arguments, which are
            passed to Rule constructor).
        )é   é   é   r   é   N)
rD   ÚtupleÚlistÚlenr
   r[   ÚPathMatchesr_   ÚappendÚprocess_rule)r    r_   Úrules      r!   ra   zRuleRouter.add_rulesY  s»   € ð ð 	7ð 	7ˆDÝ˜$¥­ Ñ.Ô.ð 'Ý˜4‘y”y IÐ-Ð-Ð-Ð-Ý˜d 1œg¥Ñ7Ô7ð 'Ý¥¨D°¬GÑ 4Ô 4Ð@°t¸A¸B¸B´xÐ@Ð@Ð@�D�Då ˜;�DàŒJ×Ò˜d×/Ò/°Ñ5Ô5Ñ6Ô6Ð6Ð6ð	7ð 	7r#   rm   r[   c                 ó   — |S )z¯Override this method for additional preprocessing of each rule.

        :arg Rule rule: a rule to be processed.
        :returns: the same or modified Rule instance.
        r2   )r    rm   s     r!   rl   zRuleRouter.process_rulei  s	   € ð ˆr#   r   r   c                 ó¨   — | j         D ]I}|j                             |¦  «        }|�+|j        r
|j        |d<    | j        |j        |fi |¤Ž}|�|c S ŒJd S )NÚtarget_kwargs)r_   ÚmatcherÚmatchrp   Úget_target_delegateÚtarget)r    r   r   rm   Útarget_paramsr=   s         r!   r"   zRuleRouter.find_handlerq  sˆ   € ð ”Jð 	$ð 	$ˆDØ œL×.Ò.¨wÑ7Ô7ˆMØÐ(ØÔ%ð HØ59Ô5G�M /Ñ2à3˜4Ô3Ø”K ðð Ø,9ðð �ð Ð'Ø#�O�O�Oøàˆtr#   rt   ru   c                 óB  — t          |t          ¦  «        r |j        |fi |¤ŽS t          |t          j        ¦  «        r)|j        €J ‚|                     |j        |j        ¦  «        S t          |¦  «        r)|j        €J ‚t          t          |fi |¤Ž|j        ¦  «        S dS )a°  Returns an instance of `~.httputil.HTTPMessageDelegate` for a
        Rule's target. This method is called by `~.find_handler` and can be
        extended to provide additional target types.

        :arg target: a Rule's target.
        :arg httputil.HTTPServerRequest request: current request.
        :arg target_params: additional parameters that can be useful
            for `~.httputil.HTTPMessageDelegate` creation.
        N)rD   r   r"   r   ÚHTTPServerConnectionDelegaterB   r)   rC   Úcallabler   r   )r    rt   r   ru   s       r!   rs   zRuleRouter.get_target_delegateƒ  sÁ   € õ �f�fÑ%Ô%ð 	Ø&�6Ô& wÐ@Ð@°-Ð@Ð@Ð@å˜¥Ô EÑFÔFð 	ØÔ%Ð1Ð1Ð1Ø×'Ò'¨Ô(AÀ7ÔCUÑVÔVÐVå�fÑÔð 	ØÔ%Ð1Ð1Ð1Ý#Ý˜Ð0Ð0 -Ð0Ð0°'Ô2Dñô ð ð ˆtr#   r'   ©rm   r[   r   r[   )r*   r+   r,   r-   r   Ú	_RuleListr>   ra   rl   r   r.   r   r/   r"   rs   r2   r#   r!   r^   r^   7  sò   € € € € € Ø+Ð+ð"ð "˜h yÔ1ð "¸Tð "ð "ð "ð "ð>7˜yð 7¨Tð 7ð 7ð 7ð 7ð ð ð ð ðØÔ1ðØ=@ðà	�(Ô.Ô	/ðð ð ð ð$ØðØ$,Ô$>ðØQTðà	�(Ô.Ô	/ðð ð ð ð ð r#   r^   c                   óf   ‡ — e Zd ZdZddee         ddfˆ fd„Zdˆ fd„Zd	ed
e	dee         fd„Z
ˆ xZS )ÚReversibleRuleRoutera  A rule-based router that implements ``reverse_url`` method.

    Each rule added to this router may have a ``name`` attribute that can be
    used to reconstruct an original uri. The actual reconstruction takes place
    in a rule's matcher (see `Matcher.reverse`).
    Nr_   r   c                 óX   •— i | _         t          ¦   «                              |¦  «         d S r'   )Únamed_rulesÚsuperr>   )r    r_   Ú	__class__s     €r!   r>   zReversibleRuleRouter.__init__§  s)   ø€ ØˆÔÝ‰Œ×Ò˜ÑÔÐÐÐr#   rm   r[   c                 óÆ   •— t          ¦   «                              |¦  «        }|j        r7|j        | j        v rt	          j        d|j        ¦  «         || j        |j        <   |S )Nz4Multiple handlers named %s; replacing previous value)r   rl   r5   r~   r	   Úwarning)r    rm   r€   s     €r!   rl   z!ReversibleRuleRouter.process_rule«  se   ø€ Ý‰wŒw×#Ò# DÑ)Ô)ˆàŒ9ð 	/ØŒy˜DÔ,Ð,Ð,Ý”ØJÈDÌIñô ð ð +/ˆDÔ˜TœYÑ'àˆr#   r5   r6   c                 óÆ   — || j         v r | j         |         j        j        |Ž S | j        D ]5}t	          |j        t          ¦  «        r |j        j        |g|¢R Ž }|�|c S Œ6d S r'   )r~   rq   Úreverser_   rD   rt   r4   r8   )r    r5   r6   rm   Úreversed_urls        r!   r8   z ReversibleRuleRouter.reverse_url·  s…   € Ø�4Ô#Ð#Ð#Ø9�4Ô# DÔ)Ô1Ô9¸4Ð@Ð@à”Jð 	(ð 	(ˆDÝ˜$œ+Õ'7Ñ8Ô8ð (Ø6˜tœ{Ô6°tÐC¸dÐCÐCÐC�ØÐ+Ø'Ð'Ð'Ð'øàˆtr#   r'   ry   )r*   r+   r,   r-   r   rz   r>   rl   r9   r   r8   Ú__classcell__©r€   s   @r!   r|   r|   Ÿ  sª   ø€ € € € € ðð ð ð  ˜h yÔ1ð  ¸Tð  ð  ð  ð  ð  ð  ð
ð 
ð 
ð 
ð 
ð 
ð
 ð 
¨Cð 
°H¸S´Mð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r#   r|   c                   ó„   — e Zd ZdZ	 	 ddddedeeeef                  dee         ddf
d	„Zd
edee         fd„Z	defd„Z
dS )r[   zA routing rule.Nrq   r\   rt   rp   r5   r   c                 óŽ   — t          |t          ¦  «        rt          |¦  «        }|| _        || _        |r|ni | _        || _        dS )ad  Constructs a Rule instance.

        :arg Matcher matcher: a `Matcher` instance used for determining
            whether the rule should be considered a match for a specific
            request.
        :arg target: a Rule's target (typically a ``RequestHandler`` or
            `~.httputil.HTTPServerConnectionDelegate` subclass or even a nested `Router`,
            depending on routing implementation).
        :arg dict target_kwargs: a dict of parameters that can be useful
            at the moment of target instantiation (for example, ``status_code``
            for a ``RequestHandler`` subclass). They end up in
            ``target_params['target_kwargs']`` of `RuleRouter.get_target_delegate`
            method.
        :arg str name: the name of the rule that can be used to find it
            in `ReversibleRouter.reverse_url` implementation.
        N)rD   r9   r   rq   rt   rp   r5   )r    rq   rt   rp   r5   s        r!   r>   zRule.__init__Ç  sO   € õ. �f�cÑ"Ô"ð 	+õ # 6Ñ*Ô*ˆFàˆŒØˆŒØ.;ÐC˜]˜]ÀˆÔØˆŒ	ˆ	ˆ	r#   r6   c                 ó    —  | j         j        |Ž S r'   )rq   r„   ©r    r6   s     r!   r„   zRule.reverseè  s   € Ø#ˆtŒ|Ô# TÐ*Ð*r#   c                 óp   — d                      | j        j        | j        | j        | j        | j        ¦  «        S ©Nz${}({!r}, {}, kwargs={!r}, name={!r}))Úformatr€   r*   rq   rt   rp   r5   rP   s    r!   Ú__repr__zRule.__repr__ë  s7   € Ø5×<Ò<ØŒNÔ#ØŒLØŒKØÔØŒIñ
ô 
ð 	
r#   ©NN)r*   r+   r,   r-   r   r   r   r9   r>   r„   r�   r2   r#   r!   r[   r[   Ä  s¾   € € € € € ØÐð 37Ø"ðð àðð ðð    S¨# X¤Ô/ð	ð
 �sŒmðð 
ðð ð ð ðB+˜Sð + X¨c¤]ð +ð +ð +ð +ð
˜#ð 
ð 
ð 
ð 
ð 
ð 
r#   c                   ód   — e Zd ZdZdej        deeee	f                  fd„Z
de	dee         fd„ZdS )r\   z*Represents a matcher for request features.r   r   c                 ó   — t          ¦   «         ‚)a1  Matches current instance against the request.

        :arg httputil.HTTPServerRequest request: current HTTP request
        :returns: a dict of parameters to be passed to the target handler
            (for example, ``handler_kwargs``, ``path_args``, ``path_kwargs``
            can be passed for proper `~.web.RequestHandler` instantiation).
            An empty dict is a valid (and common) return value to indicate a match
            when the argument-passing features are not used.
            ``None`` must be returned to indicate that there is no match.r   ©r    r   s     r!   rr   zMatcher.matchø  s   € õ "Ñ#Ô#Ð#r#   r6   c                 ó   — dS )zEReconstructs full url from matcher instance and additional arguments.Nr2   r‹   s     r!   r„   zMatcher.reverse  s   € àˆtr#   N)r*   r+   r,   r-   r   r.   r   r   r9   r   rr   r„   r2   r#   r!   r\   r\   õ  sr   € € € € € Ø4Ð4ð
$˜XÔ7ð 
$¸HÀTÈ#ÈsÈ(Ä^Ô<Tð 
$ð 
$ð 
$ð 
$ð˜Sð  X¨c¤]ð ð ð ð ð ð r#   c                   óH   — e Zd ZdZdej        deeee	f                  fd„Z
dS )Ú
AnyMatcheszMatches any request.r   r   c                 ó   — i S r'   r2   r“   s     r!   rr   zAnyMatches.match  s   € Øˆ	r#   N)r*   r+   r,   r-   r   r.   r   r   r9   r   rr   r2   r#   r!   r–   r–   	  sL   € € € € € ØÐð˜XÔ7ð ¸HÀTÈ#ÈsÈ(Ä^Ô<Tð ð ð ð ð ð r#   r–   c                   óh   — e Zd ZdZdeeef         ddfd„Zdej	        de
eeef                  fd„ZdS )ÚHostMatchesz@Matches requests from hosts specified by ``host_pattern`` regex.Úhost_patternr   Nc                 ó¨   — t          |t          ¦  «        r5|                     d¦  «        s|dz  }t          j        |¦  «        | _        d S || _        d S )Nú$)rD   r
   ÚendswithÚreÚcompilerš   )r    rš   s     r!   r>   zHostMatches.__init__  sZ   € Ý�l¥OÑ4Ô4ð 	-Ø×(Ò(¨Ñ-Ô-ð $Ø Ñ#�Ý "¤
¨<Ñ 8Ô 8ˆDÔÐÐà ,ˆDÔÐÐr#   r   c                 óH   — | j                              |j        ¦  «        ri S d S r'   )rš   rr   Ú	host_namer“   s     r!   rr   zHostMatches.match  s(   € ØÔ×"Ò" 7Ô#4Ñ5Ô5ð 	ØˆIàˆtr#   )r*   r+   r,   r-   r   r9   r   r>   r   r.   r   r   r   rr   r2   r#   r!   r™   r™     sw   € € € € € ØJÐJð- U¨3°¨<Ô%8ð -¸Tð -ð -ð -ð -ð˜XÔ7ð ¸HÀTÈ#ÈsÈ(Ä^Ô<Tð ð ð ð ð ð r#   r™   c                   ó\   — e Zd ZdZdededdfd„Zdej        de	e
eef                  fd„ZdS )	ÚDefaultHostMatcheszŒMatches requests from host that is equal to application's default_host.
    Always returns no match if ``X-Real-Ip`` header is present.
    Úapplicationrš   r   Nc                 ó"   — || _         || _        d S r'   )r¤   rš   )r    r¤   rš   s      r!   r>   zDefaultHostMatches.__init__'  s   € Ø&ˆÔØ(ˆÔÐÐr#   r   c                 ód   — d|j         vr&| j                             | j        j        ¦  «        ri S d S )Nz	X-Real-Ip)r@   rš   rr   r¤   Údefault_hostr“   s     r!   rr   zDefaultHostMatches.match+  s8   € à˜gœoÐ-Ð-ØÔ ×&Ò& tÔ'7Ô'DÑEÔEð Ø�	Øˆtr#   )r*   r+   r,   r-   r   r   r>   r   r.   r   r   r9   rr   r2   r#   r!   r£   r£   "  sy   € € € € € ðð ð) Cð )°wð )À4ð )ð )ð )ð )ð˜XÔ7ð ¸HÀTÈ#ÈsÈ(Ä^Ô<Tð ð ð ð ð ð r#   r£   c                   ó¸   — e Zd ZdZdeeef         ddfd„Zdej	        de
eeef                  fd„Zdede
e         fd	„Zdee
e         e
e         f         fd
„ZdS )rj   z@Matches requests with paths specified by ``path_pattern`` regex.Úpath_patternr   Nc                 ód  — t          |t          ¦  «        r4|                     d¦  «        s|dz  }t          j        |¦  «        | _        n|| _        t          | j        j        ¦  «        d| j        j        fv sJ d| j        j	        z  ¦   «         ‚|  
                    ¦   «         \  | _        | _        d S )Nrœ   r   zDgroups in url regexes must either be all named or all positional: %r)rD   r
   r�   rž   rŸ   Úregexri   Ú
groupindexÚgroupsÚpatternÚ_find_groupsÚ_pathÚ_group_count)r    r©   s     r!   r>   zPathMatches.__init__6  s´   € Ý�l¥OÑ4Ô4ð 	&Ø×(Ò(¨Ñ-Ô-ð $Ø Ñ#�Ýœ LÑ1Ô1ˆDŒJˆJà%ˆDŒJå�4”:Ô(Ñ)Ô)¨a°´Ô1BÐ-CÐCÐCÐCðØ#œzÔ1ñ2ñ DÔCÐCð
 )-×(9Ò(9Ñ(;Ô(;Ñ%ˆŒ
�DÔ%Ð%Ð%r#   r   c                 óD  — | j                              |j        ¦  «        }|€d S | j         j        si S g }i }| j         j        r1d„ |                     ¦   «                              ¦   «         D ¦   «         }nd„ |                     ¦   «         D ¦   «         }t          ||¬¦  «        S )Nc                 óN   — i | ]"\  }}t          |¦  «        t          |¦  «        “Œ#S r2   )r9   Ú_unquote_or_none)Ú.0ÚkÚvs      r!   ú
<dictcomp>z%PathMatches.match.<locals>.<dictcomp>T  s:   € ð ð ð Ù06°°A•�A‘”Õ(¨Ñ+Ô+ðð ð r#   c                 ó,   — g | ]}t          |¦  «        ‘ŒS r2   )r´   )rµ   Úss     r!   ú
<listcomp>z%PathMatches.match.<locals>.<listcomp>X  s!   € ÐEÐEÐE°Õ)¨!Ñ,Ô,ÐEÐEÐEr#   )Ú	path_argsÚpath_kwargs)r«   rr   rH   r­   r¬   Ú	groupdictÚitemsÚdict)r    r   rr   r¼   r½   s        r!   rr   zPathMatches.matchE  s¶   € Ø”
× Ò  ¤Ñ.Ô.ˆØˆ=Ø�4ØŒzÔ ð 	ØˆIàˆ	Øˆð Œ:Ô ð 	Fðð Ø:?¿/º/Ñ:KÔ:K×:QÒ:QÑ:SÔ:Sðñ ô ˆKˆKð FÐE°e·l²l±n´nÐEÑEÔEˆIå˜i°[ÐAÑAÔAÐAr#   r6   c                 ó¬  — | j         €t          d| j        j        z   ¦  «        ‚t	          |¦  «        | j        k    s
J d¦   «         ‚t	          |¦  «        s| j         S g }|D ]^}t          |t          t          f¦  «        st          |¦  «        }| 
                    t          t          |¦  «        d¬¦  «        ¦  «         Œ_| j         t          |¦  «        z  S )NzCannot reverse url regex z&required number of arguments not foundF)Úplus)r°   Ú
ValueErrorr«   r®   ri   r±   rD   r   rV   r9   rk   r   r   rg   )r    r6   Úconverted_argsÚas       r!   r„   zPathMatches.reverse\  s×   € ØŒ:ÐÝÐ8¸4¼:Ô;MÑMÑNÔNÐNÝ�4‰yŒy˜DÔ-Ò-Ð-Ð-Ø7ñ .Ô-Ð-õ �4‰yŒyð 	Ø”:ÐØˆØð 	Cð 	CˆAÝ˜a¥,µÐ!6Ñ7Ô7ð Ý˜‘F”F�Ø×!Ò!¥*­T°!©W¬W¸5Ð"AÑ"AÔ"AÑBÔBÐBÐBØŒz�E .Ñ1Ô1Ñ1Ð1r#   c                 ó’  — | j         j        }|                     d¦  «        r
|dd…         }|                     d¦  «        r
|dd…         }| j         j        |                     d¦  «        k    rdS g }|                     d¦  «        D ] }d|v rb|                     d¦  «        }|d	k    rF	 t          ||dz   d…         ¦  «        }n# t          $ r Y  dS w xY w| 
                    d
|z   ¦  «         Œh	 t          |¦  «        }n# t          $ r Y  dS w xY w| 
                    |¦  «         Œ¡d                     |¦  «        | j         j        fS )z¶Returns a tuple (reverse string, group count) for a url.

        For example: Given the url pattern /([0-9]{4})/([a-z-]+)/, this method
        would return ('/%s/%s/', 2).
        ú^rf   Nrœ   éÿÿÿÿú(r�   ú)r   z%sÚ )r«   r®   Ú
startswithr�   r­   ÚcountÚsplitÚindexr   rÃ   rk   Újoin)r    r®   ÚpiecesÚfragmentÚ	paren_locÚunescaped_fragments         r!   r¯   zPathMatches._find_groupsk  sŒ  € ð ”*Ô$ˆØ×Ò˜cÑ"Ô"ð 	"Ø˜a˜b˜b”kˆGØ×Ò˜CÑ Ô ð 	#Ø˜c˜r˜c”lˆGàŒ:Ô §¢¨cÑ 2Ô 2Ò2Ð2ð �:àˆØŸš cÑ*Ô*ð 	2ð 	2ˆHØ�hˆˆØ$ŸNšN¨3Ñ/Ô/�	Ø ’>�>ð,Ý-8¸À)ÈaÁ-À/À/Ô9RÑ-SÔ-SÐ*Ð*øÝ%ð ,ð ,ð ,ð  ,˜|˜|˜|ð,øøøð —M’M $Ð);Ñ";Ñ<Ô<Ð<øð(Ý)4°XÑ)>Ô)>Ð&Ð&øÝ!ð (ð (ð (ð (˜<˜<˜<ð(øøøð —’Ð0Ñ1Ô1Ð1Ð1à�wŠw�v‰Œ ¤
Ô 1Ð1Ð1s$   Â)CÃ
CÃCÃ0D Ä 
DÄD)r*   r+   r,   r-   r   r9   r   r>   r   r.   r   r   r   rr   r„   r   Úintr¯   r2   r#   r!   rj   rj   3  sÐ   € € € € € ØJÐJð< U¨3°¨<Ô%8ð <¸Tð <ð <ð <ð <ðB˜XÔ7ð B¸HÀTÈ#ÈsÈ(Ä^Ô<Tð Bð Bð Bð Bð.2˜Sð 2 X¨c¤]ð 2ð 2ð 2ð 2ð&2˜e H¨S¤M°8¸C´=Ð$@ÔAð &2ð &2ð &2ð &2ð &2ð &2r#   rj   c                   ó‚   ‡ — e Zd ZdZ	 	 d
deeef         dedee	eef                  dee         ddf
ˆ fd„Z
defd	„Zˆ xZS )ÚURLSpeczÍSpecifies mappings between URLs and handlers.

    .. versionchanged: 4.5
       `URLSpec` is now a subclass of a `Rule` with `PathMatches` matcher and is preserved for
       backwards compatibility.
    Nr®   Úhandlerr   r5   r   c                 ó¬   •— t          |¦  «        }t          ¦   «                              ||||¦  «         |j        | _        | j        | _        || _        dS )aƒ  Parameters:

        * ``pattern``: Regular expression to be matched. Any capturing
          groups in the regex will be passed in to the handler's
          get/post/etc methods as arguments (by keyword if named, by
          position if unnamed. Named and unnamed capturing groups
          may not be mixed in the same rule).

        * ``handler``: `~.web.RequestHandler` subclass to be invoked.

        * ``kwargs`` (optional): A dictionary of additional arguments
          to be passed to the handler's constructor.

        * ``name`` (optional): A name for this handler.  Used by
          `~.web.Application.reverse_url`.

        N)rj   r   r>   r«   rt   Úhandler_classr   )r    r®   rØ   r   r5   rq   r€   s         €r!   r>   zURLSpec.__init__œ  sN   ø€ õ0 ˜gÑ&Ô&ˆÝ‰Œ×Ò˜ '¨6°4Ñ8Ô8Ð8à”]ˆŒ
Ø!œ[ˆÔØˆŒˆˆr#   c                 óz   — d                      | j        j        | j        j        | j        | j        | j        ¦  «        S r�   )rŽ   r€   r*   r«   r®   rÚ   r   r5   rP   s    r!   r�   zURLSpec.__repr__»  s:   € Ø5×<Ò<ØŒNÔ#ØŒJÔØÔØŒKØŒIñ
ô 
ð 	
r#   r�   )r*   r+   r,   r-   r   r9   r   r   r   r   r>   r�   r†   r‡   s   @r!   r×   r×   ”  s¹   ø€ € € € € ðð ð ,0Ø"ðð à�s˜G�|Ô$ðð ðð ˜˜c 3˜hœÔ(ð	ð
 �sŒmðð 
ðð ð ð ð ð ð>
˜#ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r#   r×   rº   r   c                 ó   — d S r'   r2   ©rº   s    r!   r´   r´   Å  ó   € à€Dr#   c                 ó   — d S r'   r2   rÝ   s    r!   r´   r´   Ê  rÞ   r#   c                 ó.   — | €| S t          | dd¬¦  «        S )z¹None-safe wrapper around url_unescape to handle unmatched optional
    groups correctly.

    Note that args are passed as bytes so the handler can decide what
    encoding to use.
    NF)ÚencodingrÂ   )r   rÝ   s    r!   r´   r´   Ï  s#   € ð 	€yØˆÝ˜ D¨uÐ5Ñ5Ô5Ð5r#   )rº   Nr   N)1r-   rž   Ú	functoolsr   Útornador   Útornado.httpserverr   Útornado.escaper   r   r   Útornado.logr	   Útornado.utilr
   r   r   r   Útypingr   r   r   r   r   r   r   r   r   r   rw   r   r4   r/   r(   rI   r9   rz   r^   r|   r[   r\   r–   r™   r£   rj   r×   rV   r´   r2   r#   r!   ú<module>ré      se  ððað aðF 
€	€	€	Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø /Ð /Ð /Ð /Ð /Ð /Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø Ð Ð Ð Ð Ð Ø RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ Rðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ðAð Að Að Að AˆXÔ2ñ Aô Að Að.$ð $ð $ð $ð $�vñ $ô $ð $ð +0ð +0ð +0ð +0ð +0�xÔ3ñ +0ô +0ð +0ð\	!ð 	!ð 	!ð 	!ð 	!˜hÔ:ñ 	!ô 	!ð 	!ð Ø	ØØˆSŒ	Øˆe�C˜�NÔ# SÐ(Ô)Øˆe�C˜�NÔ# S¨$¨s°C¨x¬.Ð8Ô9Øˆe�C˜�NÔ# S¨$¨s°C¨x¬.¸#Ð=Ô>ð		@ôô€	ðeð eð eð eð e�ñ eô eð eðP"ð "ð "ð "ð "Ð+¨Zñ "ô "ð "ðJ.
ð .
ð .
ð .
ð .
ñ .
ô .
ð .
ðbð ð ð ð ñ ô ð ð(ð ð ð ð �ñ ô ð ðð ð ð ð �'ñ ô ð ð$ð ð ð ð ˜ñ ô ð ð"^2ð ^2ð ^2ð ^2ð ^2�'ñ ^2ô ^2ð ^2ðB.
ð .
ð .
ð .
ð .
ˆdñ .
ô .
ð .
ðb 
ð	˜ð 	 ð 	ð 	ð 	ñ 
„ð	ð 
ð	ð 	ð 	ñ 
„ð	ð	6˜ œð 	6¨(°5¬/ð 	6ð 	6ð 	6ð 	6ð 	6ð 	6r#   