o
    Qh                     @   s\   d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ G dd de	ZdS )    N)DictOptionalUnioncast)Artifact)ChannelOwnerfrom_nullable_channel)locals_to_paramsc                       s   e Zd Zdededededdf
 fddZ					dd	ed
ededededdfddZdd
ed	eddfddZ	deddfddZ
ddeejef ddfddZddeejef ddfddZddeejef ddfddZ  ZS ) TracingparenttypeguidinitializerreturnNc                    s.   t  |||| d| _d | _d| _d | _d S )NF)super__init___include_sources
_stacks_id_is_tracing_traces_dir)selfr   r   r   r   	__class__ V/home/air/yokohama/back/venv/lib/python3.10/site-packages/playwright/_impl/_tracing.pyr      s
   
zTracing.__init__nametitle	snapshotsscreenshotssourcesc                    sV   t t t|_dtf fdd}j|dI d H }|I d H  d S )Nr   c                      s0   j dI d H  j d dI d H S )NtracingStarttracingStartChunk)r   r   )_channelsendr   r   paramsr   r   r   r   _inner_start,   s
   

z#Tracing.start.<locals>._inner_startT)r	   localsboolr   str_connectionwrap_api_call_start_collecting_stacks)r   r   r   r   r   r   r&   
trace_namer   r$   r   start!   s   

zTracing.startc                    s4   t t }| jd|I d H }| |I d H  d S )Nr!   )r	   r'   r"   r#   r,   )r   r   r   r%   r-   r   r   r   start_chunk5   s   
zTracing.start_chunkr-   c                    s8   | j sd| _ | jd | jj| j|I d H | _d S )NT)r   r*   set_in_tracinglocal_utilstracing_startedr   r   )r   r-   r   r   r   r,   :   s   z Tracing._start_collecting_stackspathc                    s$   j  fdddI d H  d S )Nc                      s
     S N)_do_stop_chunkr   r3   r   r   r   <lambda>C   s   
 z$Tracing.stop_chunk.<locals>.<lambda>Tr*   r+   )r   r3   r   r6   r   
stop_chunkB   s   "zTracing.stop_chunkc                    s*   d fdd}j |dI d H  d S )Nr   c                      s(     I d H  jdI d H  d S )NtracingStop)r5   r"   r#   r   r6   r   r   _innerF   s   zTracing.stop.<locals>._innerT)r   Nr8   )r   r3   r;   r   r6   r   stopE   s   zTracing.stop	file_pathc                    sJ  | j rd| _ | jd |s+| jdddiI d H  | jr)| jj| jI d H  d S | jj }|rV| j	dddiI d H }| jj
t||d | jd| jdI d H  d S | j	dddiI d H }ttt t|d	}|s| jr~| jj| jI d H  d S ||I d H  | I d H  | jj
t|g | jd
| jdI d H  d S )NFtracingStopChunkmodediscardentrieswrite)zipFilerA   stacksIdr?   includeSourcesarchiveartifactappend)r   r*   r0   r"   r#   r   r1   trace_discarded	is_remotesend_return_as_dictzipr)   r   r   r   r   r   getsave_asdelete)r   r=   is_localresultrG   r   r   r   r5   L   s\   


	
zTracing._do_stop_chunk)NNNNN)NNr4   )__name__
__module____qualname__r   r)   r   r   r(   r.   r/   r,   r   pathlibPathr9   r<   r5   __classcell__r   r   r   r   r
      sF    
&r
   )rU   typingr   r   r   r   playwright._impl._artifactr   playwright._impl._connectionr   r   playwright._impl._helperr	   r
   r   r   r   r   <module>   s   