
    tni3                        U d dl Z d dlZd dlmZmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZ d dlmZ erld 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lmZ d dlmZ d dlmZ d dlmZ eeef         Zeeeeef         geeef         f         Zeeef         Z ee!e"e#fZ$dZ%dZ&dZ'dZ(g Z)de*d<   d%dZ+eegZ,de*d<   de-ddfdZ. G d d          Z/d&d$Z0dS )'    N)MappingSequenceSet)datetime)AnnotatedValuecapture_internal_exceptiondisable_capture_eventformat_timestamp	safe_reprstrip_string)TYPE_CHECKING)TracebackType)Any)Callable)ContextManager)Dict)List)Optional)Type)Union)NotImplementedTypei@B    
   z<cyclic>zList[ReprProcessor]global_repr_processors	processorReprProcessorreturnc                 :    t                               |            d S N)r   append)r   s    R/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/sentry_sdk/serializer.pyadd_global_repr_processorr"   =   s    !!),,,,,    z
List[type]sequence_typestyc                 :    t                               |            d S r   )r$   r    )r%   s    r!   add_repr_sequence_typer'   D   s    "r#   c                   F    e Zd ZdZddZddZdefd	Z	 	 	 	 	 	 	 	 ddZdS )Memo_ids_objsr   Nc                 "    i | _         g | _        d S r   r*   )selfs    r!   __init__zMemo.__init__K   s    &(	"$


r#   objr   ContextManager[bool]c                 :    | j                             |           | S r   )r,   r    r.   r0   s     r!   memoizezMemo.memoizeO   s    
#r#   c                 ~    | j         d         }t          |          | j        v rdS || j        t          |          <   dS )NTF)r,   idr+   r3   s     r!   	__enter__zMemo.__enter__S   s<    jnc77di4!$DIbgg5r#   r%   Optional[Type[BaseException]]valueOptional[BaseException]tbOptional[TracebackType]c                     | j                             t          | j                                                  d            d S r   )r+   popr7   r,   )r.   r%   r:   r<   s       r!   __exit__zMemo.__exit__[   s4     		b))**D11111r#   )r   N)r0   r   r   r1   )r%   r9   r:   r;   r<   r=   r   N)	__name__
__module____qualname__	__slots__r/   r4   boolr8   r@    r#   r!   r)   r)   H   s        !I% % % %   4    2+2 )2 &	2
 
2 2 2 2 2 2r#   r)   eventDict[str, Any]kwargsr   c                   	
 t                      g g |                    dd          dk    |                    dd          |                    dd          |                    dd          dd	d
t          ffdd"fdd#fdd#fdd#fd	 	 	 	 	 	 d$	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d%
fd	d&fd	 	 	 	 	 	 	 	 	 	 	 	 	 	 d'	fd
t          j        d           	  	| fi |}s"r t          |t                    rd          |d!<   |t          j        d           S # t          j        d           w xY w)(at  
    A very smart serializer that takes a dict and emits a json-friendly dict.
    Currently used for serializing the final Event and also prematurely while fetching the stack
    local variables for each frame in a stacktrace.

    It works internally with 'databags' which are arbitrary data structures like Mapping, Sequence and Set.
    The algorithm itself is a recursive graph walk down the data structures it encounters.

    It has the following responsibilities:
    * Trimming databags and keeping them within MAX_DATABAG_BREADTH and MAX_DATABAG_DEPTH.
    * Calling safe_repr() on objects appropriately to keep them informative and readable in the final payload.
    * Annotating the payload with the _meta field whenever trimming happens.

    :param max_request_body_size: If set to "always", will never trim request bodies.
    :param max_value_length: The max length to strip strings to, defaults to sentry_sdk.consts.DEFAULT_MAX_VALUE_LENGTH
    :param is_vars: If we're serializing vars early, we want to repr() things that are JSON-serializable to make their type more apparent. For example, it's useful to see the difference between a unicode-string and a bytestring when viewing a stacktrace.
    :param custom_repr: A custom repr function that runs before safe_repr on the object to be serialized. If it returns None or throws internally, we will fallback to safe_repr.

    max_request_body_sizeNalwaysmax_value_lengthis_varsFcustom_reprr:   r   r   c                     	 d } |           }|pt          |           S # t          $ r t          |           cY S w xY wr   )r   	Exception)r:   
repr_valuerO   s     r!   _safe_repr_wrapperz%serialize.<locals>._safe_repr_wrapper   sd    	$J&([//
15!1!11 	$ 	$ 	$U#####	$s   # ??metac                     t                    t                    k    r	 t                    dz
           }d                             t          |          i           }n# t          $ r i }Y nw xY w                    |           t                    t                    k    d                             di                               |            d S )N   r6    )len
setdefaultstr
IndexErrorr    update)rT   segmentnode
meta_stackpaths      r!   	_annotatezserialize.<locals>._annotate   s    *ooT**s:23!"~00WrBB    d### *ooT** 	2!!"b))0066666s   AA% %A43A4Optional[bool]c                      	 rdS              } | dv r| S d         }|dk    rd         dk    r
d          dS |dk    rdS n# t           $ r Y d	S w xY wd
S )z
        A databag is any value that we need to trim.
        True for stuff like vars, request bodies, breadcrumbs and extra.

        :returns: `True` for "yes", `False` for :"no", `None` for "maybe soon".
        T)TNr   breadcrumbsrV   values   extraNFr[   )is_request_bodyp0_is_request_bodyrN   r`   s     r!   _is_databagzserialize.<locals>._is_databag   s    	 t..00O,..&&aB]""tAw(':':QtW}}t   	 	 	44	 us    A A "A A 
AAc                  b    	  d         dk    r d         dk    rdS n# t           $ r Y d S w xY wdS )Nr   spansrf   dataTFrh   r`   s   r!   _is_span_attributez%serialize.<locals>._is_span_attribute   sT    	Aw'!!d1g&7&7t 	 	 	44	 u    
,,c                  b    	  d         dk    r d         dk    rdS n# t           $ r Y d S w xY wdS )Nr   requestrV   ro   TFrh   rp   s   r!   rk   z#serialize.<locals>._is_request_body   sT    	Aw)##Q6(9(9t 	 	 	44	 urr   r0   
is_databagri   should_repr_stringsr]   Optional[Segment]remaining_breadthOptional[Union[int, float]]remaining_depthc           	      l   |                     |           	 	                    |           5 }|r?t          cd d d            |*                                 
t	                    dz   d = S S  | |||||          cd d d            |*                                 
t	                    dz   d = S S # 1 swxY w Y   n# t
          $ r t          t          j                               |r0Y |+                                 
t	                    dz   d = dS dS Y |+                                 
t	                    dz   d = d S d S w xY w	 |+                                 
t	                    dz   d = d S d S # |)                                 
t	                    dz   d = w xY w)NrV   )ru   ri   rv   rz   rx   z=<failed to serialize, use init(debug=True) to see error logs>)	r    r4   CYCLE_MARKERr?   rX   BaseExceptionr   sysexc_info)r0   ru   ri   rv   r]   rx   rz   result_serialize_node_implmemor_   r`   s           r!   _serialize_nodez"serialize.<locals>._serialize_node   sm    KK   	0c"" f ('      ( "


s4yy1}// #! ,+)$3(;$3&7  	      ( "


s4yy1}// #)          	 	 	&s|~~666 WV "


s4yy1}/// #" "


s4yy1}/// #"	( "


s4yy1}/// #"w"


s4yy1}/////s]   C 	B:C 1B:C :B>>C B>C F ,E2F "F EF -F3c                 Z    t          | t                    r di | j         | j        } | S )NrF   )
isinstancer   metadatar:   )r0   ra   s    r!   _flatten_annotatedz%serialize.<locals>._flatten_annotated   s9    c>** 	I%%%%%)C
r#   Optional[Union[float, int]]c                    t          | t                    rd}|}|
             }|
             }|r5|r!rt          d          }t          d          }n|t          }|t          } |           } |<|dk    r6 ddgg           |r# t           |                               S d S              }|s|r8t          r1|d}t          D ]$} || |          }	|	t          ur |	          c S %t          t          |           d	d           }
| "t          | t          t          t          f          rL|s=t          | t                    r3t          j        |           st          j        |           r |           S | S t          |
          r |
|           S t          | t                     r)|st#          t%          |                     n
 |           S t          | t&                    rt)          |                                           } i }d}|                                 D ]Z\  }}|!||k    r t-          |           
            n3t#          |          } |||||||dz
  nd |          }|||<   |dz  }[|S t          | t.                    st          | t1          t2                              rhg }t5          |           D ]T\  }}|!||k    r t-          |           
            n-|                     |||||||dz
  nd |                     U|S |r |           } n`t          | t8                    st          | t:                    r|                     dd          } t          | t"                    s |           } t-                    dk    od         dk    od         dk    }|r| S  t          |                     S )NFinfr   z!limitx)rem)
max_length)r   rz   __sentry_repr__)rX   rV   )r]   rv   ru   ri   rz   rx   zutf-8replace   rn   r6   description)r   r   floatMAX_DATABAG_DEPTHMAX_DATABAG_BREADTHr   r   NotImplementedgetattrtyperE   intmathisinfisnancallabler   rZ   r
   r   dictitemsrX   serializable_str_typestupler$   	enumerater    bytes	bytearraydecode)r0   ru   ri   rv   rz   rx   is_span_attributehintsr   r   sentry_reprrv_dictikvstr_krv_listis_span_descriptionra   r   rl   rk   rq   rS   r   rN   keep_request_bodiesrM   r   r`   s                     r!   r   z'serialize.<locals>._serialize_node_impl   s    c>** 	("'&")$J"..00O 	< <#6 <"',,$)%LL!!"*&7O$,(;%  %%&?a+?+?IHc?+,,,, )) !3!3C!8!8EUVVV   4..00 	6+ 	61G 	6!oFFE3 6 6	"3..//--f55555 0 d3ii):DAA;*S4e*<==;" 3&&,0JsOO?Cz# *)#...
k"" @	;s###X&& =	 +-$S))***'',, W%% 6	 syy{{##C(*GA		  1$0Q:K5K5KI#c((++++EA#O!(;)$3/>/J!++PT&7
 
 
 "#QNC!788 	Z~&&>
 >
 	 G!#  1$0Q:K5K5KI#c((++++E#O !,?#-(73B3NOa//TX*;
 
 
    N 	.$$S))CC#u%% 5C)C)C 5jj)44c3'' .((-- IINOtAw'1Od2h-6O 	  	J!!,s?O"P"P"PQQQr#   Tr   _meta)rT   r   r   N)r   rb   )NNNNNN)r0   r   ru   rb   ri   rb   rv   rb   r]   rw   rx   ry   rz   ry   r   r   )r0   r   r   r   )r0   r   ru   rb   ri   rb   rv   rb   rz   r   rx   r   r   r   )r)   r?   rZ   r	   setr   r   )rG   rI   serialized_eventra   r   rl   rk   rq   rS   r   r   rO   rN   r   rM   r   r_   r`   s      @@@@@@@@@@@@@@@r!   	serializer   d   s1   ( 66DD)+J &

+BD I IX U(.

3Et(L(LjjE**G28**]D2Q2QK$% $C $ $ $ $ $ $
7 
7 
7 
7 
7 
7 
7       8           (,,004'+;?9=#0#0$#0 *#0 .	#0
 %#0 9#0 7#0 
#0 #0 #0 #0 #0 #0 #0 #0 #0J     JRJR$JR *JR .	JR
 7JR 9JR 
JR JR JR JR JR JR JR JR JR JR JR JR JR JR JR JR JR^ d###)*?5;;F;; 	6: 	6*5Et*L*L 	6(21W%!%((((!%((((s   .E E)r   r   r   N)rG   rH   rI   r   r   rH   )1r~   r   collections.abcr   r   r   r   sentry_sdk.utilsr   r   r	   r
   r   r   typingr   typesr   r   r   r   r   r   r   r   r   sentry_sdk._typesr   rZ   Spanr   r   Segmentr   r   
memoryviewr   MAX_EVENT_BYTESr   r   r|   r   __annotations__r"   r$   r   r'   r)   r   rF   r#   r!   <module>r      s   




  2 2 2 2 2 2 2 2 2 2                      !           ######%%%%%%444444S>Dc4S>2E:Lc:Q4RRSMCHoG ui<      13 - 2 2 2- - - - !)# . . .t     2 2 2 2 2 2 2 28b) b) b) b) b) b)r#   