§
    S¯j+  ã                   óž   — d dl Z d dlmZ d dlmZmZ d dlmZmZ d dlm	Z	 d dl
mZ d dlZe G d„ d¦  «        ¦   «         Z G d	„ d
¦  «        ZdS )é    N)Ú	dataclass)ÚdatetimeÚ	timedelta)ÚOptionalÚTuple)Úuuid1)Ú	WebDriverc                   ó:   — e Zd ZU eed<   eed<   eed<   defd„ZdS )ÚSessionÚ
session_idÚdriverÚ
created_atÚreturnc                 ó8   — t          j        ¦   «         | j        z
  S ©N)r   Únowr   ©Úselfs    ú/app/sessions.pyÚlifetimezSession.lifetime   s   € ÝŒ|‰~Œ~ ¤Ñ/Ð/ó    N)	Ú__name__Ú
__module__Ú__qualname__ÚstrÚ__annotations__r	   r   r   r   © r   r   r   r      sR   € € € € € € à€O€OOØÐÐÑØÐÐÑð0˜)ð 0ð 0ð 0ð 0ð 0ð 0r   r   c                   óÔ   — e Zd ZdZd„ Z	 	 ddee         dee         dee         de	e
ef         fd	„Zdedefd
„Zdedefd„Zddedee         de	e
ef         fd„Zdee         fd„ZdS )ÚSessionsStoragez<SessionsStorage creates, stores and process all the sessionsc                 ó   — i | _         d S r   ©Úsessionsr   s    r   Ú__init__zSessionsStorage.__init__   s   € ØˆŒˆˆr   NFr   ÚproxyÚ	force_newr   c                 ó>  — |pt          t          ¦   «         ¦  «        }|r|                      |¦  «         |                      |¦  «        r| j        |         dfS t          j        |¦  «        }t          j        ¦   «         }t          |||¦  «        }|| j        |<   |dfS )a+  create creates new instance of WebDriver if necessary,
        assign defined (or newly generated) session_id to the instance
        and returns the session object. If a new session has been created
        second argument is set to True.

        Note: The function is idempotent, so in case if session_id
        already exists in the storage a new instance of WebDriver won't be created
        and existing session will be returned. Second argument defines if 
        new session has been created (True) or an existing one was used (False).
        FT)
r   r   ÚdestroyÚexistsr"   ÚutilsÚget_webdriverr   r   r   )r   r   r$   r%   r   r   Úsessions          r   ÚcreatezSessionsStorage.create   sš   € ð  Ð/¥3¥u¡w¤w¡<¤<ˆ
àð 	%ØLŠL˜Ñ$Ô$Ð$à;Š;zÑ"Ô"ð 	4Ø”= Ô,¨eÐ3Ð3åÔ$ UÑ+Ô+ˆÝ”\‘^”^ˆ
Ý˜* f¨jÑ9Ô9ˆà$+ˆŒjÑ!à˜ˆ}Ðr   c                 ó   — || j         v S r   r!   )r   r   s     r   r(   zSessionsStorage.exists8   s   € Ø˜Tœ]Ð*Ð*r   c                 óì   — |                       |¦  «        sdS | j                             |¦  «        }t          j        dk    r|j                             ¦   «          |j                             ¦   «          dS )zÿdestroy closes the driver instance and removes session from the storage.
        The function is noop if session_id doesn't exist.
        The function returns True if session was found and destroyed,
        and False if session_id wasn't found.
        FÚntT)r(   r"   Úpopr)   ÚPLATFORM_VERSIONr   ÚcloseÚquit)r   r   r+   s      r   r'   zSessionsStorage.destroy;   sm   € ð {Š{˜:Ñ&Ô&ð 	Ø5à”-×#Ò# JÑ/Ô/ˆÝÔ! TÒ)Ð)ØŒN× Ò Ñ"Ô"Ð"ØŒ×ÒÑÔÐØˆtr   Úttlc                 óÖ   — |                       |¦  «        \  }}|L|sJ|                     ¦   «         |k    r2t          j        d|› d¦  «         |                       |d¬¦  «        \  }}||fS )NzHsession's lifetime has expired, so the session is recreated (session_id=ú)T)r%   )r,   r   ÚloggingÚdebug)r   r   r4   r+   Úfreshs        r   ÚgetzSessionsStorage.getJ   sv   € ØŸš ZÑ0Ô0‰ˆàˆ? 5ˆ?¨W×-=Ò-=Ñ-?Ô-?À#Ò-EÐ-EÝŒMÐsÐfpÐsÐsÐsÑtÔtÐtØ!Ÿ[š[¨¸t˜[ÑDÔD‰NˆGUà˜ˆ~Ðr   c                 óN   — t          | j                             ¦   «         ¦  «        S r   )Úlistr"   Úkeysr   s    r   Úsession_idszSessionsStorage.session_idsS   s   € ÝD”M×&Ò&Ñ(Ô(Ñ)Ô)Ð)r   )NNFr   )r   r   r   Ú__doc__r#   r   r   ÚdictÚboolr   r   r,   r(   r'   r   r:   r<   r>   r   r   r   r   r      s  € € € € € ØFÐFðð ð ð PTØ+0ðð  ¨#¤ð ¸hÀt¼nð Ø" 4œ.ðØ5:¸7ÀD¸=Ô5Iðð ð ð ð8+ ð +¨ð +ð +ð +ð +ð #ð ¨$ð ð ð ð ðð ˜cð ¨°Ô(;ð ÀuÈWÐVZÈ]ÔG[ð ð ð ð ð*˜T #œYð *ð *ð *ð *ð *ð *r   r   )r7   Údataclassesr   r   r   Útypingr   r   Úuuidr   Ú#selenium.webdriver.chrome.webdriverr	   r)   r   r   r   r   r   ú<module>rF      sã   ðØ €€€Ø !Ð !Ð !Ð !Ð !Ð !Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ø Ð Ð Ð Ð Ð à 9Ð 9Ð 9Ð 9Ð 9Ð 9à €€€ð ð0ð 0ð 0ð 0ð 0ñ 0ô 0ñ „ð0ð>*ð >*ð >*ð >*ð >*ñ >*ô >*ð >*ð >*ð >*r   