o
    ¶2úhó
  ã                   @   s&   d Z ddlZdZdZG dd„ dƒZdS )z(Application-level experiment ID support.é    NÚ
experimentÚHTTP_TENSORBOARD_EXPERIMENT_IDc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚExperimentIdMiddlewarea6  WSGI middleware extracting experiment IDs from URL to environment.

    Any request whose path matches `/experiment/SOME_EID[/...]` will have
    its first two path components stripped, and its experiment ID stored
    onto the WSGI environment with key taken from the `WSGI_ENVIRON_KEY`
    constant. All other requests will have paths unchanged and the
    experiment ID set to the empty string. It noops if the key taken from
    the `WSGI_ENVIRON_KEY` is already present in the environment.

    Instances of this class are WSGI applications (see PEP 3333).
    c                 C   s    || _ t dt t¡ ¡| _dS )z„Initializes an `ExperimentIdMiddleware`.

        Args:
          application: The WSGI application to wrap (see PEP 3333).
        z/%s/([^/]*)N)Ú_applicationÚreÚcompileÚescapeÚ_EXPERIMENT_PATH_COMPONENTÚ_pat)ÚselfÚapplication© r   ú\/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorboard/backend/experiment_id.pyÚ__init__*   s   
ÿzExperimentIdMiddleware.__init__c                 C   s”   t |v r
|  ||¡S | dd¡}| j |¡}|r,| d¡}|| d¡d … }| d¡}nd}|}d}||t < ||d< | dd¡| |d< |  ||¡S )NÚ	PATH_INFOÚ é   r   ÚSCRIPT_NAME)ÚWSGI_ENVIRON_KEYr   Úgetr
   ÚmatchÚgroupÚend)r   ÚenvironÚstart_responseÚpathÚmÚeidÚnew_pathÚrootr   r   r   Ú__call__7   s   
zExperimentIdMiddleware.__call__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r   r   r   r   r      s    r   )r$   r   r	   r   r   r   r   r   r   Ú<module>   s
   