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
   