
    [i8                    \    U d Z ddlmZ ddlZddlZddlmZ ddlmZ dZ	de
d<   dd	Zdd
Zy)aj  Utilities for safely resolving component asset paths and content types.

These helpers are used by server handlers to construct safe absolute paths for
component files and to determine the appropriate ``Content-Type`` header for
responses. Path resolution prevents directory traversal by normalizing and
checking real paths against a component's root directory.
    )annotationsN)Final)is_unsafe_path_patternzapplication/octet-streamz
Final[str]_OCTET_STREAMc                   t        |      ryt        j                  j                  |       }t        j                  j	                  t        j                  j                  ||            }t        j                  j                  |      }	 t        j                  j                  ||g      |k7  ry	 |S # t        $ r Y yw xY w)a:  Build an absolute path inside ``component_root`` if safe.

    The function first validates that ``relative_url_path`` does not contain
    dangerous patterns using :func:`~streamlit.path_security.is_unsafe_path_pattern`,
    then joins it with ``component_root`` and resolves symlinks.
    Returns ``None`` if the path is rejected by security checks or escapes the root.

    Parameters
    ----------
    component_root : str
        Absolute path to the component's root directory.
    relative_url_path : str
        Relative URL path from the component root to the requested file.
        Must be a simple relative path without dangerous patterns.

    Returns
    -------
    str or None
        The resolved absolute path if it passes all validation and stays
        within ``component_root``; otherwise ``None``.
    N)r   ospathrealpathnormpathjoin
commonpath
ValueError)component_rootrelative_url_path	root_real	candidatecandidate_reals        z/var/www/html/userprofiledev.eatanceapp.com/venv/lib/python3.12/site-packages/streamlit/web/server/component_file_utils.pybuild_safe_abspathr   #   s    . /0  0I  i9J!KLIWW%%i0N77y.9:iG H 	  s   	$B1 1	B=<B=c                b    t        j                  |       \  }}|dk(  ry|t        S ||S t        S )a  Guess the HTTP ``Content-Type`` for a file path.

    This logic mirrors Tornado's ``StaticFileHandler`` by respecting encoding
    metadata from ``mimetypes.guess_type`` and falling back to
    ``application/octet-stream`` when no specific type can be determined.

    Parameters
    ----------
    abspath : str
        Absolute file path used for type detection (only the suffix matters).

    Returns
    -------
    str
        Guessed content type string suitable for the ``Content-Type`` header.
    gzipzapplication/gzip)	mimetypes
guess_typer   )abspath	mime_typeencodings      r   guess_content_typer   L   sD    " $..w7Ix6!     )r   strr   r   returnz
str | None)r   r   r    r   )__doc__
__future__r   r   r   typingr   streamlit.path_securityr   r   __annotations__r   r    r   r   <module>r'      s0     #  	  :6z 6&Rr   