
    ȯei                    T   U d dl mZ d dlZd dlZd dl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mZ d dlmZ e
rd dlmZ dZd	ed
<   dZd	ed<   	 d	 	 	 	 	 ddZej0                  ddd       Zej0                  ddd       ZddZddZd dZd dZd!dZd"dZ d#dZ!d$dZ"d%dZ#d&dZ$y)'    )annotationsN)Path)IOTYPE_CHECKINGAnyFinal)env_utilerrors)is_binary_string)	Generatorz
.streamlitr   CONFIG_FOLDER_NAMEstaticAPP_STATIC_FOLDER_NAMEc                    |dk(  rt        |       rdnd}n|}|r$t        j                  | j                  |            S t        j                  |       S )a<  Coerce bytes to a BytesIO or a StringIO.

    Parameters
    ----------
    data : bytes
    encoding : str

    Returns
    -------
    BytesIO or StringIO
        If the file's data is in a well-known textual format (or if the encoding
        parameter is set), return a StringIO. Otherwise, return BytesIO.

    autoNzutf-8)r   ioStringIOdecodeBytesIO)dataencodingdata_encodings      U/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/streamlit/file_util.pyget_encoded_file_datar   %   sK    " 6 !1 6G {{4;;}566::d    c              #  8  K   t        |       }t        j                  |      j                  dk(  rt	        j
                  d| d      d}|r|dz  }t        t        j                  j                  t        |       |      5 }| ddd       y# 1 sw Y   yxY ww)a$  Opens a context to read this file relative to the streamlit path.

    For example:

    with streamlit_read('foo.txt') as foo:
        ...

    opens the file `.streamlit/foo.txt`

    path   - the path to write to (within the streamlit directory)
    binary - set to True for binary IO
    r   zRead zero byte file: ""rbN)
get_streamlit_file_pathosstatst_sizer
   Erroropenpathjoinr   )r&   binaryfilenamemodehandles        r   streamlit_readr,   D   s      't,H	wwx  A%ll3H:Q?@@D	bggll-t4d	; v  s   A>B B	BBBc              #    K   d}|r|dz  }t        |       } t        j                  t        j                  j	                  |       d       	 t        | |      5 }| ddd       y# 1 sw Y   yxY w# t        $ r}dt        j                  j                  |        g}|j                  t        j                  k(  r!t        j                  r|j                  d       t        j                  dj                  |            d}~ww xY ww)	a  Opens a file for writing within the streamlit path, and
    ensuring that the path exists.

    For example:

        with streamlit_write('foo/bar.txt') as bar:
            ...

    opens the file .streamlit/foo/bar.txt for writing,
    creating any necessary directories along the way.

    path   - the path to write to (within the streamlit directory)
    binary - set to True for binary IO
    wr   T)exist_okNzUnable to write file: zSPython is limited to files below 2GB on OSX. See https://bugs.python.org/issue24658
)r    r!   makedirsr&   dirnamer%   OSErrorabspatherrnoEINVALr	   	IS_DARWINappendr
   r$   r'   )r&   r(   r*   r+   emsgs         r   streamlit_writer;   ]   s       D"4(DKK%5
+$ 	L	 	 	 +'(='>?@77ell"x'9'9JJ9 ll499S>**+sO   A	DA2 A&A2 %D&A/+A2 .D/A2 2	D;BD  DDc                     t         j                  j                  t         j                  j                  t                    } t         j                  j                  t         j                  j                  | d            S )z3Get the folder where static HTML/JS/CSS files live.r   )r!   r&   r2   normpath__file__r'   )r2   s    r   get_static_dirr?      sG    ggoobgg..x89G77BGGLL(;<<r   c                x    t        |       j                  t        z  }t        j                  j                  |      S )z+Get the folder where app static files live.)r   parentr   r!   r&   r4   )main_script_path
static_dirs     r   get_app_static_dirrD      s,    &'..1GGJ77??:&&r   c                 z    t        j                         }|t        d      t        |t        z  t        |  z        S )zyReturn the full path to a file in ~/.streamlit.

    This doesn't guarantee that the file (or its directory) exists.
    zNo home directory.)r   homeRuntimeErrorstrr   )filepathrF   s     r   r    r       s:    
 99;D|/00t((4?:;;r   c                 \    t        t        j                         t        z  t        |  z        S )zReturn the full path to a filepath in ${CWD}/.streamlit.

    This doesn't guarantee that the file (or its directory) exists.
    )rH   r   cwdr   )rI   s    r   get_project_streamlit_file_pathrL      s$    
 txxz..x@AAr   c           	         t        t        t        j                  j	                  t        j                  j                  |                   t        z  |z        S )zReturn the full path to a file in the .streamlit folder relative to the
    main script's path.

    This doesn't guarantee that the file (or its directory) exists.
    )rH   r   r!   r&   r4   r2   r   )rB   r)   s     r   #get_main_script_streamlit_file_pathrN      sD     RWW__RWW__-=>?@
	
	 r   c                    |j                  d      s|j                  d      r|dz  }n|dz  }ddl}t        j                  j	                  |       dz   }|j                  ||      S )zTest whether a file is in some folder with globbing support.

    Parameters
    ----------
    filepath : str
        A file path.
    folderpath_glob: str
        A path to a folder that may include globbing.

    */z/*r   N)endswithfnmatchr!   r&   r2   )rI   folderpath_globrS   file_dirs       r   file_is_in_folder_globrV      s_     ##C(##C(s"Ot#Owwx(3.H??8_55r   c                    d}t        j                  |       D ]O  \  }}}|D ]D  }t         j                  j                  ||      }|t         j                  j	                  |      z  }F Q |S )z(Return the size of a directory in bytes.r   )r!   walkr&   r'   getsize)	directory
total_sizedirpath_	filenamesffps          r   get_directory_sizera      sh    J!#!3 .I 	.Agq)B"''//"--J	.. r   c                &    t         j                  j                  dd      }t        |      dk(  ry|j	                  t         j
                        D cg c]!  }t         j                  j                  |      # }}t         fd|D              S c c}w )aE  Test whether a filepath is in the same folder of a path specified in the PYTHONPATH env variable.


    Parameters
    ----------
    filepath : str
        An absolute file path.

    Returns
    -------
    boolean
        True if contained in PYTHONPATH, False otherwise. False if PYTHONPATH is not defined or empty.

    
PYTHONPATH r   Fc              3  p   K   | ]-  }t        t        j                  j                        |       / y w)N)rV   r!   r&   r=   ).0r&   rI   s     r   	<genexpr>z%file_in_pythonpath.<locals>.<genexpr>   s/       	rww//94@s   36)	r!   environgetlensplitpathsepr&   r4   any)rI   
pythonpathr&   absolute_pathss   `   r   file_in_pythonpathrp      sw     b1J
:!8B8H8H8TUbggood+UNU "   Vs   &Bc                 t    t         j                  j                  t        j                  j                  |        S )zReturn the normalized path of the joined path.

    Parameters
    ----------
    *args : str
        The path components to join.

    Returns
    -------
    str
        The normalized path of the joined path.
    )r!   r&   r=   r'   )argss    r   normalize_path_joinrs      s&     77BGGLL$/00r   c                |    t        t        j                         |       }t        j                  j	                  |      S )a  Return the full path to the main script directory.

    Parameters
    ----------
    main_script : str
        The main script path. The path can be an absolute path or a relative
        path.

    Returns
    -------
    str
        The full path to the main script directory.
    )rs   r!   getcwdr&   r2   )main_scriptrB   s     r   get_main_script_directoryrw      s+     +299;D77??+,,r   )r   )r   bytesr   rH   returnzio.StringIO | io.BytesIO)F)r&   rH   r(   boolry   zGenerator[IO[Any], None, None])ry   rH   )rB   rH   ry   rH   )rI   rH   ry   rH   )rB   rH   r)   rH   ry   rH   )rI   rH   rT   rH   ry   rz   )rZ   rH   ry   int)rI   rH   ry   rz   )rr   rH   ry   rH   )rv   rH   ry   rH   )%
__future__r   
contextlibr5   r   r!   pathlibr   typingr   r   r   r   	streamlitr	   r
   streamlit.string_utilr   collections.abcr   r   __annotations__r   r   contextmanagerr,   r;   r?   rD   r    rL   rN   rV   ra   rp   rs   rw    r   r   <module>r      s    #   	 	  0 0 & 2) ) E ( !)  ( "(
>  0 + +B='	<B6241 -r   