
    ȯeiE                    .   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+d2d"Z,d2d#Z- G d$ d%      Z.d3d&Z/d4d'Z0d5d(Z1	 	 	 	 	 	 	 	 	 	 d6d)Z2d7d*Z3 ed+e
d,ef   -      Z4e	 	 	 	 	 	 d8d.       Z5e	 d9	 	 	 	 	 d:d/       Z5d9d;d0Z5	 d9	 	 	 	 	 	 	 	 	 d<d1Z6y)=    )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ultralyticsri   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foliumrB   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-idc                    t         j                  j                  t              r*t	        t              5 } | j                         }ddd       |S t         j                  j                  t              r*t	        t              5 } | j                         }ddd       |S t        t        j                               }|S # 1 sw Y   S xY w# 1 sw Y   S xY w)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_PATHstruuidgetnode)f
machine_ids     `/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/streamlit/runtime/metrics_util.py_get_machine_id_v3r      s     
ww~~*+&' 	"1J	"  
-	.'( 	"AJ	"  (
	" 	" s   B: C:CCc                    t        j                  d      syt        j                  d      } d}t        j
                  j                  |       r.t        j                  |       5 }|j                         }ddd       |sNt        t        j                               }t        j                  |       5 }|j                  |       ddd       |S |S # 1 sw Y   [xY w# 1 sw Y   |S xY w)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outputs       r   _get_machine_id_v4r     s     78 "00AHI	ww~~h%%h/ 	$4		I	$ 

%	&&x0 	$FLL#	$ 9	$ 	$
	$ s   "C/CCC#c                  r    e Zd ZU  ej                         ZdZded<   edd       Z	d	dZ
d
dZed
d       Zy)InstallationNzInstallation | None	_instancec                    | j                   <| j                  5  | j                   t               | _         ddd       | j                   S | j                   S # 1 sw Y   | j                   S xY w)z#Returns the singleton Installation.N)r   _instance_lockr   )clss    r   instancezInstallation.instance-  s[     == ## 3==($0NCM3 }}s}}3 }}s   AA)c                    t        t        j                  t        j                  t	                           | _        t               | _        y N)r   r   uuid5NAMESPACE_DNSr   installation_id_v3r   installation_id_v4selfs    r   __init__zInstallation.__init__9  s4    "%JJt))+=+?@#
 #5"6    c                ,    t        j                  |       S r   )r   repr_r   s    r   __repr__zInstallation.__repr__@  s    zz$r   c                    | j                   S r   )r   r   s    r   installation_idzInstallation.installation_idC  s    &&&r   )returnr   )r   Noner   r   )__name__
__module____qualname__	threadingLockr   r   __annotations__classmethodr   r   r   propertyr    r   r   r   r   )  sK    #Y^^%N%)I")	 	7  ' 'r   r   c                p   t        j                  t              5  t        j                  |       r| n
t        |       }d}t        |d      r|j                  }nt        |d      r|j                  }|j                  dk7  r|j                   d| }|t        v r	t        |   }|cddd       S # 1 sw Y   yxY w)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$   )objobj_type	type_names      r   _get_type_namer  H  s    			Y	' !//#.3DI	8^, --IXz* ))I*,#../q<I,,,Y7I   s   BB,,B5c                    t        j                  |       }||j                  sy|j                  j                  d      d   S )z0Get the top level module for the given function.r  r  r   )r  	getmoduler  split)funcmodules     r   _get_top_level_moduler!  \  s:    t$F~V__??  %a((r   c                    t        j                  t              5  t        | t              rd|  cddd       S t        | t
              rdt        |        cddd       S 	 ddd       y# 1 sw Y   yxY w)zBGet metadata information related to the value of the given object.zval:Nzlen:)r  r  r  
isinstanceboolr   len)args    r   _get_arg_metadatar'  d  sp    			Y	' %cD"#<% % c5!#c($% % "	% % s   A*A**A3c                   t        j                  |       j                  }d}g }t        j                  |       }|}t	        |      D ]h  \  }	}
|	}|r|	dz   }	t        |      |	kD  r||	   n|	 }|dk(  r|
}-t        |t        |
      |      }t        |
      }|r||_	        |j                  |       j |j                         D ]@  \  }}t        |t        |            }t        |      }|r||_	        |j                  |       B t        |       }|dk7  rd| d| }|d	k(  r)|r't        |d
      r|j                  rd|j                   }|dk(  r+t        |      dkD  rt        |d   t               r
|d   }d| }t#        ||      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:)r0  args)r  getfullargspecr2  ismethod	enumerater%  r   r  r'  mappenditemsr!  r  r0  r#  r   r   )_command_func_command_namer2  kwargsarg_keywordsself_arg	arguments	is_methodr0  ir&  poskeywordargumentarg_metadatakwargkwarg_valuetop_level_modulecomponent_names                      r   _get_command_telemetryrI  p  s    ))-8==LH "I  /IDD/ #3AA%(%6%:,q/1#fHg)<D(-%HJ"#  %lln #{e~k'BC(5%HJ"# -];;& +,AdV4 	!!Hf%MMHMM?+  SY]z$q'37O a~./9--r   c                    t        | dz        S )z"Convert seconds into microseconds.i@B )int)secondss    r   to_microsecondsrM    s    w"##r   F.)boundc                     y r   r  r0  r  s     r   gather_metricsrR    s     	r   c                     y r   r  rQ  s     r   rR  rR    s     r   c                l     st         j                  d       d |d fd}|S |t              d fd       }t        j                  t
              5  |j                  j                  j                         t        j                        |_
        ddd       t        d|      S # 1 sw Y   xY w)	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	undefinedNrN  c                    t        |       S )NrQ  )rR  )r   r0  s    r   wrapperzgather_metrics.<locals>.wrapper  s    ! r   c                 $   ddl m}  |       }t        d      }|d uxr9 |j                  xr+ |j                   xr t        |j                        t        k  }d }d}|r|r	 t        
g| i |}|j                  |j                  vs |j                  |j                     t        k  r|j                  j                  |       |j                  j                  |j                  g       d|_        d}	  | i |}		 |r
|rd|_        	 |r|rt%         |       |z
        |_        |	S # t        $ r!}t        j!                  d|       Y d }~Yd }~ww xY w# t"        $ r |r|rt%         |       |z
        |_         w xY w# |r|rd|_        w w w xY w)Nr   )default_timerT)suppress_warningFz#Failed to collect command telemetry)exc_info)timeitrY  r   gather_usage_statscommand_tracking_deactivatedr%  tracked_commandsr   rI  r0  tracked_commands_counterr   r7  updater  r   debugr   rM  time)r2  r;  timer
exec_startctxtracking_activatedcommand_telemetry$has_set_command_tracking_deactivatedexresultr0  non_optional_funcs             r   wrapped_funcz$gather_metrics.<locals>.wrapped_func  s   1W
 $7 tO $&&$444$ C(()#$	 	 -1
 05,%R$:%t%.2%6<%!
 &**#2N2NN334E4J4JK./ ((//0AB,,335F5K5K4LM370 8<4
	9&77F ;380"3%4UWz5I%J"/  R CbQQR  	 "&7)8:9M)N!&	 ;380 <ss1   #BD) 6E )	E2EE'E==F   F)r   rN  r   rN  )r2  r   r;  r   r   r   )r   warningr   r  r  AttributeError__dict__ra  r  	signature__signature__r
   )r0  r  rW  rm  rl  s   `   @r   rR  rR    s    , 78|	 
? ?B 
		^	, J 	$$%6%?%?@%,%6%67H%I"	J
 \""J Js   A B**B3c                B   t               }|j                  }|j                  j                  |        ||_        ||_        t        j                  d      |_        t               }t        j                  r`t        j                  D ]M  }t        j                  |      st        j                  |   }|j                  |j                  r| dn|       O |j                  j                  |       t        D 	ch c]  }	|	t        j                   v r|	 }
}	t#        t        j$                        |_        t#        t(        j*                        |_        |j.                  j                  |
       |r||_        t3               x}rt5        |j6                        |_        |S c c}	w )z2Create and return the full PageProfile ForwardMsg.zserver.headlessz:default)r   page_profilecommandsextend	exec_time	prep_timer   r   headlessset_config_optionsis_manually_setadd
is_defaultr   sysmodulesr   platformr   rc  tznametimezoneattributionsuncaught_exceptionr   r$  fragment_ids_this_runis_fragment_run)ru  rw  rx  r  msgrt  config_optionsoption_nameconfig_optionattributionr  rf  s               r   create_page_profile_messager  /  sf    ,C##L  *&L&L"--.?@L  #uN!11 	K))+6"22;?M,9,D,D;-x(+	 ~.
 2#++% 	L  #,,'LO,L$$\2*<' ""s"'+C,E,E'F$J!s   7Fr  )r  objectr   r   )r  Callable[..., Any]r   r   )r&  r  r   
str | None)
r9  r  r:  r   r2  r   r;  r   r   r   )rL  floatr   rK  )r0  r   r  rN  r   rN  r   )r0  r   r  r  r   zCallable[[F], F])r0  r   r  zF | Noner   zCallable[[F], F] | F)
ru  zlist[Command]rw  rK  rx  rK  r  r  r   r   )7
__future__r   r  r  r   r  r  rc  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'  rI  rM  rN  rR  r  r  r   r   <module>r     s   #   	 
    +  6 6 - - ' 5 = J VH% %  # u " #% % $ 15#.(6$1 2&4&3!/DX:I e s!  sj ) 2 .<' '>()	6.%6.696.BE6.QT6.6.r$
 CxS)* 


  
 
 

  
m#h &*	000 0 #	0
 0r   