
    YfF                        d dl mZ d dlmZmZmZ d dlmZmZm	Z	 d dl
mZ d dlmZmZ eee   ef   Z G d de      ZddZ	 	 	 	 dd	Zdd
ZddZy)    )annotations)ListSequenceTuple)DUMMY_ROOT_FRAME_IDENTIFIERSELF_TIME_FRAME_IDENTIFIERFrame)frame_info_get_identifier)
LiteralStrassert_neverc                      e Zd Zy)IdentifierDoesntMatchExceptionN)__name__
__module____qualname__     V/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/pyinstrument/frame_ops.pyr   r      s    r   r   c                   t        |       dk(  ry t        t              }|g}| D ]  \  }}d}|j                  t        |       t	        |d      D ]H  \  }}t        |      }	 ||   }|j                  |k7  r||d = t               	 |j                  ||       J ||dz   d = |d   }
|
j                  r|
j                  t        t        |              t        |j                        dk(  r|j                  d   }|j                          |S # t        t        f$ rI ||dz
     }	t        |      }|	j                  |       t        |      |k(  sJ |j                  |       Y w xY w)Nr   )identifier_or_frame_info   )start)
frame_infotimer   r   )lenr	   r   record_time_from_frame_info	enumerater
   
identifierr   
IndexError	add_childappendis_synthetic_leafr   childrenremove_from_parent)frame_records
root_frameframe_stackframe_info_stackr   stack_depthr   frame_identifierframeparentfinal_frames              r   build_frame_treer0      s   
=Q0KLJ !+|K"/  $../JDQ'01A'K 	P#K8D*#K0##'77#KL18:: 8 --$-O#	P( a)*!"o,,!!/IPTU= D :1$((+
%%'5  >? *$[1_5zB  ';';666""5)*s   "#DAE('E(c                   | j                   }|t        d      |dk(  r|j                  | j                  |        nb|dk(  r-|j	                  t        t        | j                        |        n0|dk(  r |xj                  | j                  z  c_        nt        |       |xj                  | j                  z  c_        | j                          t        | d	       y)
aM  
    Delete a frame from the tree.

    :param frame: the frame to delete
    :param replace_with: what to replace the frame with - `children` replaces
        the frame with its children, `self_time` replaces the frame with a
        self-time frame, and `nothing` deletes the frame, absorbing the time
        into the parent.
    NzCannot delete the root framer%   )after	self_timer   nothingT	recursive)r.   
ValueErroradd_childrenr%   r"   r	   r   r   absorbed_timer   r&   remove_frame_from_groups)r-   replace_withr.   s      r   delete_frame_from_treer<   E   s     \\F~788z!ENN%8		$+EEJJW 	 	
 
	"

*\"
E///	
 Ud3r   c                   | j                   |j                   u sJ |xj                  | j                  z  c_        |xj                  | j                  z  c_        | j                  j	                         D ]  \  }}	 |j                  |xx   |z  cc<    |j                  | j                         | j                          t        | d       y# t
        $ r ||j                  |<   Y sw xY w)z
    Combine two frames into one. The frames must have the same parent.

    :param frame: the frame to remove
    :param into: the frame to combine into
    Fr5   N)
r.   r9   r   
attributesitemsKeyErrorr8   r%   r&   r:   )r-   into	attributer   s       r   combine_framesrC   k   s     <<4;;&&&%---III ++113 .	4	.OOI&$.&. 	enn%	Ue4  	.)-DOOI&	.s   :CC'&C'c                   |r*| j                   r| j                   D ]  }t        |d        | j                  rU| j                  }|j                  |        t	        |j
                        dk(  r|j                  |j
                  d          yyy)z
    Removes frame from any groups that it is a member of. Should be used when
    removing a frame from a tree, so groups don't keep references to removed
    frames.
    Tr5   r   r   N)r%   r:   groupremove_framer   frames)r-   r6   childrE   s       r   r:   r:      s}     U^^^^ 	<E$Ud;	< {{5!u||! u||A/ "	 r   N)r'   zSequence[FrameRecordType]returnzFrame | None)r-   r	   r;   z.LiteralStr['children', 'self_time', 'nothing'])r-   r	   rA   r	   )r-   r	   r6   bool)
__future__r   typingr   r   r   pyinstrument.framer   r   r	   pyinstrument.frame_infor
   pyinstrument.typingr   r   strfloatFrameRecordTyper7   r   r0   r<   rC   r:   r   r   r   <module>rS      sa    " ( ( ] ] = 8
 S	5()	Z 	/d#4#4 N#4L5.0r   