a
    xd<)                  
   @  s8  d dl mZ ddlmZmZ d dlmZ d dlZd dlZddl	m
Z
 G dd deZeG d	d
 d
ZG dd dejZG dd dejZddddZddddZdddddZd0dddddZd1ddd dd!d"d#dd$d%d&Zed'eG d(d) d)Zed*eG d+d, d,Zed-eG d.d/ d/ZdS )2    )annotations   )event_classT_JSON_DICT)	dataclassN)ioc                      sB   e Zd ZdZddddZedd dddZ fd	d
Z  ZS )MemoryDumpConfigz[
    Configuration for memory dump. Used only when "memory-infra" category is enabled.
    dictreturnc                 C  s   | S N selfr   r   f/var/www/html/Ranjet/env/lib/python3.9/site-packages/selenium/webdriver/common/devtools/v85/tracing.pyto_json   s    zMemoryDumpConfig.to_jsonjsonr   c                 C  s   | |S r   r   clsr   r   r   r   	from_json   s    zMemoryDumpConfig.from_jsonc                   s   d t  S )NzMemoryDumpConfig({}))formatsuper__repr__r   	__class__r   r   r      s    zMemoryDumpConfig.__repr__)	__name__
__module____qualname____doc__r   classmethodr   r   __classcell__r   r   r   r   r      s
   r   c                   @  s   e Zd ZU dZded< dZded< dZded< dZded< dZded	< dZ	ded
< dZ
ded< dZded< dd Zedd ZdS )TraceConfigNtyping.Optional[str]record_modetyping.Optional[bool]enable_samplingenable_systraceenable_argument_filterz!typing.Optional[typing.List[str]]included_categoriesexcluded_categoriessynthetic_delaysz!typing.Optional[MemoryDumpConfig]memory_dump_configc                 C  s   t  }| jd ur| j|d< | jd ur.| j|d< | jd urB| j|d< | jd urV| j|d< | jd urtdd | jD |d< | jd urdd | jD |d	< | jd urd
d | jD |d< | jd ur| j	 |d< |S )N
recordModeenableSamplingenableSystraceenableArgumentFilterc                 S  s   g | ]}|qS r   r   .0ir   r   r   
<listcomp>C       z'TraceConfig.to_json.<locals>.<listcomp>includedCategoriesc                 S  s   g | ]}|qS r   r   r1   r   r   r   r4   E   r5   excludedCategoriesc                 S  s   g | ]}|qS r   r   r1   r   r   r   r4   G   r5   syntheticDelaysmemoryDumpConfig)
r	   r$   r&   r'   r(   r)   r*   r+   r,   r   )r   r   r   r   r   r   8   s$    











zTraceConfig.to_jsonc                 C  s   | d|v rt |d nd d|v r,t|d nd d|v rBt|d nd d|v rXt|d nd d|v rtdd |d D nd d|v rd	d |d D nd d
|v rdd |d
 D nd d|v rt|d nd dS )Nr-   r.   r/   r0   r6   c                 S  s   g | ]}t |qS r   strr1   r   r   r   r4   S   r5   z)TraceConfig.from_json.<locals>.<listcomp>r7   c                 S  s   g | ]}t |qS r   r:   r1   r   r   r   r4   T   r5   r8   c                 S  s   g | ]}t |qS r   r:   r1   r   r   r   r4   U   r5   r9   )r$   r&   r'   r(   r)   r*   r+   r,   )r;   boolr   r   r   r   r   r   r   L   s    zTraceConfig.from_json)r   r   r   r$   __annotations__r&   r'   r(   r)   r*   r+   r,   r   r    r   r   r   r   r   r"      s   
r"   c                   @  s,   e Zd ZdZdZdZdd Zedd ZdS )	StreamFormatz
    Data format of a trace. Can be either the legacy JSON format or the
    protocol buffer format. Note that the JSON format will be deprecated soon.
    r   protoc                 C  s   | j S r   valuer   r   r   r   r   b   s    zStreamFormat.to_jsonc                 C  s   | |S r   r   r   r   r   r   r   e   s    zStreamFormat.from_jsonN)	r   r   r   r   ZJSONPROTOr   r    r   r   r   r   r   r>   Z   s   r>   c                   @  s,   e Zd ZdZdZdZdd Zedd ZdS )	StreamCompressionzB
    Compression type to use for traces returned via streams.
    nonegzipc                 C  s   | j S r   r@   r   r   r   r   r   q   s    zStreamCompression.to_jsonc                 C  s   | |S r   r   r   r   r   r   r   t   s    zStreamCompression.from_jsonN)	r   r   r   r   NONEZGZIPr   r    r   r   r   r   r   rC   j   s   rC   z0typing.Generator[T_JSON_DICT, T_JSON_DICT, None]r
   c                  c  s   ddi} | V }dS )z'
    Stop trace events collection.
    methodzTracing.endNr   cmd_dictr   r   r   r   endy   s    rJ   z<typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[str]]c                  c  s    ddi} | V }dd |d D S )zc
    Gets supported tracing categories.

    :returns: A list of supported tracing categories.
    rG   zTracing.getCategoriesc                 S  s   g | ]}t |qS r   r:   r1   r   r   r   r4      r5   z"get_categories.<locals>.<listcomp>
categoriesr   rH   r   r   r   get_categories   s    rL   r;   )sync_idr   c                 c  s"   t  }| |d< d|d}|V }dS )zh
    Record a clock sync marker in the trace.

    :param sync_id: The ID of this clock sync marker
    ZsyncIdzTracing.recordClockSyncMarkerrG   paramsNr	   )rM   rO   rI   r   r   r   r   record_clock_sync_marker   s    rQ   r%   zCtyping.Generator[T_JSON_DICT, T_JSON_DICT, typing.Tuple[str, bool]])deterministicr   c                 c  s>   t  }| dur| |d< d|d}|V }t|d t|d fS )aI  
    Request a global memory dump.

    :param deterministic: *(Optional)* Enables more deterministic results by forcing garbage collection
    :returns: A tuple with the following items:

        0. **dumpGuid** - GUID of the resulting global memory dump.
        1. **success** - True iff the global memory dump succeeded.
    NrR   zTracing.requestMemoryDumprN   ZdumpGuidsuccess)r	   r;   r<   )rR   rO   rI   r   r   r   r   request_memory_dump   s    

rT   r#   typing.Optional[float]typing.Optional[StreamFormat]"typing.Optional[StreamCompression]ztyping.Optional[TraceConfig])rK   optionsbuffer_usage_reporting_intervaltransfer_modestream_formatstream_compressiontrace_configr   c           
      c  s   t  }| dur| |d< |dur&||d< |dur6||d< |durF||d< |durZ| |d< |durn| |d< |dur| |d< d	|d
}|V }	dS )a7  
    Start trace events collection.

    :param categories: *(Optional)* Category/tag filter
    :param options: *(Optional)* Tracing options
    :param buffer_usage_reporting_interval: *(Optional)* If set, the agent will issue bufferUsage events at this interval, specified in milliseconds
    :param transfer_mode: *(Optional)* Whether to report trace events as series of dataCollected events or to save trace to a stream (defaults to ```ReportEvents````).
    :param stream_format: *(Optional)* Trace data format to use. This only applies when using ````ReturnAsStream```` transfer mode (defaults to ````json````).
    :param stream_compression: *(Optional)* Compression format to use. This only applies when using ````ReturnAsStream```` transfer mode (defaults to ````none```)
    :param trace_config: *(Optional)*
    NrK   rX   ZbufferUsageReportingIntervalZtransferModeZstreamFormatstreamCompressionZtraceConfigzTracing.startrN   )r	   r   )
rK   rX   rY   rZ   r[   r\   r]   rO   rI   r   r   r   r   start   s&    r_   zTracing.bufferUsagec                   @  s:   e Zd ZU ded< ded< ded< edd dddZd	S )
BufferUsagerU   percent_fullevent_countrA   r   r   c                 C  sJ   | d|v rt |d nd d|v r,t |d nd d|v rBt |d nd dS )NZpercentFullZ
eventCountrA   )ra   rb   rA   )floatr   r   r   r   r      s
    zBufferUsage.from_jsonN)r   r   r   r=   r    r   r   r   r   r   r`      s
   
r`   zTracing.dataCollectedc                   @  s.   e Zd ZU dZded< edd dddZdS )	DataCollectedz
    Contains an bucket of collected trace events. When tracing is stopped collected events will be
    send as a sequence of dataCollected events followed by tracingComplete event.
    ztyping.List[dict]rA   r   r   c                 C  s   | dd |d D dS )Nc                 S  s   g | ]}t |qS r   rP   r1   r   r   r   r4     r5   z+DataCollected.from_json.<locals>.<listcomp>rA   r@   r   r   r   r   r   r     s    zDataCollected.from_jsonNr   r   r   r   r=   r    r   r   r   r   r   rd      s   
rd   zTracing.tracingCompletec                   @  sF   e Zd ZU dZded< ded< ded< ded	< ed
d dddZdS )TracingCompletez
    Signals that tracing is stopped and there is no trace buffers pending flush, all data were
    delivered via dataCollected events.
    r<   data_loss_occurredz typing.Optional[io.StreamHandle]streamrV   trace_formatrW   r\   r   r   c                 C  s\   | t |d d|v r$tj|d nd d|v r<t|d nd d|v rTt|d nd dS )NZdataLossOccurredrh   ZtraceFormatr^   )rg   rh   ri   r\   )r<   r   ZStreamHandler   r>   rC   r   r   r   r   r     s    
zTracingComplete.from_jsonNre   r   r   r   r   rf   
  s   
rf   )N)NNNNNNN)
__future__r   utilr   r   Zdataclassesr   enumtyping r   r	   r   r"   Enumr>   rC   rJ   rL   rQ   rT   r_   r`   rd   rf   r   r   r   r   <module>   s@   ;
        *