
    [,h                         d Z ddlZddlZddlZddlZddlmZmZ ddlm	Z	 ddl
m
Z
 ddlmZ ddlmZ dd	lmZmZ dd
lmZ dZd Z G d d      Z G d d      Z G d de      Zy)zB
Provides all the main functional classes for analyzing HAR files
    N)ListOptional)Counter)cached_property)parser   )PageNotFoundError)RequestResponse)	MimicDictc                 B     t        j                          fd       }|S )zDWrapper function for converting dicts of entries to HarEnrty Objectsc                      t        |       }t        |d   t              rt        |d         |d<    t	        |      i |S )Nr   )list
isinstancedictHarEntrytuple)argskwargschanged_argsfuncs      L/var/www/html/trade_iq/venv/lib/python3.12/site-packages/haralyzer/assets.pyinnerzconvert_to_entry.<locals>.inner   sC     Dzl1ot,&|A7LOU<(3F33    )	functoolswraps)r   r   s   ` r   convert_to_entryr      s'     __T4 4 Lr   c                      e Zd ZdZd!defdZedeegdd fd       Z	edeegfd	       Z
ee	 d"d
ddededededefd              Zee	 d"d
ddededefd              Zee	 d"d
ddededefd              Zee	 d"d
ddededefd              Zee	 d"d
ddededefd              Zeded   defd       Zeded   fd       Zedefd       Zedefd       Zedefd       Zedefd        Zy)#	HarParserzj
    A Basic HAR parser that also adds helpful stuff for analyzing the
    performance of a web page.
    Nhar_datac                 R    |rt        |t              st        d      |d   | _        y)z
        :param har_data: a ``dict`` representing the JSON of a HAR file
        (i.e. - you need to load the HAR data into a string using json.loads or
        requests.json() if you are pulling the data via HTTP.
        zYA dict() representation of a HAR file is required to instantiate this class. Please RTFM.logN)r   r   
ValueErrorr    )selfr    s     r   __init__zHarParser.__init__.   s/     z(D9;  !r   filereturnc                     t        | dd      5 }t        t        j                  |            cddd       S # 1 sw Y   yxY w)z
        Function create a HarParser from a file path

        :param file: Path to har file or bytes of har file
        :type file: [str, bytes]
        :return: HarParser Object
        :rtype HarParser
        rzutf-8)r&   modeencodingN)openr   jsonload)r&   infiles     r   	from_filezHarParser.from_file;   s8     t#8 	0FTYYv./	0 	0 	0s	   7A datac                 >    t        t        j                  |             S )z
        Function to load string or bytes as a HarParser

        :param data: Input string or bytes
        :type  data: [str, bytes]
        :return: HarParser Object
        :rtype HarParser
        )r   r-   loads)r1   s    r   from_stringzHarParser.from_stringH   s     D)**r   entryr   header_typeheadervalueregexc                    |dvrt        d      t        | |      j                  D ]d  }|d   j                         |j                         k(  s(|d   .|r+t	        j
                  ||d   t        j                        r y||d   k(  sd y y)a  
        Function to match headers.

        Since the output of headers might use different case, like:

            'content-type' vs 'Content-Type'

        This function is case-insensitive

        :param entry: Entry to analyze
        :type entry: HarEntry
        :param header_type: Header type. Valid values: 'request', or 'response'
        :type header_type: str
        :param header: The header to search for
        :type header: str
        :param value: The value to search for
        :type value: str
        :param regex: Whether to use regex or exact match
        :type regex: bool

        :returns: Whether a match was found
        :rtype: bool
        )requestresponsez?Invalid header_type, should be either:

* 'request'
*'response'namer8   flagsTF)r#   getattrheaderslowerresearch
IGNORECASE)r5   r6   r7   r8   r9   hs         r   match_headerszHarParser.match_headersT   s    : 55T 
 ,44 	 Ay FLLN2qz7MRYYuajNAgJ&	  r   content_typec                     | j                   j                  }|r't        j                  ||t        j                        ry||k(  ryy)a  
        Matches the content type of a request using the mimeType metadata.

        :param entry: Entry to analyze
        :type entry: HarEntry
        :param content_type: Regex to use for finding content type
        :type content_type: str
        :param regex: Whether to use regex or exact match.
        :type regex: bool
        :return: Mime type matches
        :rtype: bool
        r>   TF)r<   mimeTyperC   rD   rE   )r5   rH   r9   	mime_types       r   match_content_typezHarParser.match_content_type   s:    " NN++	RYY|YbmmL9$r   request_typec                     |r<t        j                  || j                  j                  t         j                        duS | j                  j                  |k(  S )a  
        Helper function that returns entries with a request type
        matching the given `request_type` argument.

        :param entry: Entry to analyze
        :type entry: HarEntry
        :param request_type: Request type to match
        :type request_type: str
        :param regex: Whether to use a regex or string match
        :type regex: bool
        :return: Request method matches
        :rtype: bool
        r>   N)rC   rD   r;   methodrE   )r5   rM   r9   s      r   match_request_typezHarParser.match_request_type   sI    $ 		,(<(<BMMR }}##|33r   http_versionc                     | j                   j                  }|r(t        j                  ||t        j                        duS ||k(  S )a  
        Helper function that returns entries with a request type
        matching the given `request_type` argument.

        :param entry: Entry to analyze
        :type entry: HarEntry
        :param http_version: HTTP version type to match
        :type http_version: str
        :param regex: Whether to use a regex or string match
        :type regex: bool
        :return: HTTP version matches
        :rtype: bool
        r>   N)r<   httpVersionrC   rD   rE   )r5   rQ   r9   response_versions       r   match_http_versionzHarParser.match_http_version   sF    $ !>>55		,(8N  <//r   status_codec                     |r5t        j                  |t        | j                  j                              duS t        | j                  j                        |k(  S )a  
        Helper function that returns entries with a status code matching
        then given `status_code` argument.

        NOTE: This is doing a STRING comparison NOT NUMERICAL

        :param entry: Entry to analyze
        :type entry: HarEntry
        :param status_code: Status code to search for
        :type status_code: str
        :param regex: Whether to use a regex or string match
        :type regex: bool
        :return: Status code matches
        :rtype: bool
        N)rC   rD   strr<   status)r5   rV   r9   s      r   match_status_codezHarParser.match_status_code   sF    ( 99[#enn.C.C*DETQQ5>>(()[88r   
asset_listc                 *   i }| D ]  }|j                   }t        |j                        }||v r||   j                  |       n|g||<   t	        d|      D ]:  }|t        j                  d      z   }||v r||   j                  |       5|g||<   <  |S )a  
        Returns a `dict` of the timeline for the requested assets. The key is
        a datetime object (down to the millisecond) of ANY time where at least
        one of the requested assets was loaded. The value is a `list` of ALL
        assets that were loading at that time.

        :param asset_list: The assets to create a timeline for.
        :type asset_list: List[HarEntry]
        :return: Milliseconds and assets that were loaded
        :rtype: dict
        r   )milliseconds)	startTimeinttimeappendrangedatetime	timedelta)r[   resultsassettime_key	load_time_s         r   create_asset_timelinezHarParser.create_asset_timeline   s      	0EHEJJI7"!((/%*G! 1i( 0#h&8&8a&HHw&H%,,U3).GH%0	0$ r   HarPagec                    g }t        d | j                  d   D              r|j                  t        d|              | j                  j	                  dg       D ]#  }t        |d   |       }|j                  |       % |S )z
        This is a list of HarPage objects, each of which represents a page
        from the HAR file.

        :return: HarPages in the file
        :rtype: List[HarPage]
        c              3   $   K   | ]  }d |v 
 yw)pagerefN ).0r5   s     r   	<genexpr>z"HarParser.pages.<locals>.<genexpr>  s     L%y%Ls   entriesunknown)
har_parserpagesid)anyr    ra   rk   get)r$   ru   har_pagepages       r   ru   zHarParser.pages  sv     L4==3KLLLLt<=))'26 	H8D>d;DLL	 r   c                      | j                   d   S )zc
        Browser of Har File

        :return: Browser of the Har File
        :rtype: str
        browserr    r$   s    r   r|   zHarParser.browser       }}Y''r   c                      | j                   d   S )zW
        HAR Version

        :return: Version of HAR used
        :rtype: str
        versionr}   r~   s    r   r   zHarParser.version$  r   r   c                      | j                   d   S )z
        Creator of Har File. Usually the same as the browser but not always

        :return: Program that created the HarFile
        :rtype: str
        creatorr}   r~   s    r   r   zHarParser.creator.  r   r   c                 |    | j                   D cg c]  }|j                  dk7  s| }}|d   j                  S c c}w )zo
        Hostname of first page

        :return: Hostname of the first known page
        :rtype: str
        rs   r   )ru   page_idhostname)r$   pvalid_pagess      r   r   zHarParser.hostname8  s<     #'**GQ		Y0FqGG1~&&& Hs   99N)T)__name__
__module____qualname____doc__r   r%   staticmethodrX   bytesr0   r4   r   boolrG   rL   rP   rU   rZ   r   rj   propertyru   r|   r   r   r   r   ro   r   r   r   r   (   sW   
( ( 
0e 
0 
0 
0 	+3, 	+ 	+ TX''(+'58'AD'MQ'	'  'R <@),59	  0 <@44),4594	4  4. <@00),0590	0  00 ;?99(+9489	9  9, $z*: t  B tI  & ( ( ( ( ( ( ( ( ( '# ' 'r   r   c                      e Zd ZdZ	 dDdedddefdZd Zd	 Zd
 Z	dede
d   fdZdedefdZdefdZdedee   fdZ	 	 	 	 	 	 dEdedededededede
d   fdZ	 	 	 	 dFdededededef
dZede
d   defd       Zede
d   defd       Zedefd       Zedee   fd       Zede
d   fd        Zedee   fd!       Zede
d   fd"       Zede
d   fd#       ZedGd$       Zedefd%       Zede
d   fd&       Z ede
d   fd'       Z!ede
d   fd(       Z"ede
d   fd)       Z#ede
d   fd*       Z$ede
d   fd+       Z%ede
d   fd,       Z&edefd-       Z'edefd.       Z(edefd/       Z)edefd0       Z*edefd1       Z+edefd2       Z,edefd3       Z-edefd4       Z.edefd5       Z/edefd6       Z0edefd7       Z1edefd8       Z2edefd9       Z3edefd:       Z4edefd;       Z5edefd<       Z6edefd=       Z7edefd>       Z8edefd?       Z9edefd@       Z:edefdA       Z;edefdB       Z<edefdC       Z=y)Hrk   z;
    An object representing one page of a HAR resource
    Nr   rt   r   r    c                     || _         d| _        ||t        d      |r|| _        nt	        |      | _        ddddd	d
dd| _        | j                  j                  }d}| j                   dk(  rd}|j                  dg       D ]B  }|d   | j                   k(  sd}|j                  dd      | _        |d   | _	        |d   | _
        D |s0|d   D cg c]  }|d   	 }}t        d| j                    d|       yc c}w )z
        :param page_id: Page ID
        :type page_id: str
        :param har_parser: HarParser object
        :type har_parser: HarParser
        :param har_data: HAR file
        :type har_data: dict
        r   Nz%Either parser or har_data is requiredr}   zimage.*z.*cssztext.*z.*javascriptzaudio.*zvideo.*|.*flashhtml)imagecsstextjsaudiovideor   Frs   Tru   rv   title startedDateTimepageTimingszNo page found with id z

Page ID's are )r   _indexr#   r   r   asset_typesr    rx   r   r   r   r	   )r$   r   rt   r    raw_datavalidrz   page_idss           r   r%   zHarPage.__init__J  s.    ("2DEE$DK#X6DK
  &
 ;;''<<9$ELL"- 	7DDzT\\)!XXgr2
'+,='>$#'#6 	7 /7/@AtT
AHA#(6H
S  As   C;c                 :    d| j                    d| j                   S )NzID: z, URL: )r   urlr~   s    r   __repr__zHarPage.__repr__|  s    dll^7488*55r   c                 ,    t        | j                        S r   )iterrr   r~   s    r   __iter__zHarPage.__iter__  s    DLL!!r   c                     	 | j                   | j                     }| xj                  dz  c_        |S # t        $ r t        w xY w)Nr   )rr   r   
IndexErrorStopIteration)r$   results     r   __next__zHarPage.__next__  sE    	 \\$++.F 	q  	 	 s	   2 A
asset_typer'   r   c                 @    | j                  | j                  |         S )z
        Returns a list of all HarEntry object of a certain file type.
        :param asset_type: Asset type to filter for
        :type asset_type: str
        :return: List of HarEntry objects that meet the
        :rtype: List[HarEntry]
        rH   )filter_entriesr   r$   r   s     r   _get_asset_fileszHarPage._get_asset_files  s#     ""0@0@0L"MMr   c                 h    |dk(  r| j                   }nt        | | dd      }| j                  |      S )z
        Helper function to dynamically create *_size properties.
        :param asset_type: Asset type to filter for
        :type asset_type: str
        :return: Size of transferred data
        :rtype: int
        rz   _filesN)rr   r@   get_total_size_transr$   r   assetss      r   _get_asset_size_transzHarPage._get_asset_size_trans  s;     \\FTj\#8$?F((00r   c                 h    |dk(  r| j                   }nt        | | dd      }| j                  |      S )z
        Helper function to dynamically create *_size properties.
        :param asset_type: Asset type to filter for
        :type asset_type: str
        :return: Size of assets
        :rtype: int
        rz   r   N)rr   r@   get_total_sizer   s      r   _get_asset_sizezHarPage._get_asset_size  s;     \\FTj\#8$?F""6**r   c                     |dk(  r| j                   j                  S |dk(  r| j                  d   S |dk(  r| j                  dk(  ry| j                  d   S | j	                  | j
                  |         S )	z
        Helper function to dynamically create *_load_time properties. Return
        value is in ms.
        :param asset_type: Asset type to filter for
        :type asset_type: str
        :return: Time of loading asset
        :rtype: int
        initialcontentonContentLoadrz   rs   NonLoadr   )actual_pager`   r   r   get_load_timer   r   s     r   _get_asset_loadzHarPage._get_asset_load  s     "##((("##O44||y(##H-- !!t/?/?
/K!LLr   rM   rH   rV   rQ   load_time__gtr9   c                 l   g }| j                   D ]  }	 d}	| j                  }
||
j                  |||      sd}	| | j                  j                  |||      sd}	||
j	                  |||      sd}	||
j                  |||      sd}	||j                  |k  rd}	|	s|j                  |        |S )a<  
        Generate a list of entries with from criteria

        :param request_type: The request type (i.e. - GET or POST)
        :type request_type: str
        :param content_type: Regex to use for finding content type
        :type content_type: str
        :param status_code: The desired status code
        :type status_code: str
        :param http_version: HTTP version of request
        :type http_version: str
        :param load_time__gt: Load time in milliseconds. If
            provided, an entry whose load time is less than this value will
            be excluded from the results.
        :type load_time__gt: int
        :param regex: Whether to use regex or exact match.
        :type regex: bool
        :return: List of entry objects based on the filtered criteria.
        :rtype: List[HarEntry]
        T)r9   F)rr   r   rP   rL   rZ   rU   r`   ra   )r$   rM   rH   rV   rQ   r   r9   re   r5   valid_entryr   s              r   r   zHarPage.filter_entries  s    < \\  	&E	 KA'0D0D|5 1E 1 $'{{55e\QV5W"'K&q/B/B{% 0C 0 $'0D0D|5 1E 1 $(UZZ--G#u%A 	&D r   asynchronousc                     | j                  |||      }|j                  d|      }|sd}|D ]  }||j                  z  } |S t        | j                  j                  |            S )a%  
        This method can return the TOTAL load time for the assets or the ACTUAL
        load time, the difference being that the actual load time takes
        asynchronous transactions into account. So, if you want the total load
        time, set asynchronous=False.

        EXAMPLE:

        I want to know the load time for images on a page that has two images,
        each of which took 2 seconds to download, but the browser downloaded
        them at the same time.

        self.get_load_time(content_types=['image']) (returns 2)
        self.get_load_time(content_types=['image'], asynchronous=False) (returns 4)

        :param request_type: The request type (i.e. - GET or POST)
        :type request_type: str
        :param content_type: Regex to use for finding content type
        :type content_type: str
        :param status_code: The desired status code
        :type status_code: str
        :param asynchronous: Whether to separate load times
        :type asynchronous: bool
        :return: Total load time
        :rtype: int
        )rM   rH   rV   asyncr   )r   rx   r`   lenr   rj   )	r$   rM   rH   rV   r   r   rr   r`   r5   s	            r   r   zHarPage.get_load_time  sy    D %%%%# & 
 zz'<8D  #

"#K4;;44W=>>r   rr   c                 ~    d}| D ]5  }|j                   j                  dkD  s||j                   j                  z  }7 |S )z
        Returns the total size of a collection of entries.

        :param entries: ``list`` of entries to calculate the total size of.
        :return: Total size of entries
        :rtype: int
        r   )r<   bodySizerr   sizer5   s      r   r   zHarPage.get_total_sizeA  sE      	0E~~&&*///	0 r   c                     d}| D ];  }|j                   j                  d   dkD  s ||j                   j                  d   z  }= |S )a3  
        Returns the total size of a collection of entries - transferred.

        NOTE: use with har file generated with chrome-har-capturer

        :param entries: ``list`` of entries to calculate the total size of.
        :return: Total size of entries that was transferred
        :rtype: int
        r   _transferSize)r<   	raw_entryr   s      r   r   zHarPage.get_total_size_transP  sQ      	BE~~''81<00AA	B r   c                 r    | j                   d   j                  j                  D ]  }|d   dk(  s|d   c S  y)zN
        :return: Hostname of the initial request
        :rtype: str
        r   r=   Hostr8   N)rr   r;   rA   )r$   r7   s     r   r   zHarPage.hostnamec  s=     ll1o--55 	'Ff~'g&	'r   c                     d| j                   d   j                  v rHd| j                   d   j                  j                  v r#| j                   d   j                  j                  S y)zu
        The absolute URL of the initial request.

        :return: URL of first request
        :rtype: str
        r;   r   r   N)rr   r   r;   r   r~   s    r   r   zHarPage.urlm  sS     a222a00:::<<?**...r   c                 >   g }| j                   j                  d   D ]^  }d|vr+| j                  dk(  s|j                  t	        |             2|d   | j                  k(  sE|j                  t	        |             ` t        d |D              rt        |d       S |S )z[
        :return: All entries that make up the page
        :rtype: List[HarEntry]
        rr   rn   rs   c              3   4   K   | ]  }|j                     y wr   r^   )rp   xs     r   rq   z"HarPage.entries.<locals>.<genexpr>  s     1qq{{1s   c                     | j                   S r   r   r5   s    r   <lambda>z!HarPage.entries.<locals>.<lambda>  s
    %// r   )key)r   r    r   ra   r   allsorted)r$   page_entriesr5   s      r   rr   zHarPage.entries|  s     [[)))4 	5E%<<9, ''8y!T\\1##HUO4	5 1L11,,IJJr   c                    | j                   dk(  ryd}| j                  D ]`  }|j                  j                  dk(  r6|j                  j                         D ]  \  }}|dk7  s|dkD  s||z  }  |S ||j                  z  }b |S )z[
        :return: Time to first byte of the page request in ms
        :rtype: int
        rs   Nr      receive)r   rr   r<   rY   timingsitemsr`   )r$   ttfbr5   kvs        r   time_to_first_bytezHarPage.time_to_first_byte  s     <<9$\\ 	E~~$$+!MM//1 &DAqI~q5 AID&   EJJD	 r   c                 &    | j                  d      S )z
        Returns a list of GET requests, each of which is a HarEntry object

        :return: All GET requests
        :rtype: List[HarEntry]
        rx   rM   r   r~   s    r   get_requestszHarPage.get_requests  s     """66r   c                 &    | j                  d      S )z
        Returns a list of POST requests, each of which is an HarEntry object

        :return: All POST requests
        :rtype: List[HarEntry]
        postr   r   r~   s    r   post_requestszHarPage.post_requests  s     """77r   c                 v    | j                   D ]*  }d|j                  j                  cxk  r	dk  r#|c S  |c S  y)z
        Returns the first entry object that does not have a redirect status,
        indicating that it is the actual page we care about (after redirects).

        :return: First entry of the page
        :rtype: HarEntry
        i,  i  N)rr   r<   rY   )r$   r5   s     r   r   zHarPage.actual_page  s=     \\ 	E%..//636 7	r   c                     t        | j                  D cg c]  }|j                  j                   c}      }|j	                         D ci c]  \  }}|dkD  s|| c}}S c c}w c c}}w )z
        Returns a dict of urls and its number of repetitions that are sent more than once

        :return: URLs and the amount of times they were duplicated
        :rtype: dict
        r   )r   rr   r;   r   r   )r$   r5   counted_urlsr   r   s        r   duplicate_url_requestzHarPage.duplicate_url_request  sX     t||Le 1 1LM!-!3!3!5?AQ1??  M?s   A"A'A'c                 $    | j                  d      S )zv
        All image files for a page

        :return: Image entries for a page
        :rtype: List[HarEntry]
        r   r   r~   s    r   image_fileszHarPage.image_files       $$W--r   c                 $    | j                  d      S )zr
        All CSS files for a page

        :return: CSS entries for a page
        :rtype: List[HarEntry]
        r   r   r~   s    r   	css_fileszHarPage.css_files  s     $$U++r   c                 $    | j                  d      S )zt
        All text files for a page

        :return: Text entries for a page
        :rtype: List[HarEntry]
        r   r   r~   s    r   
text_fileszHarPage.text_files       $$V,,r   c                 $    | j                  d      S )zp
        All JS files for a page

        :return: JS entries for a page
        :rtype: List[HarEntry]
        r   r   r~   s    r   js_fileszHarPage.js_files  s     $$T**r   c                 $    | j                  d      S )zv
        All audio files for a page

        :return: Audio entries for a page
        :rtype: List[HarEntry]
        r   r   r~   s    r   audio_fileszHarPage.audio_files  r   r   c                 $    | j                  d      S )zv
        All video files for a page

        :return: Video entries for a page
        :rtype: List[HarEntry]
        r   r   r~   s    r   video_fileszHarPage.video_files  r   r   c                 $    | j                  d      S )zt
        All HTML files for a page

        :return: HTML entries for a page
        :rtype: List[HarEntry]
        r   r   r~   s    r   
html_fileszHarPage.html_files  r   r   c                 $    | j                  d      S )zY
        Size of the page

        :return: Size of the page
        :rtype: int
        rz   r   r~   s    r   	page_sizezHarPage.page_size       ##F++r   c                 $    | j                  d      S )zy
        Size of image files from the page

        :return: Size of image files on the page
        :rtype: int
        r   r  r~   s    r   
image_sizezHarPage.image_size$       ##G,,r   c                 $    | j                  d      S )zu
        Size of CSS files from the page

        :return: Size of CSS files on the page
        :rtype: int
        r   r  r~   s    r   css_sizezHarPage.css_size.       ##E**r   c                 $    | j                  d      S )zw
        Size of text files from the page

        :return: Size of text files on the page
        :rtype: int
        r   r  r~   s    r   	text_sizezHarPage.text_size8  r
  r   c                 $    | j                  d      S )zs
        Size of JS files from the page

        :return: Size of JS files on the page
        :rtype: int
        r   r  r~   s    r   js_sizezHarPage.js_sizeB       ##D))r   c                 $    | j                  d      S )zy
        Size of audio files from the page

        :return: Size of audio files on the page
        :rtype: int
        r   r  r~   s    r   
audio_sizezHarPage.audio_sizeL  r  r   c                 $    | j                  d      S )zy
        Size of video files from the page

        :return: Size of video files on the page
        :rtype: int
        r   r  r~   s    r   
video_sizezHarPage.video_sizeV  r  r   c                 $    | j                  d      S )zm
        Page transfer size

        :return: Size of transfer data for the page
        :rtype: int
        rz   r   r~   s    r   page_size_transzHarPage.page_size_trans`       ))&11r   c                 $    | j                  d      S )zl
        Image transfer size

        :return: Size of transfer data for images
        :rtype: int
        r   r  r~   s    r   image_size_transzHarPage.image_size_transj       ))'22r   c                 $    | j                  d      S )zg
        CSS transfer size

        :return: Size of transfer data for CSS
        :rtype: int
        r   r  r~   s    r   css_size_transzHarPage.css_size_transt  s     ))%00r   c                 $    | j                  d      S )zi
        Text transfer size

        :return: Size of transfer data for text
        :rtype: int
        r   r  r~   s    r   text_size_transzHarPage.text_size_trans~  r  r   c                 $    | j                  d      S )ze
        JS transfer size

        :return: Size of transfer data for JS
        :rtype: int
        r   r  r~   s    r   js_size_transzHarPage.js_size_trans  s     ))$//r   c                 $    | j                  d      S )zk
        Audio transfer size

        :return: Size of transfer data for audio
        :rtype: int
        r   r  r~   s    r   audio_size_transzHarPage.audio_size_trans  r   r   c                 $    | j                  d      S )zl
        Video transfer size

        :return: Size of transfer data for images
        :rtype: int
        r   r  r~   s    r   video_size_transzHarPage.video_size_trans  r   r   c                 $    | j                  d      S )zg
        Initial load time

        :return: Initial load time of the page
        :rtype: int
        r   r   r~   s    r   initial_load_timezHarPage.initial_load_time       ##I..r   c                 $    | j                  d      S )zc
        Content load time

        :return: Load time for all content
        :rtype: int
        r   r,  r~   s    r   content_load_timezHarPage.content_load_time  r.  r   c                 $    | j                  d      S )zd
        Load time of the page

        :return: Load time for the page
        :rtype: int
        rz   r,  r~   s    r   page_load_timezHarPage.page_load_time  r
  r   c                 $    | j                  d      S )zf
        Image load time

        :return: Load time for images on a page
        :rtype: int
        r   r,  r~   s    r   image_load_timezHarPage.image_load_time  r  r   c                 $    | j                  d      S )za
        CSS load time

        :return: Load time for CSS on a page
        :rtype: int
        r   r,  r~   s    r   css_load_timezHarPage.css_load_time  r  r   c                 $    | j                  d      S )z_
        JS load time

        :return: Load time for JS on a page
        :rtype: int
        r   r,  r~   s    r   js_load_timezHarPage.js_load_time  r  r   c                 $    | j                  d      S )ze
        Audio load time

        :return: Load time for audio on a page
        :rtype: int
        r   r,  r~   s    r   audio_load_timezHarPage.audio_load_time  r  r   c                 $    | j                  d      S )ze
        Video load time

        :return: Load time for video on a page
        :rtype: int
        r   r,  r~   s    r   video_load_timezHarPage.video_load_time  r  r   c                 $    | j                  d      S )zc
        HTML load time

        :return: Load time for HTML on a page
        :rtype: int
        r   r,  r~   s    r   html_load_timezHarPage.html_load_time  r
  r   )NN)NNNNNT)NNNT)r'   r   )>r   r   r   r   rX   r   r%   r   r   r   r   r   r_   r   r   r   r   r   r   r   r   r   r   r   r   r   rr   r   r   r   r   r   r   r   r   r   r  r  r  r	  r  r  r  r  r  r  r  r  r"  r$  r&  r(  r*  r-  r0  r2  r4  r6  r8  r:  r<  r>  ro   r   r   rk   rk   D  s   
 NR00(30FJ0d6"N3 N4
3C N1 1 1+# +M# M(3- M: !  !BB B 	B
 B B B 
j	BL ! !/?/? /? 	/?
 /? 
/?b Z 0 S   d:&6 3  $ '# ' ' Xc]   j)  " HSM  * 7d:. 7 7 8tJ/ 8 8 
 
 @t @ @ .T*- . . ,4
+ , , -D, - - +$z* + + .T*- . . .T*- . . -D, - - ,3 , , -C - - +# + + ,3 , , * * * -C - - -C - - 2 2 2 3# 3 3 1 1 1 2 2 2 0s 0 0 3# 3 3 3# 3 3 /3 / / /3 / / , , , - - - +s + + *c * * - - - - - - , , ,r   rk   c                   l    e Zd ZdZdef fdZd Zd Zede	fd       Z
edefd       Zedeej                     fd	       Zedefd
       Zedefd       Zedefd       Zedefd       Zedefd       Zedefd       Zedefd       Zedefd       Zedefd       Zedefd       Z xZS )r   z:
    An object that represent one entry in a HAR Page
    r5   c                 0    || _         t        | 	          y r   )r   superr%   )r$   r5   	__class__s     r   r%   zHarEntry.__init__  s    r   c                      d| j                    S NzHarEntry for r   r~   s    r   __str__zHarEntry.__str__
      txxj))r   c                      d| j                    S rD  rE  r~   s    r   r   zHarEntry.__repr__  rG  r   r'   c                 4    t        | j                  d         S )zG
        :return: Request of the entry
        :rtype: Request
        r;   r   )r
   r   r~   s    r   r;   zHarEntry.request  s     T^^I677r   c                 J    t        | j                  | j                  d         S )zI
        :return: Response of the entry
        :rtype: Response
        r<   )r   r5   )r   r   r   r~   s    r   r<   zHarEntry.response  s     DHHDNN:,FGGr   c                     	 t        j                  | j                  j                  dd            S # t         j                  j
                  $ r Y yw xY w)zw
        Start time and date

        :return: Start time of entry
        :rtype: Optional[datetime.datetime]
        r   r   N)r   parser   rx   _parserParserErrorr~   s    r   r^   zHarEntry.startTime   sD    	<< 2 23Db IJJ~~)) 		s   .1 AAc                      | j                   d   S )z=
        :return: Cached objects
        :rtype: str
        cacher   r~   s    r   rP  zHarEntry.cache.  s     ~~g&&r   c                 :    | j                   j                  dg       S )zL
        :return: Request and Response Cookies
        :rtype: list
        cookiesr   rx   r~   s    r   rS  zHarEntry.cookies6  s     ~~!!)R00r   c                      | j                   d   S )zA
        :return: Page for the entry
        :rtype: str
        rn   rQ  r~   s    r   rn   zHarEntry.pageref>       ~~i((r   c                 2    t        | j                  d         S )zJ
        :return: Port connection was made to
        :rtype: int
        
connection)r_   r   r~   s    r   portzHarEntry.portF  s     4>>,/00r   c                 @    | j                   j                  dd      dk(  S )zE
        :return: Connection was secure
        :rtype: bool
        _securityStater   securerT  r~   s    r   r\  zHarEntry.secureN  s!     ~~!!"2B78CCr   c                      | j                   d   S )zG
        :return: IP Address of the server
        :rtype: str
        serverIPAddressrQ  r~   s    r   serverAddresszHarEntry.serverAddressV  s     ~~/00r   c                 &    | j                   d   d   S )z?
        :return: HTTP Status Code
        :rtype: int
        r<   rY   rQ  r~   s    r   rY   zHarEntry.status^  s     ~~j)(33r   c                      | j                   d   S )zK
        :return: Time taken to complete entry
        :rtype: int
        r`   rQ  r~   s    r   r`   zHarEntry.timef  s     ~~f%%r   c                      | j                   d   S )zG
        :return: Timing of the page load
        :rtype: dict
        r   rQ  r~   s    r   r   zHarEntry.timingsn  rV  r   c                 &    | j                   d   d   S )z2
        :return: URL of Entry
        :rtype: strr;   r   rQ  r~   s    r   r   zHarEntry.urlv  s    
 ~~i(//r   )r   r   r   r   r   r%   rF  r   r   r
   r;   r   r<   r   rc   r^   rX   rP  r   rS  rn   r_   rY  r   r\  r_  rY   r`   r   r   __classcell__)rB  s   @r   r   r     s   d ** 8 8 8 H( H H 8H$5$56   's ' ' 1 1 1 ) ) ) 1c 1 1 D D D 1s 1 1 4 4 4 &c & & ) ) ) 0S 0 0r   r   )r   r   rc   r-   rC   typingr   r   collectionsr   r   dateutilr   errorsr	   httpr
   r   mixinsr   DECIMAL_PRECISIONr   r   rk   r   ro   r   r   <module>rl     sb       	 !  +  % #  Y' Y'xz
, z
,zz0y z0r   