
    `i              
           d Z ddlmZmZ ddlmZ ddlmZmZm	Z	 ddl
mZ 	 ddedee	         d	ee         d
ee         fdZded
ee         fdZdS )a  Helper module for routing.

The two functions in this module are licensed under the BSD 3-Clause License
instead of the ISC License like the rest of the project. Therefore the code
is contained in a dedicated module.

Based on code from [elastic/apm-agent-python](https://github.com/elastic/apm-agent-python/blob/527f62c0c50842f94ef90fda079853372539319a/elasticapm/contrib/starlette/__init__.py).
    )ListOptional)HTTPConnection)MatchMountRoute)ScopeNscoperoutes
route_namereturnc                 ,   |D ]}|                     |           \  }}|t          j        k    rM|j        }i | |}t	          |t
                    r'|j        r t          ||j        |          }|d}n||z  }|c S |t          j        k    r	||j        }dS )z;Gets route name for given scope taking mounts into account.N)	matchesr   FULLpath
isinstancer   r   _get_route_namePARTIAL)r
   r   r   routematchchild_scopechild_route_names          }/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/prometheus_fastapi_instrumentator/routing.pyr   r   /   s    
  $ $"]]511{EJJ2U2k2K%'' 3EL 3#2;j#Y#Y #+!%JJ"22Jem##
(:J4    requestc                 j   | j         }| j        }|j        }t          ||          }|s|j        j        r|d         dk    rst          |          }|d                             d          r|d         dd         |d<   d}n|d         dz   |d<   d}t          ||          }||r|dz   n	|dd         }|S )z=Gets route name for given request taking mounts into account.r   /NTF)appr
   r   r   routerredirect_slashesdictendswith)r   r   r
   r   r   redirect_scopetrims          r   get_route_namer&   E   s     +CMEZF //J  G#*5 G%-3:N:Ne=!!#&& 	%*6]3B3%7N6"DD%*6]S%8N6"D$^V<<
!-1Fc))z#2#Jr   )N)__doc__typingr   r   starlette.requestsr   starlette.routingr   r   r   starlette.typesr	   strr   r&    r   r   <module>r.      s   >  " ! ! ! ! ! ! ! - - - - - - 1 1 1 1 1 1 1 1 1 1 ! ! ! ! ! ! DH u+3;C=c]   ,N x}      r   