
    ]*i+                         S SK r S SKJr  S SKJrJr  S SKJrJr  S SKJ	r	  S SK
Jr  S SKr\ " S S5      5       r " S	 S
5      rg)    N)	dataclass)datetime	timedelta)OptionalTuple)uuid1)	WebDriverc                   B    \ rS rSr% \\S'   \\S'   \\S'   S\4S jr	Sr
g)	Session   
session_iddriver
created_atreturnc                 F    [         R                  " 5       U R                  -
  $ N)r   nowr   selfs    /app/sessions.pylifetimeSession.lifetime   s    ||~//     N)__name__
__module____qualname____firstlineno__str__annotations__r	   r   r   r   __static_attributes__r   r   r   r   r      s    O0) 0r   r   c                       \ rS rSrSrS r  SS\\   S\\   S\\	   S\
\\	4   4S	 jjrS\S\	4S
 jrS\S\	4S jrSS\S\\   S\
\\	4   4S jjrS\\   4S jrSrg)SessionsStorage   z<SessionsStorage creates, stores and process all the sessionsc                     0 U l         g r   sessionsr   s    r   __init__SessionsStorage.__init__   s	    r   Nr   proxy	force_newr   c                 J   U=(       d    [        [        5       5      nU(       a  U R                  U5        U R                  U5      (       a  U R                  U   S4$ [
        R                  " U5      n[        R                  " 5       n[        XU5      nX`R                  U'   US4$ )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   createSessionsStorage.create   s      /3uw<
LL$;;z""==,e33$$U+\\^
*j9$+j!}r   c                     XR                   ;   $ r   r&   )r   r   s     r   r.   SessionsStorage.exists8   s    ]]**r   c                     U R                  U5      (       d  gU R                  R                  U5      n[        R                  S:X  a  UR
                  R                  5         UR
                  R                  5         g)zdestroy 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   r1   s      r   r-   SessionsStorage.destroy;   s[     {{:&&--##J/!!T)NN  "r   ttlc                     U R                  U5      u  p4UbG  U(       d@  UR                  5       U:  a,  [        R                  " SU S35        U R                  USS9u  p4X44$ )NzHsession's lifetime has expired, so the session is recreated (session_id=)T)r+   )r2   r   loggingdebug)r   r   r=   r1   freshs        r   getSessionsStorage.getJ   s^    Z0?5W-=-=-?#-EMMefpeqqrst![[t[DNG~r   c                 H    [        U R                  R                  5       5      $ r   )listr'   keysr   s    r   session_idsSessionsStorage.session_idsS   s    DMM&&())r   r&   )NNFr   )r   r   r   r   __doc__r(   r   r   dictboolr   r   r2   r.   r-   r   rC   rF   rH   r!   r   r   r   r#   r#      s    F PT+0# htn "4.5:7D=5I8+ + +# $ c (; uWVZ]G[ *T#Y *r   r#   )r@   dataclassesr   r   r   typingr   r   uuidr   #selenium.webdriver.chrome.webdriverr	   r/   r   r#   r   r   r   <module>rQ      s=     ! ( "  9  0 0 0>* >*r   