o
    hs                     @   s   d dl Z d dlmZ d dlmZ d dlmZ er<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 Zdd Zdd Zdd Zdd ZdS )    N)should_send_default_pii)_filter_headers)TYPE_CHECKING)Any)Dict)Optional)Union)Literal)AnnotatedValuec                 C   sT   i }| d D ]!\}}| d}| d}||v r#|| d | ||< q|||< q|S )z^
    Extract headers from the ASGI scope, in the format that the Sentry protocol expects.
    headerslatin-1z, )decode)
asgi_scoper   raw_key	raw_valuekeyvalue r   f/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/sentry_sdk/integrations/_asgi_common.py_get_headers   s   


r   c                 C   s   |  d|}|  dd}|  dd|  dd }|r!d|||f S |durF|\}}dd	dd	d
 |}||kr?d||||f S d|||f S |S )zR
    Extract URL from the ASGI scope, without also including the querystring.
    schemeserverN	root_path pathz	%s://%s%sP   i  )httphttpswswssz%s://%s:%s%s)get)r   default_schemehostr   r   r   portdefault_portr   r   r   _get_url#   s   r%   c                 C   s$   |  d}|s	dS tj|dS )zb
    Extract querystring from the ASGI scope, in the format that the Sentry protocol expects.
    query_stringNr   )r    urllibparseunquoter   )r   qsr   r   r   
_get_query9   s   
r+   c              	   C   sd   t | }z|d dd  W S  ttfy   Y nw z|d W S  ty*   Y nw | dd S )zh
    Extract IP Address from the ASGI scope based on request headers with fallback to scope client.
    zx-forwarded-for,r   z	x-real-ipclient)r   splitstripKeyError
IndexErrorr    )r   r   r   r   r   _get_ipD   s   
r2   c                 C   s   i }| d }|dv r2|  d|d< tt|  |d< }t| |d< t| |dkr)dnd| d|d	< |  d
}|rDt rDdt| i|d< |S )zG
    Returns data related to the HTTP request from the ASGI scope.
    type)r   	websocketmethodr   r&   r   r   r"   urlr-   REMOTE_ADDRenv)r    r   r   r+   r%   r   r2   )r   request_datatyr   r-   r   r   r   _get_request_dataW   s   

r;   )r'   sentry_sdk.scoper   $sentry_sdk.integrations._wsgi_commonr   typingr   r   r   r   r   typing_extensionsr	   sentry_sdk.utilsr
   r   r%   r+   r2   r;   r   r   r   r   <module>   s     