o
    h                     @   s   d dl mZ d dlZd dlmZmZ d dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZ zed	ZW n eyK   ed
w d dlmZ erzd dlmZmZmZmZ d dlmZmZmZm Z  d dl!m"Z" d dl#m$Z$m%Z% G dd deZ&dd Z'dd Z(dd Z)dS )    )import_moduleN)
get_clientcapture_event)_check_minimum_versionDidNotEnableIntegration)ignore_logger)request_body_within_bounds)should_send_default_pii)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionpackage_versionzariadne.graphqlzariadne is not installed)TYPE_CHECKING)AnyDictListOptional)GraphQLErrorGraphQLResultGraphQLSchemaQueryParser)DocumentNode)EventEventProcessorc                   @   s   e Zd ZdZedd ZdS )AriadneIntegrationariadnec                  C   s$   t d} tt|  td t  d S )Nr   )r   r   r   r   _patch_graphql)version r   a/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/sentry_sdk/integrations/ariadne.py
setup_once#   s   

zAriadneIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr!   r   r   r   r    r       s    r   c                     sj   t jt j t jttfdd} tt  fdd}ttfdd}| t _|t _|t _d S )Nc                    s&   t |}t |  | ||}|S )N)_make_request_event_processor
sentry_sdkget_isolation_scopeadd_event_processor)context_valuequery_parserdataevent_processorresult)old_parse_queryr   r    _sentry_patched_parse_query4   s   z3_patch_graphql.<locals>._sentry_patched_parse_queryc           	         s    | g|R i |}t |d }t | t }| rLt " | D ]}t||jt	j
ddd\}}t||d q%W d    |S 1 sGw   Y  |S N   F)typehandled)client_options	mechanism)hint)_make_response_event_processorr(   r)   r*   r   	is_activer   r   optionsr   r%   r   )	errorsargskwargsr/   r.   clienterroreventr8   )old_handle_errorsr   r    %_sentry_patched_handle_graphql_errors=   s(   

z=_patch_graphql.<locals>._sentry_patched_handle_graphql_errorsc           	         s    | g|R i |}t |d }t | t }| rOt % | jp'g D ]}t||j	t
jddd\}}t||d q(W d    |S 1 sJw   Y  |S r2   )r9   r(   r)   r*   r   r:   r   r<   r   r;   r   r%   r   )	r/   r=   r>   query_resultr.   r?   r@   rA   r8   )old_handle_query_resultr   r    #_sentry_patched_handle_query_resultU   s(   

z;_patch_graphql.<locals>._sentry_patched_handle_query_result)ariadne_graphqlparse_queryhandle_graphql_errorshandle_query_resultr   r   )r1   rC   rF   r   )rB   rE   r0   r    r   .   s   
r   c                        fdd}|S )z*Add request data and api_target to events.c              
      s   t  ts| S t c zt dpi dd}W n ttfy.   |  Y W  d    S w t rGtt	 |rG| 
di }d|d<  |d< n| di dr]| d d= W d    | S W d    | S W d    | S 1 spw   Y  | S )NheaderszContent-Lengthr   requestgraphql
api_targetr-   )
isinstancedictr   intget	TypeError
ValueErrorr
   r	   r   
setdefault)rA   r8   content_lengthrequest_infor-   r   r    innerv   s:   




z,_make_request_event_processor.<locals>.innerr   )r-   rZ   r   rY   r    r'   r   s   r'   c                    rK   )z2Add response data to the event's response context.c                    st   t  - t r  dr(| di }d i|d< W d    | S W d    | S W d    | S 1 s3w   Y  | S )Nr<   contextsr-   response)r   r
   rS   rV   )rA   r8   r[   r\   r   r    rZ      s   



z-_make_response_event_processor.<locals>.innerr   )r\   rZ   r   r]   r    r9      s   r9   )*	importlibr   r(   r   r   sentry_sdk.integrationsr   r   r   sentry_sdk.integrations.loggingr   $sentry_sdk.integrations._wsgi_commonr	   sentry_sdk.scoper
   sentry_sdk.utilsr   r   r   r   rG   ImportErrortypingr   r   r   r   r   ariadne.typesr   r   r   r   graphql.language.astr   sentry_sdk._typesr   r   r   r   r'   r9   r   r   r   r    <module>   s.    D 