
    8Cf                    l    d dl mZ d dlmZmZmZmZmZ d dlm	Z	m
Z
 d dlmZ ddlmZmZ  G d d      Zy	)
    )annotations)	FrozenSetListOptionalSequenceTuple)RequirementsRoute)	Immutable   )InvalidUsageRouteExistsc                     e Zd ZU ded<   dZded<   ded<   ded	<   d
ed<   d
ed<   ded<   ded<   ded<   d dZd Zd!dZd Zd Z	d Z
d Zd dZd Z	 d"	 	 	 	 	 	 	 d#dZed$d       Zed%d       Zed&d       Zed'd       Zed(d       Zy))
RouteGroupr   methods_index)labelsparamspartspathpatternraw_pathregexroutersegmentsstrictunquoteuristrr   zOptional[str]r   boolr   zTuple[str, ...]r   r   r   r   r   c                    t        t        d D                    dkD  rt        d      t        fdD              rt        d      t	              }|j                          | _        d| _        y )Nc              3  4   K   | ]  }|j                     y wN)r   ).0routes     S/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/sanic_routing/group.py	<genexpr>z&RouteGroup.__init__.<locals>.<genexpr><   s     355;;3s   r   z(Cannot group routes with differing pathsc              3  V   K   | ]   }d    j                   |j                   k7   " yw)N)r   )r#   r$   routess     r%   r&   z&RouteGroup.__init__.<locals>.<genexpr>?   s$     EUvbz  ELL0Es   &)z-Cannot group routes with differing strictnessr   )lensetr   anylistpop_routespattern_idx)selfr)   
route_lists    ` r%   __init__zRouteGroup.__init__;   sc    s3F334q8IJJEfEENOO&\
    c                    d| j                   xs | j                  j                   dt        | j                         }d| j
                  j                   d| dS )Nzpath=z len=<z: >)r   r   	delimiterr*   r)   	__class____name__)r1   displays     r%   __str__zRouteGroup.__str__H   sW    DII6!6!67uS=M<NO 	 4>>**+2gYa88r4   c                    t        |       S r"   )r   r1   s    r%   __repr__zRouteGroup.__repr__N   s    4yr4   c                ,    t        | j                        S r"   )iterr)   r>   s    r%   __iter__zRouteGroup.__iter__Q   s    DKK  r4   c                     | j                   |   S r"   )r)   )r1   keys     r%   __getitem__zRouteGroup.__getitem__T   s    {{3r4   c                x    || j                   v rt        | d   |      }t        | ||       |S t        d| d      )Nr   zRouteGroup has no 'z' attribute)passthru_propertiesgetattrsetattrAttributeError)r1   rD   values      r%   __getattr__zRouteGroup.__getattr__W   sH     $***DGS)ED#u%L23%{CDDr4   c           	         t        | j                  D ci c]  }|j                  D ]  }||  c}}      | _        y c c}}w r"   )r   r/   methodsr   r1   r$   methods      r%   finalizezRouteGroup.finalizeb   sM    & "\\#mm  
s   >
c                P    t        t        | j                  d             | _        y)z;
        Sorts the routes in the group by priority
        c                    | j                   S r"   priorityr$   s    r%   <lambda>z.RouteGroup.prioritize_routes.<locals>.<lambda>p   s
    5>> r4   )rD   N)tuplesortedr/   r>   s    r%   prioritize_routeszRouteGroup.prioritize_routesk   s     4<<%AB
r4   c                8    t        | j                        | _        y r"   )dictr   r>   s    r%   resetzRouteGroup.resets   s    !$"4"45r4   c           
        t        | j                        }|j                  D ]  }| D ]  }||k(  s0|j                  r|j                  r|j                  sF|j                  r:|s8|r=t	        d| j
                   ddj                  | j                         d      |j                  |       |j                  d d         t        |      | _        y)	a  
        The purpose of merge is to group routes with the same path, but
        declarared individually. In other words to group these:

        .. code-block:: python

            @app.get("/path/to")
            def handler1(...):
                ...

            @app.post("/path/to")
            def handler2(...):
                ...

        The other main purpose is to look for conflicts and
        raise ``RouteExists``

        A duplicate route is when:
        1. They have the same path and any overlapping methods; AND
        2. If they have requirements, they are the same

        :param group: Incoming route group
        :type group: RouteGroup
        :param overwrite: whether to allow an otherwise duplicate route group
            to overwrite the existing, if ``True`` will not raise exception
            on duplicates, defaults to False
        :type overwrite: bool, optional
        :param append: whether to allow an otherwise duplicate route group to
            append its routes to the existing route group, defaults to False
        :type append: bool, optional
        :raises RouteExists: Raised when there is a duplicate
        zRoute already registered: z [,]c                    | j                   S r"   rT   rV   s    r%   rW   z"RouteGroup.merge.<locals>.<lambda>   s
    %.. r4   T)rD   reverseN)r-   r/   r)   requirementsr   r   joinrN   appendsortrX   )r1   group	overwritere   r/   other_routecurrent_routes          r%   mergezRouteGroup.mergev   s    F t||$ << 	K!% ![0%22 + 8 8 *66'44 $)8 H  # 67q: 
 NN;/LL8$ ! '	. W~r4   c                2    t        | d   j                        S )z9
        The number of parts in :py:attr:`parts`
        r   )r*   r   r>   s    r%   depthzRouteGroup.depth   s    
 47==!!r4   c                V    t        d | j                  j                         D              S )Nc              3  Z   K   | ]#  }|j                   d k(  xs d|j                   v  % yw)r   /N)label)r#   params     r%   r&   z*RouteGroup.dynamic_path.<locals>.<genexpr>   s2      
 [[F";u{{(:;
s   )+)r,   r   valuesr>   s    r%   dynamic_pathzRouteGroup.dynamic_path   s)     
++-
 
 	
r4   c                f    t        | D cg c]  }|j                  D ]  }|  c}}      S c c}}w ) )	frozensetrN   rO   s      r%   rN   zRouteGroup.methods   s2     !%BEMMB&VBVB
 	
Bs   -
c                    | j                   S r"   )r/   r>   s    r%   r)   zRouteGroup.routes   s    ||r4   c                Z    | D cg c]  }|j                   s|j                    c}S c c}w r"   )rc   )r1   r$   s     r%   rc   zRouteGroup.requirements   s$    04Ku8J8J""KKKs   ((N)returnNone)rz   r   )FF)rg   r   rh   r   re   r   rz   r{   )rz   int)rz   r   )rz   zFrozenSet[str])rz   zSequence[Route])rz   zList[Requirements])r:   
__module____qualname____annotations__rG   r3   r<   r?   rB   rE   rL   rQ   rZ   r]   rk   propertyrm   rt   rN   r)   rc    r4   r%   r   r      s   $ I  K 
  L M 
H9! 	E

6 JO;&;&,0;&BF;&	;&z " " 
 
 
 
   L Lr4   r   N)
__future__r   typingr   r   r   r   r   sanic_routing.router	   r
   sanic_routing.utilsr   
exceptionsr   r   r   r   r4   r%   <module>r      s%    " = = 3 ) 1CL CLr4   