
    5i                    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        s/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/streamlit/web/server/component_file_utils.pybuild_safe_abspathr   !   s    (   0I  i9J!KLIWW%%i0N77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Ix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   