o
    ¶2úh®
  ã                   @   s"   d Z ddlmZ G dd„ dƒZdS )zîInternal path prefix support for TensorBoard.

Using a path prefix of `/foo/bar` enables TensorBoard to serve from
`http://localhost:6006/foo/bar/` rather than `http://localhost:6006/`.
See the `--path_prefix` flag docs for more details.
é    )Úerrorsc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚPathPrefixMiddlewareaX  WSGI middleware for path prefixes.

    All requests to this middleware must begin with the specified path
    prefix (otherwise, a 404 will be returned immediately). Requests
    will be forwarded to the underlying application with the path prefix
    stripped and appended to `SCRIPT_NAME` (see the WSGI spec, PEP 3333,
    for details).
    c                 C   sL   |  d¡rtd| ƒ‚|r| d¡std| ƒ‚|| _|| _| jd | _dS )ax  Initializes this middleware.

        Args:
          application: The WSGI application to wrap (see PEP 3333).
          path_prefix: A string path prefix to be stripped from incoming
            requests. If empty, this middleware is a no-op. If non-empty,
            the path prefix must start with a slash and not end with one
            (e.g., "/tensorboard").
        ú/z'Path prefix must not end with slash: %rz/Non-empty path prefix must start with slash: %rN)ÚendswithÚ
ValueErrorÚ
startswithÚ_applicationÚ_path_prefixÚ_strict_prefix)ÚselfÚapplicationÚpath_prefix© r   úZ/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorboard/backend/path_prefix.pyÚ__init__$   s   

ÿÿzPathPrefixMiddleware.__init__c                 C   sb   |  dd¡}|| jkr| | j¡st ¡ ‚|t| jƒd … |d< |  dd¡| j |d< |  ||¡S )NÚ	PATH_INFOÚ ÚSCRIPT_NAME)Úgetr	   r   r
   r   ÚNotFoundErrorÚlenr   )r   ÚenvironÚstart_responseÚpathr   r   r   Ú__call__:   s   ÿÿzPathPrefixMiddleware.__call__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s    	r   N)r   Útensorboardr   r   r   r   r   r   Ú<module>   s   