o
    ,&]iE                     @  s  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Zd dlZd dlZd dl	m
Z
mZ d dlmZ d dlmZmZmZmZmZ d dlmZmZmZ d dlmZ d dlmZ d d	lmZmZ d d
lm Z  d dl!m"Z" ee#Z$de%d< dZ&de%d< dZ'de%d< ddddddddddd
Z(de%d< g dZ)de%d< d Z*d!Z+dWd$d%Z,dWd&d'Z-G d(d) d)Z.dXd,d-Z/dYd0d1Z0dZd4d5Z1d[d<d=Z2d\dAdBZ3edCe
dDef dEZ4ed]dGdHZ5e	d^d_dKdHZ5d^d`dNdHZ5	d^dadUdVZ6dS )b    )annotationsN)CallableSized)wraps)AnyFinalTypeVarcastoverload)config	file_utilutil)
get_logger)
ForwardMsg)ArgumentCommand)RerunException)get_script_run_ctxr   _LOGGER   _MAX_TRACKED_COMMANDS   _MAX_TRACKED_PER_COMMANDDG	DataFramePlotlyFigureBokehFigureMatplotlibFigurePandasStylerPandasIndexPandasSeriesSnowparkConnectionSQLConnection)
z(streamlit.delta_generator.DeltaGeneratorzpandas.core.frame.DataFramez plotly.graph_objs._figure.Figurezbokeh.plotting.figure.Figurezmatplotlib.figure.Figurezpandas.io.formats.style.Stylerzpandas.core.indexes.base.Indexzpandas.core.series.Seriesz<streamlit.connections.snowpark_connection.SnowparkConnectionz2streamlit.connections.sql_connection.SQLConnection_OBJECT_NAME_MAPPING)pymysqlMySQLdbmysqlpymongoibisboto3psycopg2psycopg3
sqlalchemyelasticsearchpyodbcpymssql	cassandraazureredissqlite3neo4jduckdbopensearchpysupabase
databrickspolarsdaskvaexmodinpysparkcudfxarrayray	geopandasmarstableszarrdatasetsdaft	mistralaiopenai	langchainllama_index	llama_cpp	anthropic
pyllamacppcoheretransformersnomic	diffuserssemantic_kernel	replicatehuggingface_hubwandbtorch
tensorflowtrubricscomet_mlclarifairekahegelfastchat
assemblyaiopenllm
embedchainhaystackvllmalpajinaaiguidancelitellm	comet_llm
instructorxgboostlightgbmcatboostsklearnpydantic_ai	datachaindoclinglitservecrawl4aibaml_clientbrowser_usecrewaiunsloth	langgraphdspyultralyticsrh   ragasswarmfaster_whispermemoriautogen_agentchatxai_sdkagnolangfuse
smolagentsollamagroqtogetherai21marvinoutlines
guardrails
promptflowsemantic_routermem0aisuitemlflowoptunakerasjaxshap	evidentlygreat_expectationsbentomlmodal	sagemakervertexaitiktokensentence_transformersspacynltkonnxruntimellama_api_clientprefectluigiairflowdagstercelerypgvectorfaissannoypineconechromadbweaviateqdrant_clientpymilvuslancedb	snowflakepydanticfastapi	starlette
playwrightfoliumrA   httpx	pyechartsfastplotlibpygfxhighcharts_coreseaborngraphviz
matplotlibuvlooporjsonrichstreamlit_extrasstreamlit_pydantic	pygwalkerplotlybokehplostauthlibpypdf
pdfplumberdocxopenpyxl
xlsxwritercv2	mediapipe_ATTRIBUTIONS_TO_CHECKz/etc/machine-idz/var/lib/dbus/machine-idreturnstrc                  C  s   t jtr!tt} |  }W d   |S 1 sw   Y  |S t jtrBtt} |  }W d   |S 1 s;w   Y  |S tt	 }|S )aD  Get the machine ID.

    This is a unique identifier for a user for tracking metrics,
    that is broken in different ways in some Linux distros and Docker images.
    - at times just a hash of '', which means many machines map to the same ID
    - at times a hash of the same string, when running in a Docker container
    N)
ospathisfile_ETC_MACHINE_ID_PATHopenread_DBUS_MACHINE_ID_PATHr   uuidgetnode)f
machine_id r   \/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/streamlit/runtime/metrics_util.py_get_machine_id_v3   s    	







r   c                  C  s   t dsdS td} d}tj| r-t| }| }W d   n1 s(w   Y  |sPt	t
 }t| }|| W d   |S 1 sKw   Y  |S )a  Get a random ID that is stable for each machine, generating if needed.

    This is a unique identifier for a user for tracking metrics.
    Instead of relying on a hardware address in the container or host we'll
    generate a UUID and store it in the ~/.streamlit hidden folder.
    zbrowser.gatherUsageStatszno-machine-id-v4machine_id_v4N)r   
get_optionr   get_streamlit_file_pathr   r   existsstreamlit_readr   r   r   uuid4streamlit_writewrite)filepath	stable_idfileoutputr   r   r   _get_machine_id_v4  s    




r   c                   @  sR   e Zd ZU e ZdZded< edddZ	ddd	Z
dddZedddZdS )InstallationNzInstallation | None	_instancer   c                 C  s^   | j du r,| j | j du rt | _ W d   | j S W d   | j S 1 s'w   Y  | j S )z#Returns the singleton Installation.N)r   _instance_lockr   )clsr   r   r   instance-  s   




zInstallation.instanceNonec                 C  s"   t ttjt | _t | _d S N)r   r   uuid5NAMESPACE_DNSr   installation_id_v3r   installation_id_v4selfr   r   r   __init__9  s   zInstallation.__init__r   c                 C  s
   t | S r   )r   repr_r   r   r   r   __repr__@  s   
zInstallation.__repr__c                 C  s   | j S r   )r   r   r   r   r   installation_idC  s   zInstallation.installation_id)r   r   )r   r   r   r   )__name__
__module____qualname__	threadingLockr   r   __annotations__classmethodr   r   r   propertyr   r   r   r   r   r   )  s   
 

r   objobjectc                 C  s   t t= t| r| nt| }d}t|dr|j}nt|dr$|j}|j	dkr1|j	 d| }|t
v r9t
| }|W  d   S 1 sEw   Y  dS )z7Get a simplified name for the type of the given object.unknownr   r   builtins.Nfailed)
contextlibsuppress	Exceptioninspectisclasstypehasattrr   r   r   r#   )r  obj_type	type_namer   r   r   _get_type_nameH  s   


 r  funcCallable[..., Any]c                 C  s,   t | }|du s|jsdS |jdd S )z0Get the top level module for the given function.Nr  r  r   )r  	getmoduler   split)r  moduler   r   r   _get_top_level_module\  s   
r  arg
str | Nonec                 C  sx   t t- t| trd|  W  d   S t| tr*dt|  W  d   S W d   dS 1 s5w   Y  dS )zBGet metadata information related to the value of the given object.zval:Nzlen:)r	  r
  r  
isinstanceboolr   len)r  r   r   r   _get_arg_metadatad  s   


r  _command_func_command_nameargsr   kwargsr   c                 O  s`  t | j}d}g }t | }|}t|D ]7\}	}
|	}|r!|	d }	t||	kr+||	 n|	 }|dkr5|
}qt|t|
|d}t|
}|rG||_	|
| q| D ]\}}t|t|d}t|}|rf||_	|
| qQt| }|dkr|d| d| }|d	kr|rt|d
r|jrd|j }|dkrt|dkrt|d tr|d }d| }t||dS )zCGet telemetry information for the given callable and its arguments.N   r   )ktp)r$  r%  	streamlitz	external::create_instancenamez
component:_bidi_componentzcomponent_v2:)r*  r!  )r  getfullargspecr!  ismethod	enumerater  r   r  r  mappenditemsr  r  r*  r  r   r   )r  r   r!  r"  arg_keywordsself_arg	arguments	is_methodr*  ir  poskeywordargumentarg_metadatakwargkwarg_valuetop_level_modulecomponent_namer   r   r   _get_command_telemetryp  sN   
"
r?  secondsfloatintc                 C  s   t | d S )z"Convert seconds into microseconds.i@B )rB  )r@  r   r   r   to_microseconds  s   rC  F.)boundr*  c                 C     d S r   r   r*  r  r   r   r   gather_metrics     rH  r   Callable[[F], F]c                 C  rF  r   r   rG  r   r   r   rH    rI  F | NoneCallable[[F], F] | Fc                   s    s	t d d |du rd fdd}|S |td fdd}tt |jj t	|_
W d   n1 sAw   Y  td|S )a  Function decorator to add telemetry tracking to commands.

    Parameters
    ----------
    func : callable
    The function to track for telemetry.

    name : str or None
    Overwrite the function name with a custom name that is used for telemetry tracking.

    Example
    -------
    >>> @st.gather_metrics
    ... def my_command(url):
    ...     return url

    >>> @st.gather_metrics(name="custom_name")
    ... def my_command(url):
    ...     return url
    zgather_metrics: name is empty	undefinedNr   rD  r   c                   s   t  | dS )NrG  )rH  )r   )r*  r   r   wrapper  s   zgather_metrics.<locals>.wrapperr!  r   r"  c            
   
     s^  ddl m} | }tdd}|d uo|jo|j ot|jtk }d }d}|rq|rqz/t g| R i |}|j	|j
vsC|j
|j	 tk rI|j| |j
|j	g d|_d}W n typ } ztjd|d W Y d }~nd }~ww z'z	| i |}	W n ty   |r|rt| | |_ w W |r|rd|_n|r|rd|_w |r|rt| | |_|	S )Nr   )default_timerT)suppress_warningFz#Failed to collect command telemetry)exc_info)timeitrO  r   gather_usage_statscommand_tracking_deactivatedr  tracked_commandsr   r?  r*  tracked_commands_counterr   r0  updater  r   debugr   rC  time)
r!  r"  timer
exec_startctxtracking_activatedcommand_telemetry$has_set_command_tracking_deactivatedexresultr*  non_optional_funcr   r   wrapped_func  sf   

z$gather_metrics.<locals>.wrapped_func)r   rD  r   rD  )r!  r   r"  r   r   r   )r   warningr   r	  r
  AttributeError__dict__rW  r  	signature__signature__r	   )r*  r  rN  rd  r   rb  r   rH    s   
A
commandslist[Command]	exec_time	prep_timeuncaught_exceptionr   c                 C  s   t  }|j}|j|  ||_||_td|_t	 }tj
r<tj
D ]}t|s)q!tj
| }||jr8| dn| q!|j| dd tD }	ttj|_ttj|_|j|	 |r`||_t  }
rkt|
j|_|S )z2Create and return the full PageProfile ForwardMsg.zserver.headlessz:defaultc                 S  s   h | ]	}|t jv r|qS r   )sysmodules).0attributionr   r   r   	<setcomp>O  s
    
z.create_page_profile_message.<locals>.<setcomp>)r   page_profilerj  extendrl  rm  r   r   headlessset_config_optionsis_manually_setadd
is_defaultr   r   ro  platformr   rY  tznametimezoneattributionsrn  r   r  fragment_ids_this_runis_fragment_run)rj  rl  rm  rn  msgrt  config_optionsoption_nameconfig_optionr  r\  r   r   r   create_page_profile_message/  s6   



r  r   )r  r  r   r   )r  r  r   r   )r  r  r   r  )
r  r  r   r   r!  r   r"  r   r   r   )r@  rA  r   rB  )r*  r   r  rD  r   rD  r   )r*  r   r  r   r   rJ  )r*  r   r  rK  r   rL  )
rj  rk  rl  rB  rm  rB  rn  r  r   r   )7
__future__r   r	  r  r   ro  r   rY  r   collections.abcr   r   	functoolsr   typingr   r   r   r	   r
   r'  r   r   r   streamlit.loggerr   streamlit.proto.ForwardMsg_pb2r   streamlit.proto.PageProfile_pb2r   r   /streamlit.runtime.scriptrunner_utils.exceptionsr   7streamlit.runtime.scriptrunner_utils.script_run_contextr   r   r   r   r   r   r#   r   r   r   r   r   r   r  r  r  r?  rC  rD  rH  r  r   r   r   r   <module>   sh    6






9t