o
    ,&]ið  ã                   @  sR   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d„Z	ddd„Z
dS )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_STREAMÚcomponent_rootÚstrÚrelative_url_pathÚreturnú
str | Nonec                 C  sd   t j | ¡}t j t j ||¡¡}t j |¡}zt j ||g¡|kr%W dS W |S  ty1   Y dS 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)r   r   Ú	root_realÚ	candidateÚcandidate_real© r   úg/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/streamlit/web/server/component_file_utils.pyÚbuild_safe_abspath!   s   ÿüþr   Úabspathc                 C  s6   t  | ¡\}}|dkrdS |durtS |dur|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/gzipN)Ú	mimetypesÚ
guess_typer   )r   Ú	mime_typeÚencodingr   r   r   Úguess_content_typeD   s   r   )r   r   r   r   r   r	   )r   r   r   r   )Ú__doc__Ú
__future__r   r   r
   Útypingr   r   Ú__annotations__r   r   r   r   r   r   Ú<module>   s   
#