
    \jY                         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dddddefdZddZdddefdZddZddZy)    N)should_send_default_pii)_filter_headers)TYPE_CHECKING)Any)Dict)Optional)Union)Literal)AnnotatedValue
asgi_scoper   returnc                     i }| d   D ]?  \  }}|j                  d      }|j                  d      }||v r||   dz   |z   ||<   ;|||<   A |S )z^
    Extract headers from the ASGI scope, in the format that the Sentry protocol expects.
    headerslatin-1z, )decode)r   r   raw_key	raw_valuekeyvalues         N/root/env/lib/python3.12/site-packages/sentry_sdk/integrations/_asgi_common.py_get_headersr      sn     !#G(3 !nnY'  +'>"3<$.6GCL GCL! N    Dict[str, Any]default_schemezLiteral['ws', 'http']hostz$Optional[Union[AnnotatedValue, str]]c                    | j                  d|      }| j                  dd      }| j                  dd      | j                  dd      z   }|r	|d||S |5|\  }}dd	dd	d
j                  |      }||k7  r|d|d||S |d||S |S )zR
    Extract URL from the ASGI scope, without also including the querystring.
    schemeserverN	root_path pathz://P   i  )httphttpswswss:)get)r   r   r   r   r   r!   portdefault_ports           r   _get_urlr+   "   s     ^^Hn5F^^Hd+F>>+r*Z^^FB-GGD$dD11
d "S3GKKFS<%+T4>>$dD11Kr   c                     | j                  d      }|syt        j                  j                  |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   qss     r   
_get_queryr2   ;   s6     
	'B<<		) 455r   c                     t        |       }	 |d   j                  d      d   j                         S # t        t        f$ r Y nw xY w	 |d   S # t        $ r Y nw xY w| j                  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   s     r   _get_ipr:   E   s     :&G()//4Q7==??j! {##  >>(#A&&s!   $2 AAA 	AAc                 8   i }| d   }|dv ra| j                  d      |d<   t        t        |             x|d<   }t        |       |d<   t	        | |dk(  rdnd|j                  d            |d	<   | j                  d
      }|rt               rdt        |       i|d<   |S )zG
    Returns data related to the HTTP request from the ASGI scope.
    typer#   	websocketmethodr   r-   r#   r%   r   urlr5   REMOTE_ADDRenv)r(   r   r   r2   r+   r   r:   )r   request_datatyr   r5   s        r   _get_request_datarE   W   s     &(L	F	B	""!+!9X,;L<T,UUY''1*'=^$&",D'++f:M
U ^^H%F)+,gj.ABUr   c                    i }| d   }|dv r| j                  d      r| d   j                         |d<   t        t        |       d      }|j	                         D ]  \  }}||d|j                          <    t        |       }|r||d<   t        | |d	k(  rd	nd
|j                  d            |d<   | j                  d      }|rt               rt        |       }||d<   ||d<   |S )zL
    Return attributes related to the HTTP request from the ASGI scope.
    r<   r=   r?   zhttp.request.methodF)use_annotated_valuezhttp.request.header.z
http.queryr#   r%   r   zurl.fullr5   zclient.addresszuser.ip_address)
r(   upperr   r   itemslowerr2   r+   r   r:   )	r   
attributesrD   r   headerr   queryr5   ips	            r   _get_request_attributesrO   n   s    $&J	F	B	"">>(#0:80D0J0J0LJ,-!,z":PUV$]]_ 	HMFEBGJ-flln-=>?	H :&',J|$!)",D'++f:M"

: ^^H%F)+Z ')
#$(*
$%r   )r   r   r   zDict[str, str])r   r   r   r   )r   r   r   r   )r   r   r   zdict[str, Any])r.   sentry_sdk.scoper   $sentry_sdk.integrations._wsgi_commonr   typingr   r   r   r   r	   typing_extensionsr
   sentry_sdk.utilsr   r   strr+   r2   r:   rE   rO    r   r   <module>rW      sv     4 @  )/  + 1 		26' '# '$.r   