
    8Cfv$                        d dl mZ d dlmZ d dlmZ d dl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 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Z#dZ$ G d de      Z%y)    )annotations)	lru_cache)	signature)AnyDictIterableListOptionalTupleUnion)UUID)
BaseRouter)NoMethod)NotFound)
RouteGroup)Route)HTTP_METHODS)check_error_format)MethodNotAllowedr   SanicException)RouteHandleri   )__file_uri__c                  P    e Zd ZdZdZeZ	 	 	 	 	 	 	 	 ddZ ee	      	 	 	 	 	 	 	 	 dd       Z
	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ ee	      	 d	 	 	 	 	 dd       Zedd       Zedd	       Zedd
       Zedd       Zd fdZddZ xZS )Routerz`The router implementation responsible for routing a `Request` object to the appropriate handler.GETc                (   	 | j                  |||r	d|i      S d       S # t        $ r}t        d|j                   d      d d }~wt        $ rA}t        d| d| ||j                  rt        |j                              d d       d d }~ww xY w)Nhost)pathmethodextrazRequested URL z
 not foundzMethod z not allowed for URL )r   allowed_methods)resolveRoutingNotFoundr   r   r   r   r!   tuple)selfr   r   r   es        L/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/sanic/router.py_getzRouter._get   s    	<<(,vtn     37    
  	J^AFF8:>?TI 	"&!6tf=$$ !&a&7&7 8 
  	s$   ! ! 	BAB<BB)maxsizec                ,    d}| j                  |||      S )a  Retrieve a `Route` object containing the details about how to handle a response for a given request

        :param request: the incoming request object
        :type request: Request
        :return: details needed for handling the request and returning the
            correct response
        :rtype: Tuple[ Route, RouteHandler, Dict[str, Any]]

        Args:
            path (str): the path of the route
            method (str): the HTTP method of the route
            host (Optional[str]): the host of the route

        Raises:
            NotFound: if the route is not found
            MethodNotAllowed: if the method is not allowed for the route

        Returns:
            Tuple[Route, RouteHandler, Dict[str, Any]]: the route, handler, and match info
        T)r(   )r%   r   r   r   __tracebackhide__s        r'   getz
Router.get2   s    0 !yyvt,,    c           
     h   |Ot        |      j                  d      j                  d      }dj                  | | |j                  d      g      }| j	                  ||      }t        |||rt        t        t         |            nd|	||
|      }t        |t               r|g}n|xs dg}g }|D ]  }|r|j                  dd|ii       |	}t        |      dkD  r|	r|	 d|j                  d	d       nd
}t        | 4  di |}||j                  _        ||j                  _        ||j                  _        ||j                  _        ||j                  _        ||j                  _        |rt+        |j                  j(                         |j-                  |        t        |      dk(  r|d   S |S )a  Add a handler to the router

        Args:
            uri (str): The path of the route.
            methods (Iterable[str]): The types of HTTP methods that should be attached,
                example: ["GET", "POST", "OPTIONS"].
            handler (RouteHandler): The sync or async function to be executed.
            host (Optional[str], optional): Host that the route should be on. Defaults to None.
            strict_slashes (bool, optional): Whether to apply strict slashes. Defaults to False.
            stream (bool, optional): Whether to stream the response. Defaults to False.
            ignore_body (bool, optional): Whether the incoming request body should be read.
                Defaults to False.
            version (Union[str, float, int], optional): A version modifier for the uri. Defaults to None.
            name (Optional[str], optional): An identifying name of the route. Defaults to None.

        Returns:
            Route: The route object.
        N/v)r   handlermethodsnamestrictunquote	overwriterequirementsr      _.__unnamed__r    )strstriplstripjoin
_normalizedict	frozensetmap
isinstanceupdatelenreplacesuperaddr    identignore_bodystreamhostsstaticerror_formatr   append)r%   urir2   r1   r   strict_slashesrM   rL   versionr3   r5   rO   version_prefixr6   rP   paramsrN   routesrK   route	__class__s                       r'   rJ   z
Router.addM   s   H 'l((-44S9G((~.wi8#**S/JKCooc7+4;Ic#w/0!
 dC FENTFE 	!D~~>?E5zA~  fAdll3456&  GK)&)E %EKK&1EKK#!'EKK %EKK!'EKK'3EKK$"5;;#;#;<MM% /	!2 v;!!9r-   c                    |sy| j                   j                  |      }|s@| j                  j                  j	                  |      }| j                   j                  |      }|sy|S )a+  Find a route in the router based on the specified view name.

        Args:
            view_name (str): the name of the view to search for
            name (Optional[str], optional): the name of the route. Defaults to `None`.

        Returns:
            Optional[Route]: the route object
        N)
name_indexr,   ctxapp_generate_name)r%   	view_namer3   rX   	full_names        r'   find_route_by_view_namezRouter.find_route_by_view_name   sX     ##I.33I>IOO''	2Er-   c                V    | j                   D ci c]  }|j                  | c}S c c}w )z|Return all routes in the router.

        Returns:
            Dict[Tuple[str, ...], Route]: a dictionary of routes
        )rW   parts)r%   rX   s     r'   
routes_allzRouter.routes_all   s%     15<uU"<<<s   &c                    | j                   S )a0  Return all static routes in the router.

        _In this context "static" routes do not refer to the `app.static()`
        method. Instead, they refer to routes that do not contain
        any path parameters._

        Returns:
            Dict[Tuple[str, ...], Route]: a dictionary of routes
        )static_routesr%   s    r'   routes_staticzRouter.routes_static   s     !!!r-   c                    | j                   S )zReturn all dynamic routes in the router.

        _Dynamic routes are routes that contain path parameters._

        Returns:
            Dict[Tuple[str, ...], Route]: a dictionary of routes
        )dynamic_routesrg   s    r'   routes_dynamiczRouter.routes_dynamic   s     """r-   c                    | j                   S )a  Return all regex routes in the router.

        _Regex routes are routes that contain path parameters with regex
        expressions, or otherwise need regex to resolve._

        Returns:
            Dict[Tuple[str, ...], Route]: a dictionary of routes
        )regex_routesrg   s    r'   routes_regexzRouter.routes_regex   s        r-   c                    t        |   |i | | j                  j                         D ]-  }t	        d |j
                  D              s t        d| d       y)zFinalize the router.

        Raises:
            SanicException: if a route contains a parameter name that starts with "__" and is not in ALLOWED_LABELS
        c              3  R   K   | ]  }|j                  d       xr |t        v ! yw)__N)
startswithALLOWED_LABELS).0labels     r'   	<genexpr>z"Router.finalize.<locals>.<genexpr>   s0         &F5+FFs   %'zInvalid route: z". Parameter names cannot use '__'.N)rI   finalizerj   valuesanylabelsr   )r%   argskwargsrX   rY   s       r'   rw   zRouter.finalize   sj     	$)&)((//1 	E "\\  %%eW,NO 	r-   c                   d|vr|S t        |      }|j                  j                         D ci c]S  }|j                  t        t
        t        t        fv r/|j                  |j                  j                  j                         U }}g }|j                  d      D ]I  }|j                  d      r%d|vr!|dd }|j                  |      }	|	r	d| d|	 d}|j                  |       K dj                  |      S c c}w )N<r/   :r8   >)r   
parametersrx   
annotationr=   intfloatr   r3   __name__lowersplitrr   r,   rQ   r@   )
r%   rR   r1   sigparammappingreconstructionpartr3   r   s
             r'   rA   zRouter._normalize   s    c>J  ..0
CeT#:: JJ((117799
 
 IIcN 	(Ds#4Abz$[[.
tfAj\3D!!$'	( xx''
s   AC8)r   r=   r   r=   r   Optional[str]returnz*Tuple[Route, RouteHandler, Dict[str, Any]])NFFFNNFFz/vFN)rR   r=   r2   zIterable[str]r1   r   r   z#Optional[Union[str, Iterable[str]]]rS   boolrM   r   rL   r   rT   z Optional[Union[str, float, int]]r3   r   r5   r   rO   r   rU   r=   r6   r   rP   r   r   zUnion[Route, List[Route]])N)r_   r=   r3   r   r   zOptional[Route])r   zDict[Tuple[str, ...], Route])r   z!Dict[Tuple[str, ...], RouteGroup])r   None)rR   r=   r1   r   r   r=   )r   
__module____qualname____doc__DEFAULT_METHODr   ALLOWED_METHODSr(   r   ROUTER_CACHE_SIZEr,   rJ   ra   propertyrd   rh   rk   rn   rw   rA   __classcell__)rY   s   @r'   r   r      s   jN"O!$,9	3( ()--!$-,9-	3- *-> 59$!48""&*VV V 	V
 2V V V V 2V V V V V V $V  
#!Vp ()48$1	 *2 = = 
" 
" # # 	! 	!"(r-   r   N)&
__future__r   	functoolsr   inspectr   typingr   r   r   r	   r
   r   r   uuidr   sanic_routingr   sanic_routing.exceptionsr   r   r#   sanic_routing.groupr   sanic_routing.router   sanic.constantsr   sanic.errorpagesr   sanic.exceptionsr   r   sanic.models.handler_typesr   r   rs   r   r<   r-   r'   <module>r      sS    "   D D D  $ - @ * % ( / G G 3  "x(Z x(r-   