B
    !²ô`h  ã               @   sL   d Z ddlmZ ddlmZ ddlmZ ddlZdZdZG dd	„ d	eƒZ	dS )
z(Application-level experiment ID support.é    )Úabsolute_import)Údivision)Úprint_functionNZ
experimentZ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)ÚselfZapplication© r   úP/home/dcms/DCMS/lib/python3.7/site-packages/tensorboard/backend/experiment_id.pyÚ__init__-   s    zExperimentIdMiddleware.__init__c             C   s”   t |kr|  ||¡S | dd¡}| j |¡}|rX| d¡}|| d¡d … }| d¡}nd}|}d}||t < ||d< | dd¡| |d< |  ||¡S )NZ	PATH_INFOÚ é   r   ZSCRIPT_NAME)ÚWSGI_ENVIRON_KEYr   Úgetr   ÚmatchÚgroupÚend)r   ÚenvironZstart_responseÚpathÚmZeidÚnew_pathÚrootr   r   r   Ú__call__:   s    
zExperimentIdMiddleware.__call__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r       s   r   )
r    Ú
__future__r   r   r   r   r
   r   Úobjectr   r   r   r   r   Ú<module>   s   