o
    %h                     @   sh   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	 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)TracingGroupLocation)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d'ddZd&d	ededdfd d!Zd'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__ M/var/www/html/myenv/lib/python3.10/site-packages/playwright/_impl/_tracing.pyr      s
   
zTracing.__init__nametitle	snapshotsscreenshotssourcesc                    s\   t t }t|| _| jdd |I d H  | jdd ||dI d H }| |I d H  d S )NtracingStarttracingStartChunk)r   r   )r
   localsboolr   _channelsend_start_collecting_stacks)r   r   r   r   r    r!   params
trace_namer   r   r   start"   s   


zTracing.startc                    s6   t t }| jdd |I d H }| |I d H  d S )Nr#   )r
   r$   r&   r'   r(   )r   r   r   r)   r*   r   r   r   start_chunk3   s   
zTracing.start_chunkr*   c                    s8   | j sd| _ | jd | jj| j|I d H | _d S )NT)r   _connectionset_is_tracinglocal_utilstracing_startedr   r   )r   r*   r   r   r   r(   8   s   z Tracing._start_collecting_stackspathc                    s   |  |I d H  d S N)_do_stop_chunkr   r1   r   r   r   
stop_chunk@   s   zTracing.stop_chunkc                    s*   |  |I d H  | jdd I d H  d S )NtracingStop)r3   r&   r'   r4   r   r   r   stopC   s   zTracing.stop	file_pathc                    s@  |    |s$| jdd ddiI d H  | jr"| jj| jI d H  d S | jj }|rP| jdd ddiI d H }| jj	t
||d | jd| jdI d H  d S | jdd ddiI d H }ttt t|d}|s{| jry| 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 )
NtracingStopChunkmodediscardentrieswrite)zipFiler<   stacksIdr:   includeSourcesarchiveartifactappend)_reset_stack_counterr&   r'   r   r-   r/   trace_discarded	is_remotesend_return_as_dictzipstrr   r   r   r   r	   getsave_asdelete)r   r8   is_localresultrB   r   r   r   r3   J   sZ   



	
zTracing._do_stop_chunkc                 C   s    | j rd| _ | jd d S d S r   )r   r-   r.   r   r   r   r   rD      s   zTracing._reset_stack_counterlocationc                    s"   | j dd tt I d H  d S )NtracingGroup)r&   r'   r
   r$   )r   r   rP   r   r   r   group   s    zTracing.groupc                    s   | j dd I d H  d S )NtracingGroupEnd)r&   r'   rO   r   r   r   	group_end   s
   zTracing.group_end)NNNNN)NNr2   )r   N)__name__
__module____qualname__r   rI   r   r   r%   r+   r,   r(   r   pathlibPathr5   r7   r3   rD   r   rR   rT   __classcell__r   r   r   r   r      sL    

<r   )rX   typingr   r   r   r    playwright._impl._api_structuresr   playwright._impl._artifactr   playwright._impl._connectionr   r	   playwright._impl._helperr
   r   r   r   r   r   <module>   s   