a
    ҏi7                     @   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
mZ d dlmZ G dd de	ZdS )    N)DictOptionalUnioncast)Artifact)ChannelOwnerfilter_nonefrom_nullable_channel)locals_to_paramsc                       s   e Zd Zeeeedd fddZdeeeeeddddZdeeddd	d
Z	eddddZ
deejef ddddZdeejef ddddZdeejef ddddZ  ZS )TracingN)parenttypeguidinitializerreturnc                    s.   t  |||| d| _d | _d| _d | _d S )NF)super__init___include_sources
_stacks_id_is_tracing_traces_dir)selfr   r   r   r   	__class__ I/home/Claro/venv/lib/python3.9/site-packages/playwright/_impl/_tracing.pyr      s
    zTracing.__init__)nametitle	snapshotsscreenshotssourcesr   c                    sT   t t t|_td fdd}j|dI d H }|I d H  d S )Nr   c                      s2   j dI d H  j dt dI d H S )NZtracingStarttracingStartChunk)r   r   )_channelsendr   r   r   paramsr   r   r   r   _inner_start0   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.start)r   r   r   c                    s2   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_chunk9   s    
zTracing.start_chunk)r.   r   c                    s6   | j sd| _ | jd | jj| j|I d H | _d S )NT)r   r+   set_in_tracinglocal_utilsZtracing_startedr   r   )r   r.   r   r   r   r-   >   s    z Tracing._start_collecting_stacks)pathr   c                    s"   j  fdddI d H  d S )Nc                      s
     S )N)_do_stop_chunkr   r3   r   r   r   <lambda>G       z$Tracing.stop_chunk.<locals>.<lambda>Tr+   r,   )r   r3   r   r5   r   
stop_chunkF   s    zTracing.stop_chunkc                    s,   d d fdd}j |dI d H  d S )Nr!   c                      s&     I d H  jdI d H  d S )NZtracingStop)r4   r#   r$   r   r5   r   r   _innerJ   s    zTracing.stop.<locals>._innerTr8   )r   r3   r:   r   r5   r   stopI   s    zTracing.stop)	file_pathr   c                    sH  | j rd| _ | jd |sT| jdddiI d H  | jrP| jj| jI d H  d S | jj }|r| 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 )NFZtracingStopChunkmodediscardentrieswrite)ZzipFiler?   ZstacksIdr=   ZincludeSourcesarchiveartifactappend)r   r+   r1   r#   r$   r   r2   Ztrace_discardedZ	is_remoteZsend_return_as_dictzipr*   r   r   r   r   r	   getZsave_asdelete)r   r<   is_localresultrB   r   r   r   r4   P   sZ    


	
zTracing._do_stop_chunk)NNNNN)NN)N)N)N)__name__
__module____qualname__r   r*   r   r   r)   r/   r0   r-   r   pathlibPathr9   r;   r4   __classcell__r   r   r   r   r      s*        r   )rL   typingr   r   r   r   Zplaywright._impl._artifactr   Zplaywright._impl._connectionr   r   r	   Zplaywright._impl._helperr
   r   r   r   r   r   <module>   s
   