Ë
    úmxið  ã                  óP   — U d Z ddlmZ ddlZddl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)ÚFinalzapplication/octet-streamz
Final[str]Ú_OCTET_STREAMc                óh  — 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 joins ``relative_url_path`` with ``component_root`` and
    normalizes and resolves symlinks. If the resulting path escapes the
    component root, ``None`` is returned to indicate a forbidden traversal.

    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.

    Returns
    -------
    str or None
        The resolved absolute path if it stays within ``component_root``;
        otherwise ``None`` when the path would traverse outside the root.
    N)ÚosÚpathÚrealpathÚnormpathÚjoinÚ
commonpathÚ
ValueError)Úcomponent_rootÚrelative_url_pathÚ	root_realÚ	candidateÚcandidate_reals        ú`/home/htdocs/ttos/venv/lib/python3.12/site-packages/streamlit/web/server/component_file_utils.pyÚbuild_safe_abspathr   !   s–   € ô( —‘× Ñ  Ó0€IÜ—‘× Ñ ¤§¡§¡¨iÐ9JÓ!KÓL€IÜ—W‘W×%Ñ% iÓ0€Nðä�7‰7×Ñ˜y¨.Ð9Ó:¸iÒGØð Hð Ðøô	 ò áðús   Á=$B% Â%	B1Â0B1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   D   sD   € ô" $×.Ñ.¨wÓ7Ñ€Iˆxà�6ÒØ!ð ÐÜÐØÐØÐäÐó    )r   Ústrr   r   Úreturnz
str | None)r   r   r   r   )Ú__doc__Ú
__future__r   r   r   Útypingr   r   Ú__annotations__r   r   © r   r   ú<module>r%      s-   ðò õ #ã Û 	Ý à6€ˆzÓ 6ó ôFr   