o
    ^۷i                  
   @   s   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dZded
ee fd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                 C   s   |D ]D}| | \}}|tjkr:|j}i | |}t|tr6|jr6t||j|}|du r2d}|  S ||7 }|  S |tjkrF|du rF|j}q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_name r   _/home/ubuntu/vllm_env/lib/python3.10/site-packages/prometheus_fastapi_instrumentator/routing.pyr   /   s    
r   requestc                 C   s   | j }| j}|j}t||}|sQ|jjrQ|d dkrQt|}|d dr2|d dd |d< d}n
|d d |d< d}t||}|durQ|rK|d 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trimr   r   r   get_route_nameE   s   

r#   )N)__doc__typingr   r   starlette.requestsr   starlette.routingr   r   r   starlette.typesr   strr   r#   r   r   r   r   <module>   s    	
