o
    BD©is  ã                   @   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   ú]/var/www/Datamplify/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%séP   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     