
    hje]                        d Z ddlmZ ddlZ ej        e          ZddlmZ ddl	m
Z
 ddlmZmZ ddlmZmZmZmZ dd	lmZ erd
dlmZ ddlmZ ddlmZ ddlmZ dZ G d de          ZdS )z9 Abstract request handler that handles bokeh-session-id

    )annotationsN)TYPE_CHECKING)HTTPServerRequest)	HTTPErrorauthenticated)check_token_signaturegenerate_jwt_tokengenerate_session_idget_session_id   )AuthRequestHandler   )ID   )ApplicationContext)ServerSession)BokehTornado)SessionHandlerc                  l     e Zd ZU dZded<   ded<   ded<   ded	<   d fdZd Zedd            Z xZ	S )r   zD Implements a custom Tornado handler for document display page

    r   applicationr   requestr   application_contextstrbokeh_websocket_pathtornado_appreturnNonec                v    |d         | _         |d         | _         t                      j        |g|R i | d S )Nr   r   )r   r   super__init__)selfr   argskw	__class__s       Blib/python3.11/site-packages/bokeh/server/views/session_handler.pyr    zSessionHandler.__init__J   sL    #%&;#< $&'=$>!2t222r22222    c                    d S )N )r!   r"   r#   s      r%   
initializezSessionHandler.initializeP   s    r&   r   c                  	
K   | j         }|                     dd           }|                     dd           }d| j        j        v rL|+t                              d           t          dd          | j        j                            d          }|=|+t                              d	           t          dd
          t          |          }nP|N|j	        rt          |j        |j                  }n+t                              d           t          dd          |B|j        "|j        pg fd| j        j        D             
n|j        

fd| j        j                                        D             }|j        "|j        pg fd| j        j        D             	n|j        		fd| j        j                                        D             }|rd|v rd|j        pg vr|d= | j        j        i n| j        j        }|||d}|                    | j        j                             | j                             t/          ||j        |j        |j        |          }t3          ||j        |j                  s,t                              d|           t          dd          | j                            || j        |           d {V }|S )Nzbokeh-token)defaultzbokeh-session-idzBokeh-Session-IdzLServer received session ID in request argument and header, expected only onei  z1session ID was provided as an argument and header)status_codereasonz<Server received both token and session ID, expected only onez'Both token and session ID were provided)
secret_keysignedzCServer configured not to generate session IDs and none was providedzNo bokeh-session-id providedc                    g | ]}|v|	S r(   r(   ).0headerexcluded_headerss     r%   
<listcomp>z.SessionHandler.get_session.<locals>.<listcomp>n   1     #F #F #Ff&,4D&D&D $*&D&D&Dr&   c                $    i | ]\  }}|v 	||S r(   r(   )r1   kvallowed_headerss      r%   
<dictcomp>z.SessionHandler.get_session.<locals>.<dictcomp>r   s3     0 0 01.. !...r&   c                    g | ]}|v|	S r(   r(   )r1   cookieexcluded_cookiess     r%   r4   z.SessionHandler.get_session.<locals>.<listcomp>w   r5   r&   c                .    i | ]\  }}|v 	||j         S r(   )value)r1   r7   r8   allowed_cookiess      r%   r:   z.SessionHandler.get_session.<locals>.<dictcomp>{   s5     0 0 0da.. !'...r&   Cookie)headerscookies	arguments)r.   r/   
expirationextra_payloadz$Session id had invalid signature: %rzInvalid token or session ID)r   get_argumentr   rB   logdebugr   getr   generate_session_idsr
   r.   sign_sessionsinclude_headersexclude_headersitemsinclude_cookiesexclude_cookiesrC   rD   updater   process_requestr	   session_token_expirationr   errorcreate_session_if_needed)r!   apptoken
session_idrB   rC   rD   payloadsessionr@   r9   r=   r3   s            @@@@r%   get_sessionzSessionHandler.get_sessionS   s     !!-!>> $ 1 12Dd 1 S S
!555%		hiiiC8kllll-112DEEJ%		XYYYC8abbbb'..JJ' X0CN8;8IK K K

 		_```C8VWWWW="*$'$7$=2 #F #F #F #F8L #F #F #F #&"50 0 0 0(<(B(B(D(D 0 0 0G "*$'$7$=2 #F #F #F #F8L #F #F #F #&"50 0 0 0dl.B.H.H.J.J 0 0 0G  &8w..8CDWD][]3^3^H%"l4<$,BXI")gIVVGNN43?OOPTP\]]^^^&z25..1.?252N5<	> > >E %U03,/,=? ? ? 	S II<jIII4QRRRR0II*VZVbdijjjjjjjjr&   )r   r   r   r   )r   r   )
__name__
__module____qualname____doc____annotations__r    r)   r   r\   __classcell__)r$   s   @r%   r   r   ?   s           ++++3 3 3 3 3 3   ? ? ? ]? ? ? ? ?r&   r   )r`   
__future__r   logging	getLoggerr]   rH   typingr   tornado.httputilr   tornado.webr   r   bokeh.util.tokenr   r	   r
   r   auth_request_handlerr   
core.typesr   contextsr   r[   r   tornador   __all__r   r(   r&   r%   <module>ro      sd    # " " " " " g!! !           / . . . . . 0 0 0 0 0 0 0 0            5 4 4 4 4 4 '      ------''''''&&&&&&T T T T T' T T T T Tr&   