L iTUddlmZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z ddl mZmZddlmZe rddlmZdZd ed <d Zd ed < d dd Zej0dddZej0dddZddZddZd dZd dZd!dZd"dZ d#dZ!d$dZ"d%dZ#d&dZ$y)') annotationsN)Path)IO TYPE_CHECKINGAnyFinal)env_utilerrors)is_binary_string) Generatorz .streamlitrCONFIG_FOLDER_NAMEstaticAPP_STATIC_FOLDER_NAMEc|dk(rt|rdnd}n|}|r$tj|j|Stj|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. autoNzutf-8)r ioStringIOdecodeBytesIO)dataencoding data_encodings Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/file_util.pyget_encoded_file_datar%sK"6!1 6G  {{4;;}566 ::d c#8Kt|}tj|jdk(rt j d|dd}|r|dz }t tjjt||5}|dddy#1swYyxYww)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 rzRead zero byte file: ""rbN) get_streamlit_file_pathosstatst_sizer Erroropenpathjoinr )r&binaryfilenamemodehandles rstreamlit_readr,Ds't,H wwx  A%ll3H:Q?@@ D    bggll-t4d ;v sA>BB BBBc#Kd}|r|dz }t|}tjtjj |d t ||5}|dddy#1swYyxYw#t $r}dtjj|g}|jtjk(r!tjr|jdtjdj|d}~wwxYww) aOpens 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 wrT)exist_okNzUnable to write file: zSPython is limited to files below 2GB on OSX. See https://bugs.python.org/issue24658 )r r!makedirsr&dirnamer%OSErrorabspatherrnoEINVALr IS_DARWINappendr r$r')r&r(r*r+emsgs rstreamlit_writer;]s D    "4 (DKK%5 + $  L    +'(='>?@ 77ell "x'9'9 JJ9 ll499S>**+sOA D A2A&A2%D&A/+A2.D/A22 D;BDDDctjjtjjt}tjjtjj |dS)z3Get the folder where static HTML/JS/CSS files live.r)r!r&r2normpath__file__r')r2s rget_static_dirr?sGggoobgg..x89G 77  BGGLL(; < ?@     rc|jds|jdr|dz }n|dz }ddl}tjj |dz}|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/*rN)endswithfnmatchr!r&r2)rIfolderpath_globrSfile_dirs rfile_is_in_folder_globrVs_  # #C (  # #C ( s "O t #Owwx(3.H ??8_ 55rcd}tj|D]O\}}}|D]D}tjj||}|tjj |z }FQ|S)z(Return the size of a directory in bytes.r)r!walkr&r'getsize) directory total_sizedirpath_ filenamesffps rget_directory_sizerashJ!#!3.I .Agq)B "''//"- -J .. rc&tjjdd}t|dk(ry|j tj Dcgc]!}tj j|#}}tfd|DScc}w)aETest 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. PYTHONPATHrFc3pK|]-}ttjj|/yw)N)rVr!r&r=).0r&rIs r z%file_in_pythonpath..s/  rww//94@s36) r!environgetlensplitpathsepr&r4any)rI pythonpathr&absolute_pathss` rfile_in_pythonpathrpsw b1J :!8B8H8H8TUbggood+UNU " Vs&Bcttjjtjj|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 rnormalize_path_joinrss& 77  BGGLL$/ 00rc|ttj|}tjj |S)aReturn 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. )rsr!getcwdr&r2) main_scriptrBs rget_main_script_directoryrws++299; D 77??+ ,,r)r)rbytesrrHreturnzio.StringIO | io.BytesIO)F)r&rHr(boolryzGenerator[IO[Any], None, None])ryrH)rBrHryrH)rIrHryrH)rBrHr)rHryrH)rIrHrTrHryrz)rZrHryint)rIrHryrz)rrrHryrH)rvrHryrH)% __future__r contextlibr5rr!pathlibrtypingrrrr streamlitr r streamlit.string_utilr collections.abcr r __annotations__rrcontextmanagerr,r;r?rDr rLrNrVrarprsrwrrrs# 00&2))E(!)("( > 0 ++B= ' <B 624 1 -r