L iddlmZddlZddlmZmZddlmZmZm Z m Z ddl m Z m Z ddlmZe dZGdd eeeZy) ) annotationsN)ABCabstractmethod)AnyGenericTypeVarcast)AttrDictsecrets_singleton)calc_md5RawConnectionTcneZdZdZd dZd dZd dZddZeddZ d dZ eddZ e dd Z y )BaseConnectionaThe abstract base class that all Streamlit Connections must inherit from. This base class provides connection authors with a standardized way to hook into the ``st.connection()`` factory function: connection authors are required to provide an implementation for the abstract method ``_connect`` in their subclasses. Additionally, it also provides a few methods/properties designed to make implementation of connections more convenient. See the docstrings for each of the methods of this class for more information .. note:: While providing an implementation of ``_connect`` is technically all that's required to define a valid connection, connections should also provide the user with context-specific ways of interacting with the underlying connection object. For example, the first-party SQLConnection provides a ``query()`` method for reads and a ``session`` property for more complex operations. c ||_||_ttj|j j |_tjj|j|jdi||_ y)aCreate a BaseConnection. This constructor is called by the connection factory machinery when a user script calls ``st.connection()``. Subclasses of BaseConnection that want to overwrite this method should take care to also call the base class' implementation. Parameters ---------- connection_name : str The name of this connection. This corresponds to the ``[connections.]`` config section in ``st.secrets``. kwargs : dict Any other kwargs to pass to this connection class' ``_connect`` method. Returns ------- None N)_connection_name_kwargsr jsondumps_secretsto_dict_config_section_hashr file_change_listenerconnect_on_secrets_changed_connect _raw_instance)selfconnection_namekwargss k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/connections/base_connection.py__init__zBaseConnection.__init__.sf*!0 $,TZZ 8M8M8O-P$Q!..66t7O7OP4ADMM4KF4KcVtjj|jy)N)r r disconnectrrs r!__del__zBaseConnection.__del__Ks..99$:R:RSr#c tj||S#t$r*t|j|rtd|d|dwxYw)N`z3` doesn't exist here, but you can call `._instance.z ` instead)object__getattribute__AttributeErrorhasattr _instance)rnames r!r+zBaseConnection.__getattribute__Ns_ **46 6 t~~t,$vPQUPVV_`   s 3A cttj|jj }||j k7r||_|j yy)zReset the raw connection object when this connection's secrets change. We don't expect either user scripts or connection authors to have to use or overwrite this method. N)r rrrrrreset)r_new_hashs r!rz"BaseConnection._on_secrets_changedZsJ DJJt}}'<'<'>?@ t00 0(0D % JJL 1r#c d}tjrtjd}|t|tur t iSt d|j|j t iS)a=Get the secrets for this connection from the corresponding st.secrets section. We expect this property to be used primarily by connection authors when they are implementing their class' ``_connect`` method. User scripts should, for the most part, have no reason to use this property. N connectionsr )r load_if_toml_existsgettyper r r)rconnections_sections r!rzBaseConnection._secretshso04  0 0 2"3"7"7 "F   &$/B*C8*SB<  +//0E0ExPR|T  r#cd|_y)aKReset this connection so that it gets reinitialized the next time it's used. This method can be useful when a connection has become stale, an auth token has expired, or in similar scenarios where a broken connection might be fixed by reinitializing it. Note that some connection methods may already use ``reset()`` in their error handling code. Returns ------- None Example ------- >>> import streamlit as st >>> >>> conn = st.connection("my_conn") >>> >>> # Reset the connection before using it if it isn't healthy >>> # Note: is_healthy() isn't a real method and is just shown for example here. >>> if not conn.is_healthy(): ... conn.reset() >>> >>> # Do stuff with conn... N)rr&s r!r1zBaseConnection.reset{s 2"r#ct|j!|jdi|j|_|jS)zKGet an instance of the underlying connection, creating a new one if needed.r)rrrr&s r!r.zBaseConnection._instances6    %!.!>!>D !!!r#c t)aCreate an instance of an underlying connection object. This abstract method is the one method that we require subclasses of BaseConnection to provide an implementation for. It is called when first creating a connection and when reconnecting after a connection is reset. Parameters ---------- kwargs : dict Returns ------- RawConnectionT The underlying connection object. )NotImplementedError)rr s r!rzBaseConnection._connects ""!r#N)rstrr rreturnNone)r?r@)r/r>r?r)r2r>r?r@)r?r )r?r )r rr?r )__name__ __module__ __qualname____doc__r"r'r+rpropertyrr1r.rrrr#r!rrs^$L:T   $"6""""r#r) __future__rrabcrrtypingrrrr streamlit.runtime.secretsr r streamlit.utilr r rrr#r!rKs<# #..A#)*U"S'.1U"r#