
    8Cfv{                        d dl mZmZmZ d dlmZ d dlmZmZ d dl	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 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dl m!Z!m"Z" d dl#m$Z$ d dl%m&Z& ee$gee$eee$f   f   f   Z' G d dee      Z(y)    )NodeVisitorReturnparse)suppress)	getsource	signature)dedent)
AnyCallableDictIterableListOptionalSetTupleUnioncast)Route)	SanicMeta)HTTP_METHODS)RESPONSE_MAPPING)	BaseMixin)FutureRouteFutureStatic)RouteHandler)HashableDictc            #          e Zd Zd)dZdedee   fdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*ded	e	e
e      d
e	eeee   f      de	e   dede	eeeef      de	e   dedede	ee      dedededede	e   dedef"dZ edh      ddddddddf	deded	e
e   d
e	eeee   f      de	e   de	eeeef      de	e   dedede	e   dededefdZ	 	 	 	 	 	 	 d+ded
e	eeee   f      de	e   de	eeeef      de	e   dedede	e   dedefdZ	 	 	 	 	 	 	 d,ded
e	eeee   f      de	e   dede	eeeef      de	e   dede	e   dedefdZ	 	 	 	 	 	 	 d,ded
e	eeee   f      de	e   dede	eeeef      de	e   dede	e   dedefdZ	 	 	 	 	 	 	 d+ded
e	eeee   f      de	e   de	eeeef      de	e   dedede	e   dedefdZ	 	 	 	 	 	 	 d+ded
e	eeee   f      de	e   de	eeeef      de	e   dedede	e   dedefd Z	 	 	 	 	 	 	 d,ded
e	eeee   f      de	e   de	eeeef      de	e   dede	e   dedefd!Z	 	 	 	 	 	 	 d-ded
e	eeee   f      de	e   de	eeeef      de	e   dedede	e   dedefd"Z	 	 	 	 	 	 	 	 d.ded
e	eeee   f      de	e   de	ee      de	eeeef      de	e   dedede	e   defd#Z	 	 	 	 	 	 	 d/ded
e	eeee   f      de	e   de	eeeef      de	e   dede	e   defd$Zdefd%Zd& Zd'e eef   de!fd(Z"y)0
RouteMixinreturnNc                 @    t               | _        t               | _        y N)set_future_routes_future_statics)selfargskwargss      S/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/sanic/mixins/routes.py__init__zRouteMixin.__init__#   s    0325%    routec                     t         r!   )NotImplementedError)r%   r+   s     r(   _apply_routezRouteMixin._apply_route'   s    !!r*   F/vurimethodshoststrict_slashesstreamversionnameignore_bodyapplysubprotocols	websocketunquotestaticversion_prefixerror_format
ctx_kwargsc                     	
 j                  d      sst         d      rdz    j                  sst        dh       j	                  |      	 
fd}|S )a  Decorate a function to be registered as a route.

        Args:
            uri (str): Path of the URL.
            methods (Optional[Iterable[str]]): List or tuple of
                methods allowed.
            host (Optional[Union[str, List[str]]]): The host, if required.
            strict_slashes (Optional[bool]): Whether to apply strict slashes
                to the route.
            stream (bool): Whether to allow the request to stream its body.
            version (Optional[Union[int, str, float]]): Route specific
                versioning.
            name (Optional[str]): User-defined route name for url_for.
            ignore_body (bool): Whether the handler should ignore request
                body (e.g. `GET` requests).
            apply (bool): Apply middleware to the route.
            subprotocols (Optional[List[str]]): List of subprotocols.
            websocket (bool): Enable WebSocket support.
            unquote (bool): Unquote special characters in the URL path.
            static (bool): Enable static route.
            version_prefix (str): URL path that should be before the version
                 value; default: `"/v"`.
            error_format (Optional[str]): Error format for the route.
            ctx_kwargs (Any): Keyword arguments that begin with a `ctx_*`
                prefix will be appended to the route context (`route.ctx`).

        Returns:
            RouteWrapper: Tuple of routes, decorated function.

        Examples:
            Using the method to define a GET endpoint:

            ```python
            @app.route("/hello")
            async def hello(request: Request):
                return text("Hello, World!")
            ```

            Adding context kwargs to the route:

            ```python
            @app.route("/greet", ctx_name="World")
            async def greet(request: Request):
                name = request.route.ctx.name
                return text(f"Hello, {name}!")
            ```
        /routerGETc                    t        | t              r| \  }} j                  |       t        	t              rt	        	g      	n	rt        	t              s	 t	        	      	t        t              rt              nt        t              rt	              rdk(  rj                  |       t        | rd n&t	        D cg c]  }|j                          c}      	
      }t        dd      }|r't        t        fdj                              _        j                  j                  |       t        t!        |       j"                  j%                               }r)t'        |      dk  r| j(                  }t        d| d      |s| j(                  }t        d	| d      s	r| _        rj-                  ||
       r|| fS | S # t
        $ r t        d	z        w xY wc c}w )Nz:Expected either string or Iterable of host strings, not %sauto_allow_route_overwriteFc                 "    | j                   k7  S r!   )r0   )xr0   s    r(   <lambda>z5RouteMixin.route.<locals>.decorator.<locals>.<lambda>   s    QUUc\ r*      z8Required parameter `request` and/or `ws` missing in the z	() route?z,Required parameter `request` missing in the )	overwrite)
isinstancetuple_generate_namestr	frozenset	TypeError
ValueErrorlistr"   _determine_error_formatr   uppergetattrfilterr#   addr   
parameterskeyslen__name__	is_streamr.   )handler_rH   r+   rK   r&   handler_namer8   r>   r2   r7   r1   r6   route_contextr%   r<   r4   r3   r9   r;   r0   r5   r=   r:   s          r(   	decoratorz#RouteMixin.route.<locals>.decoratorz   s&    '5) %
7&&tW5D$$ $(jy9$T?D ,-$\2L#.(6<6#9#;;GD!yW1M!'')1M'N!E$  &>FI&)143F3FG'# ##E*	'*55::<=DSY]&// *^96  &// *^96 
 $*!!!%9!=g~%NA ! $!#'( $ 2Ns   G# G>#G;)
startswithhasattrr3   rP   _build_route_context)r%   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   rb   ra   s   ````````````````  @r(   r+   zRouteMixin.route*   su    J ~~c"wtX/F)C!!00Ny(G11*=[	 [	 [	z r*   rC   r^   c                 >   t        |d      r_t               }t        D ]L  }t        |d      }t        ||j	                         d      }|s-|j                  |       t        |d      sKd}N || j                  }  | j                  d||||||||	|
|d
||       |S )a  A helper method to register class-based view or functions as a handler to the application url routes.

        Args:
            handler (RouteHandler): Function or class-based view used as a route handler.
            uri (str): Path of the URL.
            methods (Iterable[str]): List or tuple of methods allowed; these are overridden if using an HTTPMethodView.
            host (Optional[Union[str, List[str]]]): Hostname or hostnames to match for this route.
            strict_slashes (Optional[bool]): If set, a route's slashes will be strict. E.g. `/foo` will not match `/foo/`.
            version (Optional[Union[int, str, float]]): Version of the API for this route.
            name (Optional[str]): User-defined route name for `url_for`.
            stream (bool): Boolean specifying if the handler is a stream handler.
            version_prefix (str): URL path that should be before the version value; default: ``/v``.
            error_format (Optional[str]): Custom error format string.
            unquote (bool): Boolean specifying if the handler requires unquoting.
            ctx_kwargs (Any): Keyword arguments that begin with a `ctx_*` prefix will be appended to the route context (``route.ctx``). See below for examples.

        Returns:
            RouteHandler: The route handler.

        Examples:
            ```python
            from sanic import Sanic, text

            app = Sanic("test")

            async def handler(request):
                return text("OK")

            app.add_route(handler, "/test", methods=["GET", "POST"])
            ```

            You can use `ctx_kwargs` to add custom context to the route. This
            can often be useful when wanting to add metadata to a route that
            can be used by other parts of the application (like middleware).

            ```python
            from sanic import Sanic, text

            app = Sanic("test")

            async def handler(request):
                return text("OK")

            async def custom_middleware(request):
                if request.route.ctx.monitor:
                    do_some_monitoring()

            app.add_route(handler, "/test", methods=["GET", "POST"], ctx_monitor=True)
            app.register_middleware(custom_middleware)
        
view_classNr]   T)
r0   r1   r2   r3   r4   r5   r6   r=   r>   r;    )rd   r"   r   rV   lowerrX   r3   r+   )r%   r^   r0   r1   r2   r3   r5   r6   r4   r=   r>   r;   r?   methodrg   _handlers                   r(   	add_routezRouteMixin.add_route   s    D 7L)eG& &$Wl;
":v||~tDKK'x5!%& !!00N	



 	
))%	
 	
 	 r*   c	                 j    t        t         | j                  |ft        dh      |||||||d|	      S )a0  Decorate a function handler to create a route definition using the **GET** HTTP method.

        Args:
            uri (str): URL to be tagged to GET method of HTTP.
            host (Optional[Union[str, List[str]]]): Host IP or FQDN for
                the service to use.
            strict_slashes (Optional[bool]): Instruct Sanic to check if the
                request URLs need to terminate with a `/`.
            version (Optional[Union[int, str, float]]): API Version.
            name (Optional[str]): Unique name that can be used to identify
                the route.
            ignore_body (bool): Whether the handler should ignore request
                body. This means the body of the request, if sent, will not
                be consumed. In that instance, you will see a warning in
                the logs. Defaults to `True`, meaning do not consume the body.
            version_prefix (str): URL path that should be before the version
                value. Defaults to `"/v"`.
            error_format (Optional[str]): Custom error format string.
            **ctx_kwargs (Any): Keyword arguments that begin with a
                `ctx_* prefix` will be appended to the route
                context (`route.ctx`).

        Returns:
            RouteHandler: Object decorated with route method.
        rC   r1   r2   r3   r5   r6   r7   r=   r>   r   r   r+   rP   
r%   r0   r2   r3   r5   r6   r7   r=   r>   r?   s
             r(   getzRouteMixin.get9  sT    J DJJ!5'*-'-) 
 	
r*   c	                 j    t        t         | j                  |ft        dh      |||||||d|	      S )ao  Decorate a function handler to create a route definition using the **POST** HTTP method.

        Args:
            uri (str): URL to be tagged to POST method of HTTP.
            host (Optional[Union[str, List[str]]]): Host IP or FQDN for
                the service to use.
            strict_slashes (Optional[bool]): Instruct Sanic to check if the
                request URLs need to terminate with a `/`.
            stream (bool): Whether or not to stream the request body.
                Defaults to `False`.
            version (Optional[Union[int, str, float]]): API Version.
            name (Optional[str]): Unique name that can be used to identify
                the route.
            version_prefix (str): URL path that should be before the version
                value. Defaults to `"/v"`.
            error_format (Optional[str]): Custom error format string.
            **ctx_kwargs (Any): Keyword arguments that begin with a
                `ctx_*` prefix will be appended to the route
                context (`route.ctx`).

        Returns:
            RouteHandler: Object decorated with route method.
        POSTr1   r2   r3   r4   r5   r6   r=   r>   ro   
r%   r0   r2   r3   r4   r5   r6   r=   r>   r?   s
             r(   postzRouteMixin.postn  sT    F DJJ!6(+--) 
 	
r*   c	                 j    t        t         | j                  |ft        dh      |||||||d|	      S )am  Decorate a function handler to create a route definition using the **PUT** HTTP method.

        Args:
            uri (str): URL to be tagged to PUT method of HTTP.
            host (Optional[Union[str, List[str]]]): Host IP or FQDN for
                the service to use.
            strict_slashes (Optional[bool]): Instruct Sanic to check if the
                request URLs need to terminate with a `/`.
            stream (bool): Whether or not to stream the request body.
                Defaults to `False`.
            version (Optional[Union[int, str, float]]): API Version.
            name (Optional[str]): Unique name that can be used to identify
                the route.
            version_prefix (str): URL path that should be before the version
                value. Defaults to `"/v"`.
            error_format (Optional[str]): Custom error format string.
            **ctx_kwargs (Any): Keyword arguments that begin with a
                `ctx_*` prefix will be appended to the route
                context (`route.ctx`).

        Returns:
            RouteHandler: Object decorated with route method.
        PUTrt   ro   ru   s
             r(   putzRouteMixin.put  sT    F DJJ!5'*--) 
 	
r*   c	                 j    t        t         | j                  |ft        dh      |||||||d|	      S )a2  Decorate a function handler to create a route definition using the **HEAD** HTTP method.

        Args:
            uri (str): URL to be tagged to HEAD method of HTTP.
            host (Optional[Union[str, List[str]]]): Host IP or FQDN for
                the service to use.
            strict_slashes (Optional[bool]): Instruct Sanic to check if the
                request URLs need to terminate with a `/`.
            version (Optional[Union[int, str, float]]): API Version.
            name (Optional[str]): Unique name that can be used to identify
                the route.
            ignore_body (bool): Whether the handler should ignore request
                body. This means the body of the request, if sent, will not
                be consumed. In that instance, you will see a warning in
                the logs. Defaults to `True`, meaning do not consume the body.
            version_prefix (str): URL path that should be before the version
                value. Defaults to `"/v"`.
            error_format (Optional[str]): Custom error format string.
            **ctx_kwargs (Any): Keyword arguments that begin with a
                `ctx_*` prefix will be appended to the route
                context (`route.ctx`).

        Returns:
            RouteHandler: Object decorated with route method.
        HEADrn   ro   rp   s
             r(   headzRouteMixin.head  sT    J DJJ!6(+-'-) 
 	
r*   c	                 j    t        t         | j                  |ft        dh      |||||||d|	      S )a8  Decorate a function handler to create a route definition using the **OPTIONS** HTTP method.

        Args:
            uri (str): URL to be tagged to OPTIONS method of HTTP.
            host (Optional[Union[str, List[str]]]): Host IP or FQDN for
                the service to use.
            strict_slashes (Optional[bool]): Instruct Sanic to check if the
                request URLs need to terminate with a `/`.
            version (Optional[Union[int, str, float]]): API Version.
            name (Optional[str]): Unique name that can be used to identify
                the route.
            ignore_body (bool): Whether the handler should ignore request
                body. This means the body of the request, if sent, will not
                be consumed. In that instance, you will see a warning in
                the logs. Defaults to `True`, meaning do not consume the body.
            version_prefix (str): URL path that should be before the version
                value. Defaults to `"/v"`.
            error_format (Optional[str]): Custom error format string.
            **ctx_kwargs (Any): Keyword arguments that begin with a
                `ctx_*` prefix will be appended to the route
                context (`route.ctx`).

        Returns:
            RouteHandler: Object decorated with route method.
        OPTIONSrn   ro   rp   s
             r(   optionszRouteMixin.options	  sT    J DJJ!9+.-'-) 
 	
r*   c	                 j    t        t         | j                  |ft        dh      |||||||d|	      S )a  Decorate a function handler to create a route definition using the **PATCH** HTTP method.

        Args:
            uri (str): URL to be tagged to PATCH method of HTTP.
            host (Optional[Union[str, List[str]]]): Host IP or FQDN for
                the service to use.
            strict_slashes (Optional[bool]): Instruct Sanic to check if the
                request URLs need to terminate with a `/`.
            stream (bool): Set to `True` if full request streaming is needed,
                `False` otherwise. Defaults to `False`.
            version (Optional[Union[int, str, float]]): API Version.
            name (Optional[str]): Unique name that can be used to identify
                the route.
            version_prefix (str): URL path that should be before the version
                value. Defaults to `"/v"`.
            error_format (Optional[str]): Custom error format string.
            **ctx_kwargs (Any): Keyword arguments that begin with a
                `ctx_*` prefix will be appended to the route
                context (`route.ctx`).

        Returns:
            RouteHandler: Object decorated with route method.
        PATCHrt   ro   ru   s
             r(   patchzRouteMixin.patch>  sT    F DJJ!7),--) 
 	
r*   c	                 j    t        t         | j                  |ft        dh      |||||||d|	      S )as  Decorate a function handler to create a route definition using the **DELETE** HTTP method.

        Args:
            uri (str): URL to be tagged to the DELETE method of HTTP.
            host (Optional[Union[str, List[str]]]): Host IP or FQDN for the
                service to use.
            strict_slashes (Optional[bool]): Instruct Sanic to check if the
                request URLs need to terminate with a */*.
            version (Optional[Union[int, str, float]]): API Version.
            name (Optional[str]): Unique name that can be used to identify
                the Route.
            ignore_body (bool): Whether or not to ignore the body in the
                request. Defaults to `False`.
            version_prefix (str): URL path that should be before the version
                value. Defaults to `"/v"`.
            error_format (Optional[str]): Custom error format string.
            **ctx_kwargs (Any): Keyword arguments that begin with a `ctx_*`
                prefix will be appended to the route context (`route.ctx`).

        Returns:
            RouteHandler: Object decorated with route method.
        DELETErn   ro   rp   s
             r(   deletezRouteMixin.deleteq  sT    D DJJ!8*--'-) 
 	
r*   c
                 >     | j                   d||d|||||d||	d|
S )a  Decorate a function to be registered as a websocket route.

        Args:
            uri (str): Path of the URL.
            host (Optional[Union[str, List[str]]]): Host IP or FQDN details.
            strict_slashes (Optional[bool]): If the API endpoint needs to
                terminate with a `"/"` or not.
            subprotocols (Optional[List[str]]): Optional list of str with
                supported subprotocols.
            version (Optional[Union[int, str, float]]): WebSocket
                protocol version.
            name (Optional[str]): A unique name assigned to the URL so that
                it can be used with url_for.
            apply (bool): If set to False, it doesn't apply the route to the
                app. Default is `True`.
            version_prefix (str): URL path that should be before the version
                value. Defaults to `"/v"`.
            error_format (Optional[str]): Custom error format string.
            **ctx_kwargs (Any): Keyword arguments that begin with
                a `ctx_* prefix` will be appended to the route
                context (`route.ctx`).

        Returns:
            tuple: Tuple of routes, decorated function.
        NT)r0   r2   r1   r3   r5   r6   r8   r9   r:   r=   r>   rh   )r+   )r%   r0   r2   r3   r9   r5   r6   r8   r=   r>   r?   s              r(   r:   zRouteMixin.websocket  sH    L tzz 
)%)%
 
 	
r*   c
                 D      | j                   d||||||||	d|
|      S )az  A helper method to register a function as a websocket route.

        Args:
            handler (Callable): A callable function or instance of a class
                that can handle the websocket request.
            uri (str): URL path that will be mapped to the websocket handler.
            host (Optional[Union[str, List[str]]]): Host IP or FQDN details.
            strict_slashes (Optional[bool]): If the API endpoint needs to
                terminate with a `"/"` or not.
            subprotocols (Optional[List[str]]): Subprotocols to be used with
                websocket handshake.
            version (Optional[Union[int, str, float]]): Versioning information.
            name (Optional[str]): A unique name assigned to the URL.
            version_prefix (str): URL path before the version value.
                Defaults to `"/v"`.
            error_format (Optional[str]): Format for error handling.
            **ctx_kwargs (Any): Keyword arguments beginning with `ctx_*`
                prefix will be appended to the route context (`route.ctx`).

        Returns:
            Callable: Object passed as the handler.
        )r0   r2   r3   r9   r5   r6   r=   r>   rh   )r:   )r%   r^   r0   r2   r3   r9   r5   r6   r=   r>   r?   s              r(   add_websocket_routezRouteMixin.add_websocket_route  sK    F

~t~~ 

)%)%

 

 
 
	r*   c                    t        t        t              5  t        t	        |            }t        |      }| j                  |      }t        |      dk(  rt        t        |            cd d d        S 	 d d d        y# 1 sw Y   yxY w)N    )
r   OSErrorrQ   r	   r   r   _get_response_typesr[   nextiter)r%   r^   srctreehttp_response_typess        r(   rT   z"RouteMixin._determine_error_format  sz    gy) 	77+,C:D"&":":4"@&'1,D!456	7 	7
 -	7 	7 s   AA;;Bc                 j    t                G fddt              } |       j                  |       S )Nc                   "    e Zd Zdedef fdZy);RouteMixin._get_response_types.<locals>.HttpResponseVisitornoder   c                    t        t              5  |j                  j                  j                  g}|j                  j
                  r@||j                  j
                  D cg c]  }|j                  dk(  r|j                   c}z  }|D ]#  }|t        v sj                  t        |          % 	 d d d        y c c}w # 1 sw Y   y xY w)Ncontent_type)	r   AttributeErrorvaluefuncidkeywordsargr   rX   )r%   r   checkskchecktypess        r(   visit_ReturnzHRouteMixin._get_response_types.<locals>.HttpResponseVisitor.visit_Return  s     n- ?"jjoo001Fzz**%)ZZ%8%8# ! uu6 GG#  "( ? $44!II&6u&=>?? ?#? ?s$   AC ""B;C C ;C  C	N)r\   
__module____qualname__r   r
   r   )r   s   r(   HttpResponseVisitorr     s    ? ?C ?r*   r   )r"   r   visit)r%   r   r   r   s      @r(   r   zRouteMixin._get_response_types  s.    	?+ 	?" 	##D)r*   rawc                     i |j                         D ci c]5  }|j                  d      r"|j                  dd      |j                  |      7 }}|r-dj	                  |j                               }t        d|       t        |      S c c}w )Nctx_r   z, zUnexpected keyword arguments: )rZ   rc   replacepopjoinrQ   r   )r%   r   keyr?   unexpected_argumentss        r(   re   zRouteMixin._build_route_context*  s     #w||~
~~f% KK#SWWS\1

 

 #'99SXXZ#8 01E0FG  J''
s   :B)r   N)NNNFNNFTNFFFr/   N)NNNNTr/   N)NNFNNr/   N)NNNNFr/   N)NNNNNTr/   N)NNNNNr/   N)#r\   r   r   r)   r   r   r   r.   rO   r   r   r   boolintfloatr
   RouteWrapperr+   rP   r   rl   rq   rv   ry   r|   r   r   r   r:   r   rT   r   r   r   re   rh   r*   r(   r   r   "   se   8"+ "$u+ " ,004)-48"!,0"&*!mm (3-(m uS$s)^,-	m
 !m m %S%01m smm m m tCy)m m m m m  sm!m" #m$ 
%mf "+E7!304)-48""&*]] ] #	]
 uS$s)^,-] !] %S%01] sm] ] ] sm] ] ] 
]F 15)-48" "&*3
3
 uS$s)^,-3
 !	3

 %S%013
 sm3
 3
 3
 sm3
 3
 
3
p 15)-48""&*1
1
 uS$s)^,-1
 !	1

 1
 %S%011
 sm1
 1
 sm1
 1
 
1
l 15)-48""&*1
1
 uS$s)^,-1
 !	1

 1
 %S%011
 sm1
 1
 sm1
 1
 
1
l 15)-48" "&*3
3
 uS$s)^,-3
 !	3

 %S%013
 sm3
 3
 3
 sm3
 3
 
3
p 15)-48" "&*3
3
 uS$s)^,-3
 !	3

 %S%013
 sm3
 3
 3
 sm3
 3
 
3
p 15)-48""&*1
1
 uS$s)^,-1
 !	1
 %S%011
 sm1
 1
 sm1
 1
 
1
l 15)-48"!"&*0
0
 uS$s)^,-0
 !	0

 %S%010
 sm0
 0
 0
 sm0
 0
 
0
j 15)-,048""&*3
3
 uS$s)^,-3
 !	3

 tCy)3
 %S%013
 sm3
 3
 3
 sm3
 3
r 15)-48""&*- - uS$s)^,-	-
 !- %S%01- sm- - sm- -^	# 	0(S#X (< (r*   r   )	metaclassN))astr   r   r   
contextlibr   inspectr   r   textwrapr	   typingr
   r   r   r   r   r   r   r   r   r   sanic_routing.router   sanic.base.metar   sanic.constantsr   sanic.errorpagesr   sanic.mixins.baser   sanic.models.futuresr   r   sanic.models.handler_typesr   sanic.typesr   r   r   rh   r*   r(   <module>r      sw    * *  (    & % ( - ' : 3 $ NE,e\.A(BBCC
S(i S(r*   