o
    Yh$                     @  s   U d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d d	lmZ erId d
lmZ d dlmZ eeeeejf Zded< dddZG dd dZdS )    )annotationsN)Path)TYPE_CHECKINGAnyUnioncast)	TypeAlias)url_util)validate_heightStreamlitAPIException)gather_metrics)DeltaGenerator)HeightWithoutContentr   PdfDatareturn
Any | Nonec                  C  s&   zddl } | jW S  ty   Y dS w )zGet the PDF custom component if available.

    Returns
    -------
    Any | None
        The pdf_viewer function if the streamlit-pdf component is available,
        None otherwise.
    r   N)streamlit_pdf
pdf_viewerImportError)r    r   W/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/streamlit/elements/pdf.py_get_pdf_component#   s   	r   c                   @  sH   e Zd ZedddddddZdddZdddZedddZdS )PdfMixinpdfi  N)heightkeydatar   r   r   r   
str | Noner   r   c                C  s6   |du rt dt }|du r|  S | ||||S )a  Display a PDF viewer.

        .. Important::

            You must install |streamlit-pdf|_ to use this command. You can
            install it as an extra with Streamlit:

            .. code-block:: shell

                pip install streamlit[pdf]

        .. |streamlit-pdf| replace:: ``streamlit-pdf``
        .. _streamlit-pdf: https://github.com/streamlit/streamlit-pdf

        Parameters
        ----------
        data : str, Path, BytesIO, or bytes
            The PDF file to show. This can be one of the following:

            - A URL (string) for a hosted PDF file.
            - A path to a local PDF file. If you use a relative path, it must
              be relative to the current working directory.
            - A file-like object. For example, this can be an ``UploadedFile``
              from ``st.file_uploader``, or this can be a local file opened
              with ``open()``.
            - Raw bytes data.

        height : int or "stretch"
            The height of the PDF viewer. This can be one of the following:

            - An integer specifying the height in pixels: The viewer has a
              fixed height. If the content is larger than the specified
              height, scrolling is enabled. This is ``500`` by default.
            - ``"stretch"``: The height of the viewer matches the height of
              its content or the height of the parent container, whichever is
              larger. If the viewer is not in a parent container, the height
              of the viewer matches the height of its content.

        Example
        -------
        >>> st.pdf("https://example.com/sample.pdf")
        >>> st.pdf("https://example.com/sample.pdf", height=600)
        NzhThe PDF data cannot be None. Please provide a valid PDF file path, URL, bytes data, or file-like object.)r   r   _show_pdf_warning_call_pdf_component)selfr   r   r   pdf_componentr   r   r   r   5   s   4zPdfMixin.pdfr"   r   c              
   C  s(  t |dd t|ttfrQt| }tj|ddr|}n`zt|d}| }W d   n1 s2w   Y  W nD t	t
fyP } z
td| d| d}~ww t|trY|}n$t|d	rht|d
rh| }nt|d	rr| }ntdt|j d|dkrd}	nt|}	|||	|d}
td|
S )z5Call the custom PDF component with the provided data.F)allow_content)httphttps)allowed_schemasrbNzUnable to read file 'z': readgetvaluezUnsupported data type for PDF: zy. Please provide a file path (str or Path), URL (str), bytes data, or file-like object (such as BytesIO or UploadedFile).stretch)filer   r   r   )r
   
isinstancestrr   stripr	   is_urlopenr(   FileNotFoundErrorPermissionErrorr   byteshasattrr)   type__name__r   )r!   r"   r   r   r   data_str
file_paramr+   ecomponent_heightresultr   r   r   r    v   sD   	





zPdfMixin._call_pdf_componentc                 C  s   t d)z;Raise an exception that the PDF component is not available.zThe PDF viewer requires the `streamlit-pdf` component to be installed.

Please run `pip install streamlit[pdf]` to install it.

For more information, see the Streamlit PDF documentation at https://docs.streamlit.io/develop/api-reference/media/st.pdf.r   r!   r   r   r   r      s   zPdfMixin._show_pdf_warningc                 C  s
   t d| S )zGet our DeltaGenerator.r   )r   r<   r   r   r   dg   s   
zPdfMixin.dg)r   r   r   r   r   r   r   r   )
r"   r   r   r   r   r   r   r   r   r   )r   r   )	r6   
__module____qualname__r   r   r    r   propertyr=   r   r   r   r   r   4   s    
@
=
r   )r   r   )
__future__r   iopathlibr   typingr   r   r   r   typing_extensionsr   	streamlitr	   #streamlit.elements.lib.layout_utilsr
   streamlit.errorsr   streamlit.runtime.metrics_utilr   streamlit.delta_generatorr   r   r-   r3   BytesIOr   __annotations__r   r   r   r   r   r   <module>   s   
